How to Correctly Plot 1/Sqrt(1-(v²/c²)) in Matlab?

  • Context: MATLAB 
  • Thread starter Thread starter mzu
  • Start date Start date
  • Tags Tags
    Matlab Plot
Click For Summary

Discussion Overview

The discussion revolves around plotting the function 1/Sqrt(1-(v²/c²)) in Matlab, with a focus on resolving errors encountered during the plotting process. Participants explore the differences in syntax and operations between Matlab and Mathematica, particularly regarding element-wise operations.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant expresses difficulty in plotting the function in Matlab and shares their successful experience in Mathematica.
  • Another participant suggests using the syntax x = 1./sqrt(1-(v.^2/1^2)) to resolve the errors.
  • A later reply confirms that the suggested syntax works and queries the necessity of the dot notation in Matlab.
  • Participants explain that the dots indicate element-wise operations, contrasting them with default matrix operations in Matlab.
  • There is a question about the general rule for using dots with operators in Matlab, with clarification that dots are needed for element-wise operations but not for scalar multiplications.

Areas of Agreement / Disagreement

Participants generally agree on the need for element-wise operations in Matlab but discuss the specifics of when to use dot notation without reaching a consensus on a comprehensive rule.

Contextual Notes

Limitations include potential misunderstandings of Matlab's operation types and the specific context of the plotting function, which may not be fully resolved in the discussion.

Who May Find This Useful

Individuals learning Matlab, especially those transitioning from Mathematica or similar software, may find this discussion beneficial.

mzu
Messages
9
Reaction score
0
Hey everyone,

I'm trying to create a plot in Matlab but just keep getting errors. It works very well in Mathematica but I want to learn some Matlab. However with all the errors I get I will probably stay with Mathematica. Maybe someone here can help me out.
So, I'd like to create a plot of the formula 1/Sqrt(1-(v²/c²))
It is OK to just replace c by 1 and I'd like to have a plot with v starting at 0.1 and going up to 0.99

In Mathematica I type:
Plot[1/(Sqrt [1 - (v^2/1^2)]), {v, 0.1, 0.99}, PlotRange -> Full]
This gives the expected result.

In Matlab I can assign a fixed value like 0.98 to v and I'm able to calculate the result using:
v=0.98
1/sqrt(1-(v^2/1^2))

However I have no idea how to plot this with v starting at 0.1 and going to 0.99
I tried:
v=0.1:0.01:0.99;
x=1/sqrt(1-(v^2/1^2))
plot(x)

I just keep getting mpower errors. I have absolutely no idea what to do.

Can anybody help me out with this ?

Many thanks in advance.
Michael
 
Physics news on Phys.org
Great, thanks for the help. This actually works and gives the same result as Mathematica. Can anyone tell me why those dot's need to be there ? Is there a rule or so about when to put a dot and where ?

Regards,
Michael
 
The dots indicate an element by element operation. In MATLAB, the operators *, /, ^ etc. default to matrix operations.
 
Thanks for the help. Does that mean that whenever I need *, /, ^, I need to enter a dot if it's not Matrix operations ?
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
2
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 12 ·
Replies
12
Views
7K