Plotting a function over an interval
조회 수: 273 (최근 30일)
이전 댓글 표시
Hi,
I'm dealing with defining a function and then plotting it. The function is y1= arctan(exp(x)*(x-1))+ pi/2 which I need to plot it over interval x=0:0.1:2 , but every time I get an error. What do I need to do?
I did this:
x = 0:.01:2;
y1= arctan(exp(x)*(x-1))+ pi/2
plot(x,y1)
Also, if I want to have several functions plotted in a same window but with different colors, what should I do?
댓글 수: 0
채택된 답변
the cyclist
2011년 9월 27일
You need to use ".*" instead of "*" to multiply each element of the vector, and also the inverse tangent function in MATLAB is atan() not arctan():
>> y1= atan(exp(x).*(x-1))+ pi/2
댓글 수: 0
추가 답변 (2개)
Kris Hoffman
2020년 11월 29일
Tought I'd add to this answer.
y1 = @(x) atan(exp(x).*(x-1))+ pi/2
fplot(y1,[0,2])
Fangjun Jiang
2011년 9월 27일
You mean this?
x = 0:.01:2;
y1= atan(exp(x).*(x-1))+ pi/2;
plot(x,y1);
help plot for details.
plot(x1,y1,'r',x2,y2,'g',x3,y3,'b')
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!