Solving 2nd Order ODE with MATLAB:Input Argument "a" is Undefined

In summary, the function "canti" solves a non-linear equation of motion for a cantilever beam with a lumped mass. It takes in several inputs, including the damping ratio, excitation amplitude, and frequency, and calculates various parameters such as the stiffness, density, and radius of curvature. The function can be called using the "ode45" command in MATLAB to solve the equation and output a plot of the beam's displacement over time.
  • #1
mohamed_ali
6
0
hi
i am trying to solve second order ODE in MATLAB but when i write my scribt and call into the command window using ode45 i get input argument "a" is undefined i have spent so much time trying to figure out what the problem is but unsuccessful.

the function is as follows

function da_dt=canti(t,a,flag,zeta,epsi,lampda,z,omega)
%this function solves the non-linear equation of motion for a cantilever
%beam with lumped mass




L=125.4; % Lenght of the beam, the units are in mm

r=125.4; % this is the radius of gyration of the beam (mm)

J=600.9; % polar moment of inertia, unit which are mm^4

d=93.68; %position of mass (mm)

E=0.20936e-6; % stiffness of the beam (N/mm^2)

w=11.11; % this is the width of the beam (mm)

m=14.70; % the mass (g)



g=9.81; % acceleration due to gravity (m/s^2)

%lampda=1; lampda=r/L

h=0.368; %the thickness of the beam (mm)

I=4.626e-2; %cross-sectional moment of inertia (mm^4)

rho=0.03177; % the density (g/mm^3)

k=1.609; %radius of curevature of the beam at s





H11=0.977127;
H12=0.977127;
H13=0.687553;
H21=0.977127;
H31=0.977127;
H32=0.168365;
H33=0.153578;
H34=0.270738;
H41=0.325800;
H42=0.578800;
H43=-0.319906;
H51=0.217654;
H52=0.732989;
H53=0.472729;
H61=0.217654;
H62=0.231875;
H63=0.732989;
H64=0.393123;
H65=0.236364;

if nargin<1, zeta=1.469e-3; %this is the damping ratio
end
if nargin<2, epsi=1; %this value is intoduced to show the smallness of damping, nonlinear terms,and excitation
end
if nargin<3, lampda=1;
end

if nargin<4, z=2;% this is the amplitude of the excitation
end

if nargin<5, omega=5; %frequency of excitation
end
mu=m/rho*L;
Q=(H11+mu*H12+J(1)*H13*lampda*lampda);

c=abs(2*zeta*sqrt(E*m));
zeta1=(c*H21)/(2*epsi*rho*Q);

alpha1=((E*I*lampda*lampda)/(epsi*rho*Q*L^4))*((k^4)*(H41+mu*H42)+H43);

J(1)=J/rho*L*r^2;

theta=abs(sqrt(((E*I*k^4)*(H31+mu*H32)/(rho*L^4)-(g/L)*(H33+mu*H34))/Q));

zeta=zeta1/theta;
alpha=alpha1/theta;
phi=omega/theta;

lampda=r/L;

f=(omega*omega*(z))*(H33+mu*H34)/(epsi*(theta^2)*(Q));


K1=((lampda*lampda)*(H51+mu*H52+H53*J(1)*lampda*lampda)/epsi*Q);

K2=((lampda*lampda)*(H61-H62+mu*H63-mu*H64+J(1)*H65*lampda*lampda)/epsi*Q);

da_dt=zeros(2,1);


da_dt(1)=a(2);
da_dt(2)=-((2*zeta*epsi*a(2)+(1 - epsi*f*cos(phi*t))*a(1)+epsi*alpha*(a(1)*a(1)*a(1))+epsi*K1*a(1)*a(2)*a(2))/(1 + epsi*K2*a(1)*a(1)));

end

please can anyone help

thanks
 
Physics news on Phys.org
  • #2
Does it tell you what line it breaks at? My guess would be to rename the variable "a" to something else.
 
  • #3
thanks for the reply gb7nash yeah it tells me that error is at da_dt=a(2) but i will try to rename the variable "a" to something else
 
  • #4
If memory serves me right, you want to avoid using single-letter variables (in any programming language). Sometimes they're predefined to do something else. I can't remember if that occurs on MATLAB and I can't compile it (my license expired). That would be my guess though, the syntax looks fine.
 
  • #5
How are you calling the function with ode45?

Also, for readability post the code in
Code:
tags...
 
  • #6
thanks for the reply jhae2.718
i am calling the ode like [t,a]=ode45('canti',[0 20],[0.1;0],[],zeta,epsi,lampda,z,omega)

sorry i didnt understand what you meant by "post the code in
Code:
tags..." and btw i am not using pi (π) am using ϕ (phi)
 
  • #7
Can you post the exact error? Also, does the function work if you call it directly?

Regarding the code tags, edit your post and type
Code:
 before your code, and
after.
 
  • #8
mohamed_ali said:
hi
Code:
da_dt(2)=-((2*zeta*epsi*a(2)+(1 - epsi*f*cos(phi*t))*a(1)+epsi*alpha*(a(1)*a(1)*a(1))+epsi*K1*a(1)*a(2)*a(2))/(1 + epsi*K2*a(1)*a(1)));

I'm assuming you want this to be a singular value? As it currently is, it will return a vector the length of t, which will throw a vertcat error when you try and assign it to da_dt.
 
  • #9
I have noticed the error only occures when I debug the code but when I call the function it seems to be working fine. however another problem i have is that when I give a default value to variables by using nargin< , I get the message "too many input arguments" . by using nargin the value given to the variables should be recognised by the Matlab but its not seem to be doing that instead, i have to write the default values again in the command window.

