How do I plot a function over a specific range of x values?

144 views (last 30 days)
I am trying to graph the function y=exp(-.2x)*cos(2.1x) over the x values of 0 to 4. I have to use the function and the f plot method. I tried to do this by using the method of "fplot(fun1,[0 4])," but this did not work, as it is asking me to enter the value of x. I believe the problem lies in my function, which I have attached. If anyone has any advice, I would greatly appreciate it.

Accepted Answer

William
William on 23 Mar 2021
Erica,
I think fplot() will work if it is called correctly. If you want to use it, you need to define the function so that it can handle a vector input for x. In your case, this means that you should use a ".*" operator to multiply the two functions together, as in the following:
func = @(x) exp(-.2*x).*cos(2.1*x)
fplot(func,[0,4])

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!