Plotting ODE solutions for a single time point
조회 수: 1 (최근 30일)
이전 댓글 표시
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)')
댓글 수: 0
답변 (1개)
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
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 Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!