How do i plot a derivative versus time
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
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
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
See Also
Categories
Find more on Colormaps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!