Plotting ODE solutions for a single time point

조회 수: 1 (최근 30일)
Aishah Malek
Aishah Malek 2018년 9월 11일
댓글: Star Strider 2018년 9월 11일
I have plotted the solution to four odes against time.
I now want to plot results for a single time point. Such as for when t=5, i want to plot c_{j}(5) against j. Is there a short command that can do this using the code i have written
function f = beckerdorin(t,C)
a=0.5;
b=1.5;
sigma=0.5;
f(1,1)= b*(C(4)+ C(3)+ 2*C(2))-a*C(1)*(2*C(1)+C(2)+C(3));
f(2,1)= a*(C(1))^2 - b*C(2) - a*C(1)*C(2) + b*C(3)-2*sigma*(a*C(2)^2-b*C(4));
f(3,1)= a*C(2)*C(1)-b*C(3)-a*C(3)*C(1)+b*C(4);
f(4,1)= a*C(3)*C(1)-b*C(4)+sigma*(a*C(2)^2-b*C(4));
end
Plotting
clf
[tv,c] = ode45('beckerdorin',[0,3],[10,0,0,0]);
figure(2)
plot(tv,c(:,1),'r');hold on
plot(tv,c(:,2),'b');hold on
plot(tv,c(:,3),'y');hold on
plot(tv,c(:,4),'g');
legend('C(1)','C(2)','C(3)','C(4)')
xlabel('Time t')
ylabel('c_{j}(t)')

답변 (1개)

Star Strider
Star Strider 2018년 9월 11일
It requires that you slightly change your ode45 call, then use the solution structure with the odextend (link) function:
sln = ode45(@beckerdorin,[0,3],[10,0,0,0])
tv = sln.x';
c = sln.y';
figure(2)
plot(tv,c(:,1),'r');hold on
plot(tv,c(:,2),'b');hold on
plot(tv,c(:,3),'y');hold on
plot(tv,c(:,4),'g');
legend('C(1)','C(2)','C(3)','C(4)')
xlabel('Time t')
ylabel('c_{j}(t)')
slnxtd = odextend(sln, @beckerdorin, 5); % Extend Integration To ‘t=5’
c_5 = slnxtd.y(:,end) % Values Of ‘c’ At ‘t=5’
c_5 =
2.02359968542774
1.3649852291002
0.920727887972237
0.621061548113791
  댓글 수: 2
Aishah Malek
Aishah Malek 2018년 9월 11일
Thankyou, but what if i want to change my j value ,i get the same results when i try another value for j, and also if i want to plot different j values on the same plot.
Star Strider
Star Strider 2018년 9월 11일
My pleasure.
What are you referring to? I do not see ‘j’ defined anywhere in your code. I have no idea what it is. It only appears as part of a character vector in your ylabel call.
You asked how to evaluate your ‘beckerdorin’ function at ‘t=5’, and I provided a way to do that.
I leave the rest to you.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by