Too many input arguments in ode45 using anonymous function
Mostrar comentarios más antiguos
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 comentarios
madhan ravi
el 12 de Jun. de 2020
Editada: madhan ravi
el 12 de Jun. de 2020
@(t,w) ...
We can’t run picture , upload your code as text.
DAKSH GANATRA 17BME0726
el 12 de Jun. de 2020
DAKSH GANATRA 17BME0726
el 12 de Jun. de 2020
Respuestas (2)
Steven Lord
el 12 de Jun. de 2020
0 votos
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 comentarios
DAKSH GANATRA 17BME0726
el 12 de Jun. de 2020
Steven Lord
el 12 de Jun. de 2020
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
el 13 de Jun. de 2020
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'})

Categorías
Más información sobre Numerical Integration and Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!