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

In summary, the conversation discusses an issue with MATLAB mistaking the letter "I" for the imaginary number, resulting in incorrect solutions to equations. The solution suggested is to assign numerical values to the variables before calling the solver. There is also a suggestion to use a different symbol for the moment of inertia to avoid confusion with the imaginary number.
  • #1
GreenPrint
1,196
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
  • #2
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:

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

1. How can I avoid mistaking Inertia I for an imaginary number in MATLAB?

To avoid mistaking Inertia I for an imaginary number in MATLAB, make sure to use the correct syntax for representing Inertia I. Inertia I in MATLAB is represented as "i", not "I". It is important to pay attention to case sensitivity when using MATLAB commands.

2. What should I do if I accidentally use "I" instead of "i" for Inertia I in MATLAB?

If you accidentally use "I" instead of "i" for Inertia I in MATLAB, you can fix this by simply correcting the syntax in your code. Replace all instances of "I" with "i" to represent Inertia I correctly.

3. Can I change the representation of Inertia I in MATLAB?

No, the representation of Inertia I in MATLAB cannot be changed. It is a predefined constant and must be represented as "i" in all MATLAB commands.

4. How can I check if I have mistakenly used "I" instead of "i" for Inertia I in my code?

You can check if you have mistakenly used "I" instead of "i" for Inertia I in your code by using the "whos" command in MATLAB. This will list all the variables in your workspace, and if "I" is used to represent Inertia I, it will be listed as an imaginary variable instead of a constant.

5. Can using "I" instead of "i" for Inertia I cause errors in my code?

Yes, using "I" instead of "i" for Inertia I can cause errors in your code. This is because "I" is not a predefined constant in MATLAB and will be interpreted as an imaginary variable. This can lead to incorrect calculations and unexpected results in your code.

Similar threads

Replies
26
Views
2K
Replies
2
Views
1K
Replies
2
Views
3K
Replies
10
Views
2K
Back
Top