Hi everybody,
I have code to solve a system of Differential Equations with matrix. I do not know my mistakes. When I run my, error in my code " Undefined operator '*' for input arguments of type 'function_handle'.Error in osc (line 22) odes=diff(P)==(0.2*A+s*B)*P;"
Can you see it and help me fix it. Thanks so much!
———————————————-
This is my code:
T=100; g=0.5*T; n=3;s0=0.5;lamda=0.2;% khai bao ham xa xe (KNTH)
s=@(t)(s0).*(((t-floor(t/T)*T)<g))+(0)*(((t-floor(t/T)*T)>g));t=linspace(0,500);plot(t,s(t));grid;% Khai bao mt A vuong cap n+2
syms p1(t) p2(t) p3(t) p4(t) p5(t)A=[-1 0 0 0 0; 1 -1 0 0 0; 0 1 -1 0 0; 0 0 1 -1 0; 0 0 0 1 0];B=[0 1 0 0 0; 0 -1 1 0 0; 0 0 -1 1 0; 0 0 0 -1 1; 0 0 0 0 -1];P=[p1; p2; p3; p4; p5];odes=diff(P)==(0.2*A+s*B)*P;[p1Sol(t),p2Sol(t),p3Sol(t),p4Sol(t),p5Sol(t)]=dsolve(odes);C=P(0)==[1;0;0;0;0];[p1Sol(t),p2Sol(t),p3Sol(t),p4Sol(t),p5Sol(t)]=dsolve(odes,C);clffplot(p1Sol)hold onfplot(p2Sol)hold onfplot(p3Sol)hold onfplot(p4Sol)hold onfplot(p5Sol)grid onlegend('p1Sol','p2Sol','p3Sol','p4Sol','p5Sol','Location','best')
———————————–
Best Answer