MATLAB mistaken Inertia I for imaginary number what do i do?

Click For Summary
SUMMARY

MATLAB incorrectly interprets the variable 'I' as the imaginary unit instead of the intended moment of inertia when solving equations. This issue arises particularly when using the symbolic solver for equations involving physical parameters, such as in pendulum calculations. To avoid this confusion, users should assign numerical values to variables before calling the solve function or consider using an alternative symbol for moment of inertia. This approach ensures that MATLAB does not misinterpret the variable and returns the correct results.

PREREQUISITES
  • Familiarity with MATLAB syntax and functions
  • Understanding of symbolic computation in MATLAB
  • Basic knowledge of pendulum physics and related equations
  • Experience with variable assignment and manipulation in MATLAB
NEXT STEPS
  • Learn how to use MATLAB's symbolic toolbox effectively
  • Research variable naming conventions in MATLAB to avoid conflicts
  • Explore the use of alternative symbols in MATLAB for physical constants
  • Study examples of solving equations with MATLAB's 'solve' function
USEFUL FOR

Students, engineers, and researchers working with MATLAB for physics simulations, particularly those dealing with symbolic computation and variable management in equations.

GreenPrint
Messages
1,186
Reaction score
0
MATLAB tends to mistake I or i for imaginary number when ever I try to use it as a variable, for example when do with a pendulum with a mass attached to it then

2 pi f = sqrt( (m g L)/I )
were I is the inertia not imaginary number
but when I try to get MATLAB to solve this equation for L it returns it as a lower case i because it thinks it's the imaginary number
How do I get around this
example
Code:
disp('If a pendulum on Earth has a mass of 10 kg, a frequency of .2 Hz, and a inertia of 60 kg m/s,')
fprintf('then it''s legnth is %s m.\n',char(solve(subs('2*pi*f=((m*g*L)/I)^(1/2)',{'f' 'g' 'I' 'm'},{.2 9.8 60 10}),'L')))
If a pendulum on Earth has a mass of 10 kg, a frequency of .2 Hz, and a inertia of 60 kg m/s,
then it's legnth is (2*pi^2*sqrt(-1))/1225 m.
As you can see... This was suppose to solve the equation for L and then plug in the values and return the exact answer instead it returns sqrt(-1) because it mistook I for the imaginary number
 
Physics news on Phys.org
Normally MATLAB has no problems overriding the predefined constant of I=sqrt(-1). I usually prefer to just use another variable name, but in the past I've used I (and i) as a variable without any issue.

Try assigning the variables with there numerical values before calling solve. As in,

f = 0.2
g = 9.8
I = 60
etcEdit. Ok I just realized you're using the symbolic solver and I'm not so sure how it works in this regard. Maybe you'll need to use an alternate symbol for moment of inertia.
 
Last edited:

Similar threads

Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 26 ·
Replies
26
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
5
Views
5K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K