How do i plot a derivative versus time

1 view (last 30 days)
Siddharth Jain
Siddharth Jain on 16 Nov 2022
Edited: Torsten on 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

Answers (1)

Torsten
Torsten on 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 Comments
Torsten
Torsten on 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 on 16 Nov 2022
sorry, it was my fault. Thanks once again!

Sign in to comment.

Categories

Find more on Colormaps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!