Please help i seem to be failing to understand what the following errors mean and how to correct for them.
2 ビュー (過去 30 日間)
古いコメントを表示
%Script file for the Analysis of the double Pendulum(Chaos)
%Purpose : School Assignment
%written by : Yolanda Dube
g = 9.8; %gravitational Acceleration
l1 = 1; %length of the first rope
l2 = 1; %lenght of the second rope
m1 = 0.5; %mass of particle 1
m2 = 0.5; %mass of particle 2
t = 0:0.02:20*pi; %time period
th1 = 45; %angular displacement
th2 = 0; %angular displacement
v1 = 0; %initial velocity of the first particle
v2 = 0; %initial velocity of the second particle
yi = (pi/180).*[th1;0;th2;0];
%%using the differential equation tool
t0 = 0;
[t,y] = ode45(@yi,t0,t,f)
%%trajectory
x1 = l1*sin(y(1,:));
y1 = l1*cos(y(1,:));
x2 = l1*sin(y(1,:)) + 12*sin(y(3,:));
y2 = -l1*cos(y(1,:)) - 12*cos(y(3,:));
subplot(2,2,1)
xgrid
plot(x1,y1,'-ob')
plot(x2,y2,'-dr')
xtitle('TRAJECTORY')
subplot(2,2,2)
xgrid
plot(t, (180/pi)*y(1,:),'-ob')
plot(t,(180/pi)*y(3,:),'-dr')
xtitle('Angular displacement of m1 AND m2')
subplot(2,2,3)
xgrid
plot(t,(180/pi)*y(2,:),'-ob')
plot(t,(180/pi)*y(4,:),'-dr')
xtitle('Velocity of m1 AND m2')
subplot(2,2,4)
xgrid
plot(t,(180/pi).*y(1,:),(180/pi).*y(3,:),'k')
%%Looping our sytems of equations
function [ydash]=f(t,y)
ydash(t,1)=y(2)
ydash(t,2)=(1/((m1+m2)*l1-m2*l1*((cos(y(1)-y(3)))^2)))*(-m2*l1*(y(2)*y(2))*sin(y(1)-y(3))*cos(y(1)-y(3)) + m2*g*sin(y(3))*cos(y(1)-y(3)) - m1*l2*(y(4)*y(4))*sin(y(1)-y(3)) - (m1+m2)*g*sin(y1))
ydash(t,3) = y(4)
y(4) = (1/(l2-(m2*l2/(m1+m2))*((cos(y(1)-y(3)))^2)))*(l1*(y(2)*y(2))*sin(y(1)-y(3)) - g*sin(y(3)) + (m2*l2/(m1+m2))*(y(4)*y(4))*sin(y(1)-y(3))*cos(y(1)-y(3)) + g*sin(y(1))*cos(y(1)-y(3)))
end
4 件のコメント
Stephen23
2021 年 9 月 2 日
編集済み: Stephen23
2021 年 9 月 2 日
yi is a 4x1 numeric, you cannot define a function handle from it by simply placing '@' in front of its variable name.
How to define valid function handles is covered quite well in the MATLAB documentation:
The fourth input argument to ODE45 is defined in the documentation as a structure of options for the ODE solver. Instead you called the function f without any input arguments (thus the error message you are getting). Even if you provided f with input arguments it does not return a structure of options, so it is not clear why you expect this to be a valid fourth input to ODE45.
I suspect that you should be providing a handle to f as the first input.
It is not clear what you expect defining the value of y at the very end of f is going to achieve.
採用された回答
Stephen23
2021 年 9 月 2 日
編集済み: Stephen23
2021 年 9 月 2 日
I suspect that something like this is what you are trying to do (I fixed many small bugs):
g = 9.8; %gravitational Acceleration
l1 = 1; %length of the first rope
l2 = 1; %lenght of the second rope
m1 = 0.5; %mass of particle 1
m2 = 0.5; %mass of particle 2
th1 = 45; %angular displacement
th2 = 0; %angular displacement
v1 = 0; %initial velocity of the first particle
v2 = 0; %initial velocity of the second particle
y0 = (pi/180).*[th1;0;th2;0];
ts = 0:0.02:20*pi; %time period
fun = @(t,y)f(t,y,m1,m2,l1,l2,g); % parameterize function
[t,y] = ode45(fun,ts,y0)
function ydash = f(t,y,m1,m2,l1,l2,g)
ydash = nan(4,1); % preallocate!
ydash(1) = y(2);
ydash(2) = (1/((m1+m2)*l1-m2*l1*((cos(y(1)-y(3)))^2)))*(-m2*l1*(y(2)*y(2))*sin(y(1)-y(3))*cos(y(1)-y(3)) + m2*g*sin(y(3))*cos(y(1)-y(3)) - m1*l2*(y(4)*y(4))*sin(y(1)-y(3)) - (m1+m2)*g*sin(y(1)));
ydash(3) = y(4);
ydash(4) = (1/(l2-(m2*l2/(m1+m2))*((cos(y(1)-y(3)))^2)))*(l1*(y(2)*y(2))*sin(y(1)-y(3)) - g*sin(y(3)) + (m2*l2/(m1+m2))*(y(4)*y(4))*sin(y(1)-y(3))*cos(y(1)-y(3)) + g*sin(y(1))*cos(y(1)-y(3)));
end
See also:
その他の回答 (1 件)
Matt J
2021 年 9 月 2 日
編集済み: Matt J
2021 年 9 月 2 日
Not sure what you are trying to do with ode45. The way you are invoking it does not match any syntax in the documentation. Perhaps this is what you meant,
[t,y] = ode45(@f,t,yi)
2 件のコメント
Matt J
2021 年 9 月 2 日
You're welcome, but please Accept-click the answer that you feel resolved your question.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!