Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Plotting continuous variable in MATLAB

I am using fplot() to plot the expression exp(-t)sin(5t) over the range of (-2,2). I did fplot(exp(-t)*sin(5*t),[2,2]) but it doesn’t plot the way I wanted. What should I do?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You’re getting an error:

Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error.

Listen to the error – you are missing multiplication operators! We improve the code a little…

fplot(exp(-t).*sin(5.*t),[2,2])

Now you get a new error:

Unrecognized function or variable ‘t’.

Again listen to the error, you haven’t defined t, and fplot expects you to pass a function (from the docs)

fplot(f) plots the curve defined by the function y = f(x)

We can make the expression into a function and improve the code a little more…

fplot(@(t)exp(-t).*sin(5.*t),[2,2])

Now you get a blank figure?? Ah looking at the docs again, we see

fplot(f,xinterval) plots over the specified interval. Specify the interval as a two-element vector of the form [xmin xmax].

Where [xmin xmax] are currently both 2 in your example. We can’t plot over a range of nothing, so choose something else. Now we have working code:

fplot(@(t)exp(-t).*sin(5*t),[-2,2])

plot

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading