ploting second derivative from second order differential equationn
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
Jan
le 18 Mar 2021
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!