------------------------------------------------------
function homework2 = main2(t,X1,X2)
global m1 c1 k1 m2 c2 k2
M=[m1 0;0 m2];
C=[c1+c2 -c2; -c2 c2];
K=[k1+k2 -k2; -k2 k2];
F=[3*cos(t);10*cos(3*t)];
X=[X1;X2];
homework2=M*X(3)+C*X(2)+K*X(1)-F;
end
-------------------------------------------------------
tspan= 0:0.1:50 ;
X0 = [0 0;0 0] ;
[t, X] = ode45(@main2, tspan, X0);
plot(X1,X2)
I do it here and it 's ain't working....

 採用された回答

Birdman
Birdman 2020 年 3 月 20 日

0 投票

You may try Symbolic Toolbox to solve the problem. Run the attached script to see the result.

5 件のコメント

alsgud qor
alsgud qor 2020 年 3 月 20 日
編集済み: alsgud qor 2020 年 3 月 20 日
Thank you.but If using matrix is essential, what should I do? originally the purpose was that,ode45...like that.and as far as my knowledge goes, the basic ODE for that kind of thing is
for m1
F1=-k1x1-c1x1'+k2(x2-x1)+c2(x2'-x1')+mx1''
for m2
F2=m2x2''-c2x1'+c2x2'-k2x1+k2x2
so the entire thing should be
(the right side's 0 should turn into [F1 F2])
is it wrong?so I change it from your code to
eq1=F2==m2*diff(x2,2)+c2*(diff(x2,1)-diff(x1,1))+k2*(x2-x1);
eq2=F1==m1*diff(x1,2)+c1*diff(x1,1)+k1*x1;
this.and the result graph was this
I feel awkward cause you gave me something different.I hope it is my mistake
Birdman
Birdman 2020 年 3 月 20 日
Sorry, my bad. By using the attached function, run the following code from command line:
yInitial=zeros(1,4); %initial conditions
tSpan=0:0.001:10; %time interval for the equations
[T,Y]=ode45(@(t,y) TwoMassSys(t,y), tSpan, yInitial); %solving by using ode45
plot(T,Y(:,1),T,Y(:,3));legend('X1','X2'); %plotting
Birdman
Birdman 2020 年 3 月 20 日
Have you tried my last solution? It seems to be working fine.
alsgud qor
alsgud qor 2020 年 3 月 21 日
um sorry.because of time lag, I just recieved it. let me ask some Q
  1. dydt = zeros(4,1); what does it mean?
  2. dydt(2) = (-k1/m1)*y(1)+(-c1/m1)*y(2)+F1; this part should be changed into 'F1/m1'? same with dydt(4)
Birdman
Birdman 2020 年 3 月 23 日
  1. It means that I created a vector of zeros with 4 elements.
  2. Yes exactly, I missed that.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2020 年 3 月 20 日

コメント済み:

2020 年 3 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by