second_oder_ode
Error using odearguments
SECOND_ODER_ODE/RHS returns a vector of length 3, but the length of initial conditions vector is 2. The vector returned by SECOND_ODER_ODE/RHS and the initial conditions vector must have the same number of elements.

Error in ode45 (line 104)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);

Error in solution>second_oder_ode (line 19)
[t,x]=ode45( @rhs, t, [initial_x initial_dxdt] );
function second_oder_ode
% SOLVE d^2x2/dt^2 = (k(Asin(wt)-x2)-cA(dx/dt)/h)/m
% initial conditions: x(0) = 0, x'(0)=0
t=0:0.001:1;% time scale
initial_x = 0;
initial_dxdt = 0;
c=0.001;
h=0.01;
k=100;
m=1;
w=10;
A=2;
[t,x]=ode45( @rhs, t, [initial_x initial_dxdt] );
plot(t,x(:,1));
xlabel('t'); ylabel('x');
function dxdt=rhs(t,x)
dxdt_1 = x(2);
dxdt_2 = (k*(A*sin(w*t)-x)-(c*A/h)*x(2))/m;
dxdt=[dxdt_1; dxdt_2];
end
end

1 Kommentar

Dyuman Joshi
Dyuman Joshi am 27 Jan. 2024
Please share the mathematical definition of the equation you are trying to solve.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Sam Chak
Sam Chak am 27 Jan. 2024

0 Stimmen

I've indicated the location where you should apply a fix to it.
second_oder_ode
function second_oder_ode
% SOLVE d^2x2/dt^2 = (k(Asin(wt)-x2)-cA(dx/dt)/h)/m
% initial conditions: x(0) = 0, x'(0)=0
t=0:0.001:1;% time scale
initial_x = 0;
initial_dxdt = 0;
c=0.001;
h=0.01;
k=100;
m=1;
w=10;
A=2;
[t,x]=ode45( @rhs, t, [initial_x initial_dxdt] );
plot(t,x(:,1));
xlabel('t'); ylabel('x');
function dxdt=rhs(t,x)
dxdt_1 = x(2);
dxdt_2 = (k*(A*sin(w*t)-x(1))-(c*A/h)*x(2))/m;
% ^^^^
dxdt=[dxdt_1; dxdt_2];
end
end

Weitere Antworten (0)

Tags

Gefragt:

am 27 Jan. 2024

Beantwortet:

am 27 Jan. 2024

Community Treasure Hunt

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

Start Hunting!

Translated by