Code:
function da_dt=canti(t,a,zeta,epsi,lampda,z,omega)
%this function solves the non-linear equation of motion for a cantilever
%beam with lumped mass




L=125.4;   % Lenght of the beam, the units are in mm

r=125.4; % this is the radius of gyration of the beam (mm)

J=600.9; % polar moment of inertia, unit which are mm^4

d=93.68;  %position of mass (mm)

E=0.20936e-6; % stiffness of the beam (N/mm^2)
  
w=11.11;      % this is the width of the beam (mm)

m=14.70;        % the mass (g)



g=9.81; % acceleration due to gravity (m/s^2)

%lampda=1;  lampda=r/L

h=0.368;  %the thickness of the beam (mm)

I=4.626e-2; %cross-sectional moment of inertia (mm^4)

rho=0.03177;  % the density (g/mm^3)

k=1.609;    %radius of curevature of the beam at s





H11=0.977127;
H12=0.977127;
H13=0.687553;
H21=0.977127;
H31=0.977127;
H32=0.168365;
H33=0.153578;
H34=0.270738;
H41=0.325800;
H42=0.578800;
H43=-0.319906;
H51=0.217654;
H52=0.732989;
H53=0.472729;
H61=0.217654;
H62=0.231875;
H63=0.732989;
H64=0.393123;
H65=0.236364;

if nargin<1, zeta=1.469e-3; %this  is the damping ratio
end
if nargin<2, epsi=1;   %this value is intoduced to show the smallness of damping, nonlinear terms,and excitation
end
if nargin<3,  lampda=1;
end

if nargin<4, z=2;%  this is the amplitude of the excitation
end

if nargin<5, omega=5;  %frequency of excitation
end
mu=m/rho*L;
Q=(H11+mu*H12+J(1)*H13*lampda*lampda);

c=abs(2*zeta*sqrt(E*m));
zeta1=(c*H21)/(2*epsi*rho*Q);

alpha1=((E*I*lampda*lampda)/(epsi*rho*Q*L^4))*((k^4)*(H41+mu*H42)+H43);

J(1)=J/rho*L*r^2;

theta=abs(sqrt(((E*I*k^4)*(H31+mu*H32)/(rho*L^4)-(g/L)*(H33+mu*H34))/Q));

zeta=zeta1/theta;
alpha=alpha1/theta;
phi=omega/theta;

lampda=r/L;

f=(omega*omega*(z))*(H33+mu*H34)/(epsi*(theta^2)*(Q));


K1=((lampda*lampda)*(H51+mu*H52+H53*J(1)*lampda*lampda)/epsi*Q);

K2=((lampda*lampda)*(H61-H62+mu*H63-mu*H64+J(1)*H65*lampda*lampda)/epsi*Q);

da_dt=zeros(2,1);


da_dt(1)=a(2);  
da_dt(2)=-((2*zeta*epsi*a(2)+(1 - epsi*f*cos(phi*t))*a(1)+epsi*alpha*(a(1)*a(1)*a(1))+epsi*K1*a(1)*a(2)*a(2))/(1 + epsi*K2*a(1)*a(1)));

the code used to call the function is

Code:
>> zeta=1.469e-3;
>> epsi=1;
>> lampda=1;
>> z=2;
>> omega=5;
>> [t,a]=ode45('canti',[0 72],[0.1;0],[],zeta,epsi,lampda,z,omega);
>> plot(t,a(:,1)); grid on;
 
  • #10
jhae2.718 said:
I'm assuming you want this to be a singular value? As it currently is, it will return a vector the length of t, which will throw a vertcat error when you try and assign it to da_dt.

sorry i don't understand what you mean with vertcat error
 
  • #11
Your code works for me if you just set the values for zeta, epsi ,lampda ,z, and omega in the script, and not use them as function arguments. You could also throw them onto the end of a and set those parameters in the initial a matrix.

Never mind the bit about vertcat.
 
  • #12
yeah it works fine thanks a lot for your help
 
  • #13
No problemo.
 

1. What does the input argument "a" represent in solving 2nd order ODE with MATLAB?

The input argument "a" represents the coefficient of the second derivative in the second order ODE (Ordinary Differential Equation). It is typically denoted as "a" in the general form of a second order ODE: a*y'' + b*y' + c*y = f(x).

2. Why is the input argument "a" undefined in MATLAB?

The input argument "a" may be undefined in MATLAB if it was not declared or assigned a value before being used in the ODE solving function. It is important to define all input arguments before using them in a program to avoid errors.

3. How can I define the input argument "a" in MATLAB?

The input argument "a" can be defined in MATLAB by using the equal sign (=) to assign a value to it. For example, a = 2 assigns the value of 2 to the input argument "a". It can also be defined as a variable or an array with multiple values.

4. Can the input argument "a" be a complex number in MATLAB?

Yes, the input argument "a" can be a complex number in MATLAB. Complex numbers can be defined using the imaginary unit "i" or "j", for example, a = 2 + 3i or a = 4 - 6j. However, it is important to make sure that the input argument "a" is defined as a complex number if the ODE involves complex operations.

5. How can I troubleshoot the "Undefined input argument "a"" error in MATLAB?

To troubleshoot the "Undefined input argument "a"" error in MATLAB, you can check if the input argument "a" was declared and assigned a value before being used. You can also check if there are any typos or errors in the code that may be causing the error. Additionally, you can use the MATLAB debugger to step through the code and see where the error is occurring.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Math Proof Training and Practice
2
Replies
46
Views
4K
Replies
9
Views
2K
Back
Top