ode45 not working
13 ビュー (過去 30 日間)
古いコメントを表示
Trying to solve this functions but it give me this error. Can some one find the error I have?
Im new to ode45
global m g r I ks
m = 5;
g = 9.81;
r = 0.470;
I = 0.37;
ks = 0.012;
dt = 0.01;
tspan = (0:dt:5);
x0 = [0,0];
[t,x] = ode45(funcionMAT,tspan,x0);
plot(t,x(:,1));
plot(t,x(:,2));
a = x(2)-x(1)/dt;
plot(t,a);
Error
Attempt to execute SCRIPT funcionMAT as a function:
D:\Users\Javier E. Negron\Documents\Trabajos de universidad (ene-may 2021)\Capstone\funcionMAT.m
Error in Analisis_de_movimiento2 (line 13)
[t,x] = ode45(funcionMAT,tspan,x0);
My function is
global m g r I ks
function xdot = Analisis_de_movimiento2(~,x)
A = [0,1;(-ks*x(1)-(m*g*r/2)*cos(x(1))+(2*pi/3)*ks)*x(1)/(I + m*r^2),0];
xdot = A * [x(1);x(2)];
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/611125/image.png)
0 件のコメント
回答 (2 件)
Carly McKean
2023 年 11 月 15 日
I think you need to make these changes:
[t,x] = ode45(Analisis_de_movimiento2,tspan,x0);
and rename your file functionMAT to Analisis_de_movimiento2
0 件のコメント
Steven Lord
2023 年 11 月 15 日
The way you've written your funcionMAT file, it is a script file (because the first line does not start with either function or classdef.) Then you try to call it as though it were a function, but that doesn't work because it's a script. Get rid of the global line entirely (by parameterizing your function) and it becomes a function file.
In addition, the way you're calling ode45 attempts to call the funcionMAT function with 0 inputs and pass whatever that returns into ode45 as the first input argument. Instead you want to pass a function handle to funcionMAT into ode45. With the function handle, ode45 will be able to call funcionMAT with inputs of its choosing as needed.
[t,x] = ode45(@funcionMAT,tspan,x0); % Note the @ symbol
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!