ODE45 Returning Wrong Signed Answer
显示 更早的评论
Hey, I have been struggling with this for the past few days. Basically, I have an equation that models the angular acceleration of a rigid body (pendulum). I want to integrate it twice (to get the plot of angle vs time). The angle should be decreasing, however, in my plot it is increasing. I can't seem to figure out why. The equation is correct, I suspect there is something I have implemented wrong.
Here is a sample of my code, first I have the function in its own file, then I use the main code with the input main. If you have any idea why it is producing the wrong answer please let me know
function dydt = phiddot
g=9.81; L=1; m=1;
dydt = [y(2); ((-6*g*sin(y(1)))/(L*(1+3*(sin(y(1))^2))))];
end
function maincode = main
t0=0;
T=10;
y0 = [60;0];
[ts,ys] = ode45(@phi_ddot,[t0,T],y0);
plot(ts,ys(:,1),'r')
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Lengths and Angles 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!