Error message regarding Midpoint Method

1 view (last 30 days)
Tiago
Tiago on 4 Jan 2015
Edited: Tiago on 4 Jan 2015
As part of a group project we have a system of 2 non linear differential equations and we have to draw the S=S(t) , I=I(t) graphic using the midpoint method and I'm getting the following error:
"Error in inline expression ==> matrix([[-(I*S)/1000], [(I*S)/1000 - (3*I)/10]]) Undefined function 'matrix' for input arguments of type 'double'.
Error in inline/subsref (line 23) INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);" The system is the following
The code i did is the following:
% code
clear
syms I S
u=[S;I];
F=[-0.001*S*I;0.001*S*I-0.3*I];
F1=inline(char(F),'I','S');
h=100; %Valores aleatórios
T=100000;
ni=(T/h);
u0=[799;1];
f=zeros(1,2);
k=zeros(1,2);
i=1;
%code
while i<=ni
f(1)=F1(u0(1),u0(2));
f(2)=F1(u0(1),u0(2));
delta=h*f;
k(1)=F1((u0(1)+h*(1/2)),(u0(2)+h*(1/2)));
k(2)=F1((u0(1)+h*(1/2)),(u0(2)+h*(1/2)));
u1=u0+h*k;
disp('i:'),disp(i)
disp('u= '),disp(u1)
u0=u1;
i=i+1;
end
end

Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!