I am unable to run this program.
1 次查看(过去 30 天)
显示 更早的评论
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)-(c*A/h)*x(2))/m;
dxdt=[dxdt_1; dxdt_2];
end
end
1 个评论
Dyuman Joshi
2024-1-27
Please share the mathematical definition of the equation you are trying to solve.
采纳的回答
Sam Chak
2024-1-27
Hi @Puja
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
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!