MATLAB Answers

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

1 view (last 30 days)
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 )

Accepted Answer

deepak mishra
deepak mishra on 15 Apr 2021
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 Comments

Sign in to comment.

More Answers (2)

Bjorn Gustavsson
Bjorn Gustavsson on 15 Apr 2021
Edited: Bjorn Gustavsson on 15 Apr 2021
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 on 15 Apr 2021
Edited: Jan on 15 Apr 2021
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.

Community Treasure Hunt

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

Start Hunting!

Translated by