Too many input arguments in ode45 using anonymous function
古いコメントを表示
I am trying to solve a forced vibration problem using state spac representation. Please tell me what is wrong with my code.
mass = 750; % Mass of the body [kg]
stiffness = 50000; % Stiffness Coefficient of spring [N/m]
damping = 0; % Damping coefficient of damper [Ns/m]
time = 0:0.01:1; % Time [s]
x_0 = 0.01; % Initial Condition displacement
x_dot_0 = 0; % Initial Condition velocity
mass_extruded = 0.03; % Mass of the excitation [kg]
omega = 6.28; % Angular frequency of the excitation [1/s]
radius = 0.24; % Radius of the excitation [m]
force = omega^2*radius*mass_extruded; % Calculate the force with given parameters
w0 = [x_0, x_dot_0]; % Create a vector with initial conditions
A = [0 1; -stiffness/mass -damping/mass]; % Create system Matrix
B = [0; force/mass]; % Create excitation vector
dw = @(w) A*w - B*cos(omega*time); % Define derivative
[tsim,wsim] = ode45(@(w) dw, time, w0);

3 件のコメント
madhan ravi
2020 年 6 月 12 日
編集済み: madhan ravi
2020 年 6 月 12 日
@(t,w) ...
We can’t run picture , upload your code as text.
DAKSH GANATRA 17BME0726
2020 年 6 月 12 日
DAKSH GANATRA 17BME0726
2020 年 6 月 12 日
回答 (2 件)
Steven Lord
2020 年 6 月 12 日
0 投票
The ODE solvers will generally (with the exception of ode15i) call your ODE function with two input arguments. [ode15i will call your ODE function with three input arguments.] Even if your ODE function doesn't use both of those input arguments, it must accept them.
Your dw function probably wants to accept the time input t and use it instead of the vector time that it currently uses.
2 件のコメント
DAKSH GANATRA 17BME0726
2020 年 6 月 12 日
Steven Lord
2020 年 6 月 12 日
As madhan ravi said, "dw = @(t, w) ...". My suspicion is that you want to use t instead of time in the body of the dw function.
Ameer Hamza
2020 年 6 月 13 日
There are some mistakes in the way you wrote the ODE and called ode45. Following code run fine
mass = 750; % Mass of the body [kg]
stiffness = 50000; % Stiffness Coefficient of spring [N/m]
damping = 0; % Damping coefficient of damper [Ns/m]
time = 0:0.01:1; % Time [s]
x_0 = 0.01; % Initial Condition displacement
x_dot_0 = 0; % Initial Condition velocity
mass_extruded = 0.03; % Mass of the excitation [kg]
omega = 6.28; % Angular frequency of the excitation [1/s]
radius = 0.24; % Radius of the excitation [m]
force = omega^2*radius*mass_extruded; % Calculate the force with given parameters
w0 = [x_0; x_dot_0]; % Create a vector with initial conditions
A = [0 1; -stiffness/mass -damping/mass]; % Create system Matrix
B = [0; force/mass]; % Create excitation vector
dw = @(t, w) A*w - B*cos(omega*t); % Define derivative
[tsim,wsim] = ode45(dw, time, w0); % equivalent: [tsim,wsim] = ode45(@(t, w) dw(t, w), time, w0);
plot(tsim, wsim)
legend({'x', 'x\_dot'})

カテゴリ
ヘルプ センター および File Exchange で Numerical Integration and Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!