ploting second derivative from second order differential equationn

조회 수: 13 (최근 30일)
Muhammad Sarmad Zahid
Muhammad Sarmad Zahid 2021년 3월 18일
댓글: Jan 2021년 3월 20일
Hi, Beloow is my code and i am solving second order differential equation numericaly and i am getting plot of first and zeroth derivation from ode45. is there any way to plot the second derivative as well by just calling ode45 ?
function fval = simulation( t,y )
x=y(1);
v=y(2);
c=6850;
m=450;
k=0;
f=2650;
e=535;
w=4410;
fval(1,1)=v;
%fval(2,1)= -(c*v+k*x)/m
fval(2,1)=(-c*v-f-e+w+k*x)/m;
end
%%%%main file%%%%%%
c=6850;
m=450;
k=0;
f=2650;
e=535;
w=4410;
Y0= [0;3.86];
tspan= [0 1];
options= odeset ('Events', @event);
[tsol,ysol] = ode45(@(t,y) simulation(t,y), tspan, Y0,options);
figure
plot(tsol,ysol(:,1), 'r-');
hold on;
figure
plot(tsol,ysol(:,2), 'g-');
hold on;
figure

채택된 답변

Jan
Jan 2021년 3월 18일
The easiest solution is to let the function to be integrated accept vectors as input and call it with the time steps and positions replied by ODE45:
[tsol, ysol] = ode45(@(t,y) simulation(t,y), tspan, Y0,options);
dy = simulation(tsol, ysol.').';
d2y = dy(:, 2);
function fval = simulation(t, y)
x = y(1, :);
v = y(2, :);
c = 6850;
m = 450;
k = 0;
f = 2650;
e = 535;
w = 4410;
fval(1, :) = v;
fval(2, :) = (-c * v - f - e + w + k * x) / m;
end
  댓글 수: 12
Jan
Jan 2021년 3월 20일
But this is the same question again?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by