Matlab code help

  • MATLAB
  • Thread starter mzu
  • Start date
  • #1
mzu
10
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
 

Answers and Replies

  • #2
Dr Transport
Science Advisor
Gold Member
2,417
549
x = 1./sqrt(1-(v.^2/1^2)) should work
 
  • #3
mzu
10
0
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
 
  • #4
jhae2.718
Gold Member
1,161
20
The dots indicate an element by element operation. In MATLAB, the operators *, /, ^ etc. default to matrix operations.
 
  • #5
mzu
10
0
Thanks for the help. Does that mean that whenever I need *, /, ^, I need to enter a dot if it's not Matrix operations ?
 

Related Threads on Matlab code help

  • Last Post
Replies
2
Views
9K
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
4
Views
660
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
13
Views
11K
  • Last Post
Replies
3
Views
2K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
2
Views
5K
Replies
3
Views
3K
Replies
6
Views
3K
Top