It says i don't have enough input agruments in line 3 of the function section and I dont know what is wrong
global m c k Omega f0
k=2000; % N/m
m=5; %kg
c=20; %kg/s
dt=0.005;
f0=37.5;
Omega= 25;
t=0:dt:5;
x0=[0 0];
function rl=f(t,y)
global m c k Omega f0
f=f0*sin(2*pi*Omega*t);
rl=[y(1); f/m-(c*y(1))/m-k*y(2)/(4*m)];
end

4 Kommentare

James Tursa
James Tursa am 25 Feb. 2021
Where is the rest of your code? Where is the ode45( ) call?
Jan
Jan am 25 Feb. 2021
The cause of the problem would be clear, if you post the complete code including the call to ODE45 and a copy of the complete error message.
I had the function and the rest of the code as two separate files. The error only appeared in the function file, this is why I didn't post the rest of the code. However when I combined them into a single file the problem appears to be gone, but the complete code and error that displayed was this:
clc;close all; clear;
global m c k Omega f0
k=500; % N/m
m=5; %kg
c=20; %kg/s
dt=0.005;
f0=37.5;
Omega= 25;
t=0:dt:5;
x0=[0 0];
[t,y]=ode45(@(t,y)f(t,y),t,x0);
plot(t,y(:,1))
--------------------------------------------------------------------------------
function rl=f(t,y)
global m c k Omega f0
f1=f0*sin(Omega*t);
rl=[y(2);(f1-c*y(2)-k*y(1)/4)/m];
end
Error in f (line 3)
f1=f0*sin(Omega*t);
Jan
Jan am 26 Feb. 2021
As far as I understand, your problem is solved. But it may help to improve future questions: You have still not posted a complete copy of the error message, but just the part, which explains where the problem occurred.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 25 Feb. 2021

0 Stimmen

We cannot see it, because you have not posted the complete code. But this has been the reason in many other questions in this forum:
[t, y] = ode45(rl, ...)
This calls rl without inputs. You want to provide the handle of the function instead:
[t, y] = ode45(@rl, ...)

Tags

Kommentiert:

Jan
am 26 Feb. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by