Mastering Matlab: Graphing Functions Made Easy

In summary, MATLAB is a powerful software that allows users to plot points and create graphs in a two-dimensional figure. It can also be used to define functions and graph them in a specific interval. MATLAB also has online services and a free clone called Freemat for easy exploration of its features.
  • #1
DrWahoo
53
0
The MATLAB command plot plots points in a two-dimensional figure and connects
them with straight line segments. So, here $y$ is a vector with $n$ entries
$(1; y(1)); (2; y(2)); (3; y(3)); : : : ; (n; y(n)):$

So the MATLAB command is given below for an example:
Code:
y = [1 -3 3 -4];
>> plot(y)

Yields the output here:
View attachment 7555

We can also define them in function form where each $x$ value corresponds to an output- $y$ value.
Code is given below;
Code:
y = [10 2 -6 3 -5]; x=[1 3 5 7 10];
>> plot(x,y)
Matlab output is below;
View attachment 7556Now let's try a simple function; let's graph $f(x)=x^2$
We first try using the following code;
Code:
y=x.^2;
plot(x,y);
Then we get the following output. Does this look strange?
View attachment 7557
This graph doesn't show me anything about the function for positive $x$ values? Can we fix this?
Yes, recall MATLAB is primarily based off matrices hence the "mat" lab. Aka Matrix labratories.

So let's define the values of the domain we want to see
Say for instance we want to look at the graph of the function on the interval $[-10, 10]$
We would use the following code
Code:
x=-10:0.1:10;
y=x.^2
plot(x,y)
To get the desired output below;
View attachment 7560So what if we want to graph a simple quadratic equation that is shifted to the left 10 points?
So let's start with the function $f(x)= x^2$ , shifting it to the right 10 units, we have $f(x)=(x-10)^2$
Now let's try to graph this. We could use points, but let's see if we can get the full graph. Hence, we shall try the following code knowing the x coordinate of the vertex is at 10, so we use the interval $[5,15]$
Code:
x=5:0.1:15;
y=(x-10).^2
plot(x,y)

The desired output is given below;
View attachment 7561This will continue into differential equations, phase plots, and gradient fields. Will update shortly.
 

Attachments

  • Simple_function.jpg
    Simple_function.jpg
    11.2 KB · Views: 125
  • simple_func1.jpg
    simple_func1.jpg
    11.3 KB · Views: 133
  • func1.jpg
    func1.jpg
    10.1 KB · Views: 124
  • good1.jpg
    good1.jpg
    12.3 KB · Views: 124
  • 5_15.jpg
    5_15.jpg
    11.1 KB · Views: 121
Physics news on Phys.org
  • #2
Udemy has a more comprehensive and free crash course for those of us who need more training.

https://www.udemy.com/course/matlab-crash-course/?utm_source=adwords&utm_medium=udemyads&utm_campaign=DSA_Catchall_la.EN_cc.US&utm_content=deal4584&utm_term=_._ag_95911180068_._ad_532194018659_._kw__._de_c_._dm__._pl__._ti_dsa-52949608673_._li_9028292_._pd__._&matchtype=&gclid=CjwKCAjw9suYBhBIEiwA7iMhNHX-_OgKEGjJd3P_Mpb40MVumJQsCawf_W6G97sHXJhQAIQmTDx9rhoCNfQQAvD_BwE

and this Youtube course:



Matlab provides an online service for running MATLAB code without the software. I think you have to signup and pay a subscription fee to do so.

https://www.mathworks.com/products/matlab-online.html

In addition there is a free Matlab clone called Freemat that provides an easy way to explore MATLAB features.

https://en.wikipedia.org/wiki/FreeMat

http://freemat.sourceforge.net/
 

1. What is Matlab and what is it used for?

Matlab is a high-level programming language and interactive environment for numerical computation, visualization, and programming. It is commonly used in engineering, science, and mathematics for tasks such as data analysis, modeling, and simulation.

2. How do I get started with Matlab?

To get started with Matlab, you will need to download and install the software on your computer. You can purchase a license or use a free trial version. Once installed, you can launch the program and start writing code in the command window or using the built-in editor.

3. What are the basic syntax and commands in Matlab?

The basic syntax in Matlab follows a similar structure to other programming languages, with the addition of using the '%' symbol for comments. Some common commands in Matlab include 'disp' for displaying text, 'fprintf' for formatted printing, and 'input' for user input. There are also many built-in functions for mathematical operations, data analysis, and visualization.

4. How can I learn more about Matlab?

There are various resources available to help you learn more about Matlab. The official Matlab website offers tutorials, documentation, and online courses. You can also find many helpful tutorials and guides on websites such as MathWorks, YouTube, and Coursera. Additionally, there are books and online forums where you can ask questions and get help from other Matlab users.

5. Can I use Matlab for Pampered Chef business tasks?

While Matlab is primarily used for scientific and technical computing, it can also be used for various business tasks, including data analysis and visualization. However, it may not be the most suitable tool for tasks such as inventory management or customer tracking. It is always best to evaluate your specific needs and determine if Matlab is the right tool for your Pampered Chef business.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
Back
Top