Not enough input arguments ode45

9 ビュー (過去 30 日間)
Alejandro Arias
Alejandro Arias 2024 年 5 月 10 日
コメント済み: Alejandro Arias 2024 年 5 月 10 日
Trying to find theta, angular velocity, and angular acceleration.
clear all
close all
clc
syms theta1(t)
%physical constants
Dd=0.1; Dw=0.75; Dh=0.5; Dm=15; ax=0.1; ay=0.5; b=0.25;
a = sqrt(ax^2 + ay^2); Jd = (1/3)*Dm*Dh^2;
Dweight=Dm*9.81;
thetaD0 = 0;
dthetaDdt0=0;
PHI = atand(ax/ay);
Lo = sqrt(a^2 + b^2 -2*a*b*cosd(PHI));
xmax = sqrt(a^2 + b^2 -2*a*b*cosd(PHI+90)) - Lo;
Ltotal = Lo + xmax;
k=500;
numphi = a*sind(PHI + thetaD0);
denphi = sqrt(a^2 + b^2 -2*a*b*cosd(PHI+thetaD0));
phi = asind(numphi/denphi);
d = 0.01;
%motor
NoLoadSpeed = 1057.672; %rad/s
Kt = 0.01386; %Vsec/rad
NoLoadI = 0.036; %A
Cvf = Kt*NoLoadI/NoLoadSpeed;
Jm =4.2E-7; %kg m^2
w = 1.5708/4 ; %rad/s
x = sqrt(a^2 + b^2 -2*a*b*cosd(PHI+theta1)) - Lo;
i=0.036;
[t, sol] = calcsum(thetaD0, dthetaDdt0, Cvf, b, phi, d, Dh, Dm, k, i, Kt, x, Jd, Jm)
%sol = [0;0;0]
%derivs = myODE(t, sol, Cvf, b, phi, d, Dh, Dm, k, i, Kt, x, thetaD0, Jd, Jm)
%%
function [t, sol] = calcsum(thetaD0, dthetaDdt0, Cvf, b, phi, d, Dh, Dm, k, i, Kt, x, Jd, Jm)
sol0 = [thetaD0; dthetaDdt0; i];
tspan = [0, 5];
[t, sol] = ode45(@(t, sol) myODE(sol, Cvf, b, phi, d, Dh, Dm, k, i, Kt, x, thetaD0, Jd, Jm), tspan, sol0);
end
%%
function derivs = myODE(t, sol, Cvf, b, phi, d, Dh, Dm, k, i, Kt, x, thetaD, Jd, Jm) %calc
dthetaDdt = sol(1);
g = (Kt*i - Cvf*dthetaDdt*(2*pi*b*sind(phi)/d));
num = 2*((2*pi/d)*((Kt*i - Cvf*dthetaDdt*(2*pi*b*sind(phi)/d))) + k*x)*b*sind(phi) - 0.5*Dm*9.81*Dh*sin(thetaD);
h = pi*b*sin(phi)/d;
den = Jd + 8*Jm*h^2;
ddthetaDdt = num/den;
derivs = [dthetaDdt; ddthetaDdt];
end
  1 件のコメント
Alejandro Arias
Alejandro Arias 2024 年 5 月 10 日
Here is the error, I do not know why it says I do not have enough input arguments when all variable in den are defined.
Not enough input arguments.
Error in MIEDC4>myODE (line 45)
den = Jd + 8*Jm*h^2;
Error in MIEDC4>@(t,sol)myODE(sol,Cvf,b,phi,d,Dh,Dm,k,i,Kt,x,thetaD0,Jd,Jm) (line 37)
[t, sol] = ode45(@(t, sol) myODE(sol, Cvf, b, phi, d, Dh, Dm, k, i, Kt, x, thetaD0, Jd, Jm), tspan, sol0);
Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 104)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Error in MIEDC4>calcsum (line 37)
[t, sol] = ode45(@(t, sol) myODE(sol, Cvf, b, phi, d, Dh, Dm, k, i, Kt, x, thetaD0, Jd, Jm), tspan, sol0);
Error in MIEDC4 (line 29)
[t, sol] = calcsum(thetaD0, dthetaDdt0, Cvf, b, phi, d, Dh, Dm, k, i, Kt, x, Jd, Jm)

サインインしてコメントする。

採用された回答

Sam Chak
Sam Chak 2024 年 5 月 10 日
There are numerous errors present. Since the code's mathematical expressions are written in a cluttered manner, I will focus solely on correcting the passing of extra parameters to the functions. It is essential for you to verify the correctness of the equations themselves. The symbolic variable 'theta1(t)' is unused.
% syms theta1(t)
%% physical constants
Dd=0.1; Dw=0.75; Dh=0.5; Dm=15; ax=0.1; ay=0.5; b=0.25;
a = sqrt(ax^2 + ay^2); Jd = (1/3)*Dm*Dh^2;
Dweight=Dm*9.81;
thetaD0 = 0;
dthetaDdt0=0;
PHI = atand(ax/ay);
Lo = sqrt(a^2 + b^2 -2*a*b*cosd(PHI));
xmax = sqrt(a^2 + b^2 -2*a*b*cosd(PHI+90)) - Lo;
Ltotal = Lo + xmax;
k=500;
numphi = a*sind(PHI + thetaD0);
denphi = sqrt(a^2 + b^2 -2*a*b*cosd(PHI+thetaD0));
phi = asind(numphi/denphi);
d = 0.01;
%% motor
NoLoadSpeed = 1057.672; %rad/s
Kt = 0.01386; %Vsec/rad
NoLoadI = 0.036; %A
Cvf = Kt*NoLoadI/NoLoadSpeed;
Jm = 4.2E-7; %kg m^2
w = 1.5708/4 ; %rad/s
% x = sqrt(a^2 + b^2 -2*a*b*cosd(PHI+theta1)) - Lo
i = 0.036;
tspan = [0, 5];
sol0 = [thetaD0; dthetaDdt0];
[t, sol] = ode45(@(t, sol) myODE(t, sol, Cvf, a, b, phi, PHI, d, Dh, Dm, k, i, Kt, Lo, Jd, Jm), tspan, sol0);
plot(t, sol), grid on, xlabel('t'), ylabel('Amplitude')
%% Differential equations
function derivs = myODE(t, sol, Cvf, a, b, phi, PHI, d, Dh, Dm, k, i, Kt, Lo, Jd, Jm) % calc
thetaD = sol(1);
dthetaDdt = sol(2);
x = sqrt(a^2 + b^2 -2*a*b*cosd(PHI+ thetaD )) - Lo;
g = (Kt*i - Cvf*dthetaDdt*(2*pi*b*sind(phi)/d));
num = 2*((2*pi/d)*((Kt*i - Cvf*dthetaDdt*(2*pi*b*sind(phi)/d))) + k*x)*b*sind(phi) - 0.5*Dm*9.81*Dh*sin(thetaD);
h = pi*b*sin(phi)/d;
den = Jd + 8*Jm*h^2;
ddthetaDdt = num/den;
derivs = [dthetaDdt;
ddthetaDdt];
end
  1 件のコメント
Alejandro Arias
Alejandro Arias 2024 年 5 月 10 日
@Sam Chak, thank you! You're a champ.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by