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

In summary, creating a plot in Matlab can be done using the "plot" function, which takes in two vectors representing the x and y coordinates of the data points. Additional formatting options such as line style and color can also be specified. The "xlabel," "ylabel," and "title" commands can be used to label the axes and title of the plot. Creating multiple plots on the same figure can be achieved using the "hold" function. Overall, understanding the syntax and using built-in functions can help in creating and customizing plots in Matlab.
  • #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
 
Physics news on Phys.org
  • #3
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
The dots indicate an element by element operation. In MATLAB, the operators *, /, ^ etc. default to matrix operations.
 
  • #5
Thanks for the help. Does that mean that whenever I need *, /, ^, I need to enter a dot if it's not Matrix operations ?
 

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

What is Matlab and why is it used for creating plots?

Matlab is a programming language and software environment commonly used in scientific computing and data analysis. It is often used for creating plots because it has powerful built-in functions and tools specifically designed for data visualization.

How do I create a basic plot in Matlab?

To create a basic plot in Matlab, you can use the plot function. This function takes in two arrays, one for the x-axis values and one for the y-axis values, and plots them as a line graph. You can also customize the plot by adding a title, labels for the axes, and adjusting the color and style of the line.

Can I create multiple plots in one figure using Matlab?

Yes, you can create multiple plots in one figure using the subplot function. This allows you to divide the figure into smaller subplots and plot different data in each one. You can also customize the layout and appearance of the subplots using additional arguments.

How can I save my plot in Matlab?

To save your plot in Matlab, you can use the saveas function. This function takes in the figure handle and a file name with the desired file format, such as saveas(gcf, 'myplot.png'). You can also specify the resolution and other options for the saved image.

Are there any resources or tutorials available for creating plots in Matlab?

Yes, there are plenty of resources and tutorials available for creating plots in Matlab. The Matlab documentation provides detailed information on the various plotting functions and how to use them. Additionally, there are many online tutorials and forums where you can find tips and tricks for creating more advanced plots in Matlab.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
862
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
Back
Top