i am getting error in line 18 of invalid use of operator.please help me solving this

조회 수: 2 (최근 30일)
clear all
close all
m1 =12000;
m2 =10000;
m3 =8000;
k1 =3000;
k2 =2400;
k3 =1800;
A =[( k1 + k2 )/ m1 - k2 / m1 0 ; - k2 / m2 ( k2 + k3 )/ m2 - k3 / m2 ; 0 - k3 / m3 k3 / m3 ];
[V , D ]= eig ( A );
omega = diag ( D ).^0.5
modes = V ;
modes (: ,1)= modes (: ,1)/ modes (3 ,1);
modes (: ,2)= modes (: ,2)/ modes (3 ,2);
modes (: ,3)= modes (: ,3)/ modes (3 ,3);
modes
figure (1);
subplot (1 ,3 ,1);
plot ([0; modes (:,1)] ,0:3 ,bo-);
ylabel ( Floor );
xlabel ( Relative Displacement );
mytitle = sprintf ( \\ omega =%.2 f rad / s ’ , omega (1));
title ( mytitle )
subplot (1 ,3 ,2);
plot ([0; modes (: ,2)] ,0:3 , bo - );
xlabel ( Relative Displacement );
mytitle = sprintf ( \\ omega =%.2 f rad / s ’ , omega (2));
title ( mytitle )
subplot (1 ,3 ,3);
plot ([0; modes (: ,3)] ,0:3 , bo - );
xlabel ( Relative Displacement );
mytitle = sprintf ( \\ omega =%.2 f rad / s ’ , omega (3));
title ( mytitle )
  댓글 수: 2
Bjorn Gustavsson
Bjorn Gustavsson 2021년 4월 15일
When running your code it gives an error at:
[V , D ]= eig ( A );
Because A has become a 3 x 2 matrix. Fix that - and give us the error-message.

댓글을 달려면 로그인하십시오.

채택된 답변

deepak mishra
deepak mishra 2021년 4월 15일
Can you please change it Actually I have no knowledge of matlab I have to use it in my Web development project. Please help me
  댓글 수: 2
Bjorn Gustavsson
Bjorn Gustavsson 2021년 4월 15일
Now you have accepted this comment/question of yours as the ANSWER to your problem. That will hide it from other people. First you'll have to "unaccept" this answer. Then start to look at each successive line of your code and inspect the results they produce. For example after assigning the matrix A using your code I get:
A =
0.2500 0
-0.2400 0.2400
-0.2250 0.2250
Is that consistent with your expectations?
deepak mishra
deepak mishra 2021년 4월 15일
actually i want to use this code which i have attached .please help if you can.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Bjorn Gustavsson
Bjorn Gustavsson 2021년 4월 15일
편집: Bjorn Gustavsson 2021년 4월 15일
OK, so you want to solve 3 coupled equations of motion for some harmonically varying solution. First you have to understand the physics, then the mathematics and then you can solve this numerically.
1, physics.
Eq of motion:
Harmonic solutions ->
For a number of coupled oscillators you get
Where A has to be n-by-n, where in your case n is 3.
Here you should be able to identify your first problem, since A becomes 3-by-2!
You should be able to figure out what goes wrong in your assignment of A, it has to do with the interpretation of which terms are added(or subtracted) together to form a matrix-element. To not have that happen you should insert , (commas) between to separate the matrix-elements on a row. This is a very treacherous error we all(?) encountered when starting to use matlab.
HTH

Jan
Jan 2021년 4월 15일
편집: Jan 2021년 4월 15일
For me line 18 is:
subplot (1 ,3 ,1);
I do not see a problem here. But in the next line:
plot ([0; modes (:,1)] ,0:3 ,bo-);
% ^ ^
Use single quotes ' instead. Did you copy the code from a DOCX, PDF or from the net? Then the quotes are converted sometimes. You should see the problem in the syntax highlighting already.
Please care for posting a copy of the complete error message and do not let the reader guess or count, which line is failing.
Notes:
  • Omit the brute clearing header "clear all; close all". This is not useful, but teachers suggest it only, because their teachers had suggested it 20 years ago. This is "cargo cult programming" and a widespread programming anti-pattern.
  • sqrt(X) is faster than the power operation X.^0.5.

카테고리

Help CenterFile Exchange에서 Graphics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by