How do i plot a derivative versus time

1 visualizzazione (ultimi 30 giorni)
Siddharth Jain
Siddharth Jain il 16 Nov 2022
Modificato: Torsten il 16 Nov 2022
I have the code below and want to plot for eg yp(2) vs time-
How can I do this?
function yp = reduced(t,y)
m_a = 0.5;
c_ay=1;
c_az=1;
k_ay= 1;
k_az =1;
Fy=@(t)1;
Fz=@(t)1;
T_a = @(t)178;
I_a = 2000;
R_a=1;
yp = zeros(6,1);
yp(1) = y(2);
yp(2) = (-Fy(t) - k_ay*y(1) - c_ay*y(2))/m_a;
yp(3) = y(4);
yp(4) = (-Fz(t) - k_az*y(3) - c_az*y(4))/m_a;
yp(5) = y(6);
yp(6) = (-T_a(t) - Fy(t)*R_a)/I_a;
end

Risposte (1)

Torsten
Torsten il 16 Nov 2022
[T,Y] = ode45(@reduced,tspan,y0)
for i = 1:numel(T)
dy(i,:) = reduced(T(i),Y(i,:));
end
plot(T,dy(:,2))
  3 Commenti
Torsten
Torsten il 16 Nov 2022
Runs without problems.
tspan = [0 10];
y0 = zeros(6,1);
[T,Y] = ode45(@reduced,tspan,y0);
for i = 1:numel(T)
dy(i,:) = reduced(T(i),Y(i,:));
end
plot(T,dy(:,2))
function yp = reduced(t,y)
m_a = 0.5;
c_ay=1;
c_az=1;
k_ay= 1;
k_az =1;
Fy=@(t)1;
Fz=@(t)1;
T_a = @(t)178;
I_a = 2000;
R_a=1;
yp = zeros(6,1);
yp(1) = y(2);
yp(2) = (-Fy(t) - k_ay*y(1) - c_ay*y(2))/m_a;
yp(3) = y(4);
yp(4) = (-Fz(t) - k_az*y(3) - c_az*y(4))/m_a;
yp(5) = y(6);
yp(6) = (-T_a(t) - Fy(t)*R_a)/I_a;
end
Siddharth Jain
Siddharth Jain il 16 Nov 2022
sorry, it was my fault. Thanks once again!

Accedi per commentare.

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by