finding the value at a specific time from second-order ODE
Mostrar comentarios más antiguos
I'm new to MATLAB
I've been working on solving ODE and I now have learnt two ways to plot the 2-order ODE
- using ode45
- using conv() fucntion
Here's the problem : I want to know the value at a specific time for example f(2.5) when t=2.5
it can be displayed in any way like output in the command window or on the figure
please teach a way to output the value
I'll attach the files I've been working on
if you think the codes are tltr you could just give suggestions though
[time,y] = ode45('ode45_function' , [0 10] , [0,0]) ;
figure ;
subplot(212);plot(time,y(:,1));xlabel('t');ylabel('y(t)');
m = 5;
k = 18;
c = 1.2;
f0 = 100;
wn = sqrt(k/m);
cc = 2*m*wn;
Dr = c/cc;
wd = wn*sqrt(1-Dr^2);
dt = 0.001; % assumed dt
time = 0:dt:10;
f = zeros(1, length(time));
f(0001:3000) = (f0/3) * (0:dt:3-dt); % Linear increase from 0 to 3 seconds
f(3001:5000) = f0; % Constant from 3 to 5 seconds
% f remains 0 after 5 seconds
g = (1/(m*wd))*exp(-Dr*wn*time).*sin(wd*time);
x = conv(f, g)*dt;
x = x(1:length(time)); % Ensure x is the same length as time
% x is the solution function for the 2-order ODE
figure;
subplot(221); plot(time, f, 'r'); xlabel('t(s)'); ylabel('f(t)');
subplot(222); plot(time, g); xlabel('t(s)'); ylabel('g(t)');
subplot(223); plot(time, x); xlabel('t(s)'); ylabel('位移(m)');
% this is the function which I want to extract the specific value from
% it for ex: f(3), f(2.5) ...
function ydot=ode45_function(t,y)
m=5;
k=18;
c=1.2;
if t<3
f= 100*t/3;
elseif t<5
f=100;
else
f=0;
end
ydot(1)=y(2);
ydot(2)=(1/m)*(f-c*y(2)-k*y(1));
ydot=ydot';
end
Respuesta aceptada
Más respuestas (1)
Categorías
Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

