How to arrange correctly with a graph

1 次查看(过去 30 天)
Hello,
I want to produce a graph using ode45,But it gives me an error.
Thanks for the helpers
function second_oder_ode
h=0.01;
t = 0:h:60;
initial_y = 0;
initial_dydt = 0;
[t,y]=ode45( @rhs, t, [initial_y initial_dydt] );
plot(t,y(:,1));
xlabel('t'); ylabel('y');
function y_out=rhs(y)
L0=128;
W=100;
g = 9.81; % Gravitational acceleration (m/s^2)
A=(pi*(0.02)^2)/4;
m=W/g; % Mass of the jumper (kg)
if y(1)<=L0
y_out = [y(2);g];
else
y_out = [y(2);g-((Viscosity(y)*(y(1)-L0)^0.8)*y(2))/(m*y(1))-(ElasticModulus(y)*y(1)*A)/(m*L0)];
end
function [eta]=Viscosity(y)
L0=128;
gammadot= y(2)/(y(1)-L0);
table_gammadot=[0.02 0.05 0.09 0.18 0.3 0.5 0.9 1.8 3 5 9 18 30];
table_eta=[62.20241 28.73309 16.96822 9.024566 5.742004 3.634656 2.099485 1.107372 0.703221 0.429745 0.251424 0.134518 0.082058];
eta=interp1(table_gammadot, table_eta, gammadot, 'nearest', 'extrap');
end
function [G]=ElasticModulus(y)
L0=128;
lambda=y(1)/L0;
table_lambda=[1.355667 1.67225 1.981016 2.309324 2.645449 2.973758 3.302066 3.626466 3.954774 4.294807 4.619207 4.947515 5.291457 5.486879 5.93244 6.25684 6.596873 6.925181 7.241764];
table_G=[117.957 177.1892 183.9973 189.4069 193.7871 196.9072 195.846 199.0777 205.7417 168.6455 175.6384 234.3298 252.4299 277.298 291.751 317.9678 347.2071 382.3623 478.0037];
G=interp1(table_lambda, table_G, lambda, 'nearest', 'extrap')*1000;
end
end
end

采纳的回答

Mischa Kim
Mischa Kim 2021-1-2
Anton, add t as an input arg to:
function y_out=rhs(t,y)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by