Clear Filters
Clear Filters

Whats wrong with these scripts? I can't get them to work.

1 view (last 30 days)
Script:
[W,y] = ode45(@eqtP426,[0 368],[2; 2; 0; 0]);
plot(W,y(:,1),'-',W,y(:,2),'--',W,y(:,3),'-*',W,y(:,4),'-')
title('Solution of P4-26');
xlabel('Catalyst weight W');
ylabel('Solution y');
legend('y_1','y_2','y_3','y_4')
Script:
function dydW = eqtP426(W,y)
CT0 = 0.4
FT0 = 4
kh = 0.1
keq = 1.44
k = 1.37
dydW =[-(k*CT0^2/(y(1)+y(2)+y(3)+y(4))^2)*(y(1)*y(2)-y(3)*y(4)/keq);
-(k*CT0^2/(y(1)+y(2)+y(3)+y(4))^2)*(y(1)*y(2)-y(3)*y(4)/keq);
(k*CT0^2/(y(1)+y(2)+y(3)+y(4))^2)*(y(1)*y(2)-y(3)*y(4)/keq);
(k*CT0^2/(y(1)+y(2)+y(3)+y(4))^2)*(y(1)*y(2)-y(3)*y(4)/keq)-
kh*CT0*y(4)/(y(1)+y(2)+y(3)+y(4))]

Answers (1)

Geoff Hayes
Geoff Hayes on 21 Mar 2016
Adam - when I run your code, I observe the following error
Error using feval
Error: File: eqtP426.m Line: 10 Column: 69
Expression or statement is incorrect--possibly unbalanced (, {, or [.
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn,
...
This is due to how you initialize dydW in eqtP426.m
dydW =[-(k*CT0^2/(y(1)+y(2)+y(3)+y(4))^2)*(y(1)*y(2)-y(3)*y(4)/keq);
-(k*CT0^2/(y(1)+y(2)+y(3)+y(4))^2)*(y(1)*y(2)-y(3)*y(4)/keq);
(k*CT0^2/(y(1)+y(2)+y(3)+y(4))^2)*(y(1)*y(2)-y(3)*y(4)/keq);
(k*CT0^2/(y(1)+y(2)+y(3)+y(4))^2)*(y(1)*y(2)-y(3)*y(4)/keq)-
kh*CT0*y(4)/(y(1)+y(2)+y(3)+y(4))]
The fourth element of the above array requires the long line continuation using an ellipsis as
dydW =[-(k*CT0^2/(y(1)+y(2)+y(3)+y(4))^2)*(y(1)*y(2)-y(3)*y(4)/keq);
-(k*CT0^2/(y(1)+y(2)+y(3)+y(4))^2)*(y(1)*y(2)-y(3)*y(4)/keq);
(k*CT0^2/(y(1)+y(2)+y(3)+y(4))^2)*(y(1)*y(2)-y(3)*y(4)/keq);
(k*CT0^2/(y(1)+y(2)+y(3)+y(4))^2)*(y(1)*y(2)-y(3)*y(4)/keq)- ...
kh*CT0*y(4)/(y(1)+y(2)+y(3)+y(4))];
Try making the above change and re-run your code.

Community Treasure Hunt

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

Start Hunting!