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

조회 수: 46 (최근 30일)
Erica Dawn Miller
Erica Dawn Miller 2021년 3월 23일
답변: William 2021년 3월 23일
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.

채택된 답변

William
William 2021년 3월 23일
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])

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by