Error in odearguments (line 87) f0 = feval(ode,​t0,y0,args​{:}); % ODE15I sets args{1} to yp0. Error in ode45 (line 115) odeargumen​ts(FcnHand​lesUsed, solver_name, ode, tspan, y0, options, varargin); Error in untitled2 (line 6) [z, v]=ode45(@chp

60 views (last 30 days)
How can I fix this error?
script:
Fclear
clc
%adibatic
v0=[0 305];
zspan=[0 10];
[z, v]=ode45(@chp12ex7_b, zspan, v0);
Cao=0.1; dH=-6000;
X = v(:,1); T = v(:,2);
k=0.01.*exp((5033)*(1/300-1./T)); Kc=10.*exp((dH./1.987)*(1/450-1./T));
Xeq=(2.*Cao.*Kc+1-sqrt(4.*Cao.*Kc+1))./(2.*Cao.*Kc);
rate=-k.*((Cao.^2)*((1-X).^2)-Cao.*X./Kc);
plot(z, v(:,1), z, Xeq), xlabel ('Volume (dm^3)'), ylabel ('Conversion'), legend('X','Xe'), title('Adiabatic')
figure
plot(z, v(:,2)), xlabel ('Volume (dm^3)'), ylabel ('Temperature'), legend('T'), title('Adiabatic')
figure
plot(z, -rate, 'k-'), xlabel ('Volume (dm^3)'), ylabel ('rate'), title('Adiabatic')
function:
function ydot = chp12ex7_b(~,~,y)
%input variables
X=y(1); T=y(2);
%data
Ua=0; Cao=0.1; Fao=0.2; dH=-6000; Cpo=30; Ta = 0;
%rate
k=0.01*exp((5033)*(1/300-1/T)); Kc=10*exp((dH/1.987)*(1/450-1/T));
rate=-k*((Cao.^2)*((1-X).^2)-Cao.*X./Kc);
%Equations
ydot(1)=-rate/Fao; ydot(2)=((rate*dH)-Ua*(T-Ta))/(Cpo*Fao);
ydot=ydot';
end

Answers (1)

Walter Roberson
Walter Roberson on 7 May 2021
[z, v]=ode45(@chp12ex7_b, zspan, v0);
That passes z and v to the function
function ydot = chp12ex7_b(~,~,y)
That function expects to receive z and v and y. But y was never passed to it.
  3 Comments
Tracy Tetzloff
Tracy Tetzloff on 8 May 2021
When i put function ydot = chp12ex7_b(~,y) i get the error Not enough input arguments. X=y(1); T=y(2);

Sign in to comment.

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Products


Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!