Plotting graphs while solving Multiple Differential Equations using ODE45
Show older comments
I created two different scripts to solve a system of differential Equations, while the code worked perfectly fine and graphs were as I expected, I wasn't able to concatenate the various graphs through the "hold on". Please help me locate the error or I would love a new improved version of this code.
The two scripts are:
***********************************************************************************
****Script 1
function fval=rotationeqn(t,y)
A11=y(1);
A12=y(2);
A22=y(3);
recilamda=1000;
Wi=0;
fval(1,1)=-1*recilamda*(A11-1)+Wi*recilamda*A12;
fval(2,1)=-1*recilamda*A12+Wi*0.5*recilamda*(A22-A11);
fval(3,1)=-1*recilamda*(A22-1)-Wi*recilamda*A12;
hold on
Wi=1;
fval(1,1)=-1*recilamda*(A11-1)+Wi*recilamda*A12;
fval(2,1)=-1*recilamda*A12+Wi*0.5*recilamda*(A22-A11);
fval(3,1)=-1*recilamda*(A22-1)-Wi*recilamda*A12;
hold on
end
**********************************************************************************************
*****script 2
x=pi/6;
yo=[cos(x)*cos(x);sin(x)*cos(x);sin(x)*sin(x)];
tSpan=[0:0.00001:0.01];
[tSol,ySol]=ode45(@(t,y) rotationeqn(t,y),tSpan,yo);
plot(tSol,ySol(:,2),'r');
hold on
********************************************************************************************
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!