syntax for plot functions

1 次查看(过去 30 天)
goran
goran 2014-1-5
i'm beginner in matlab. i try to type 3 functions and plot graphic for functions but i cannot do it. when i type
x=0.15; f1=1-x-x^2/(2+x)-x^3/(3+x)-x^4/(4+x)
i receive ok value. but when i type
x=-2:0.1:2; f1=1-x-x^2/(2+x)-x^3/(3+x)-x^4/(4+x)
i receive error
Error using ^
Inputs must be a scalar and a square
matrix.
To compute elementwise POWER, use POWER
(.^) instead.
when i change function on
f1=1-x-x.^2/(2+x)-x.^3/(3+x)-x.^4/(4+x)
i receive values but wrong values. when i try plot graph plot(x,f1) i receive straight line, but this function is hyperbole.same problem is with other functions. i attached those function in file

回答(2 个)

Mischa Kim
Mischa Kim 2014-1-5
You need to use the dot notation all the way throughout the equation, e.g.,
f1 = 1 - x - x.^2./(2 + x) - x.^3./(3 + x) - x.^4./(4 + x)
  1 个评论
Image Analyst
Image Analyst 2014-1-5
goran's own "Answer", which he also accepted for some reason, moved here so he can now accept Mischa's answer instead:
thank's. it's works. can you send link where i can find when i need to use the dot notation when not?

请先登录,再进行评论。


goran
goran 2014-1-5
in second function
when i type f2=sinh(x+1)+tan(x.^2)/tan(x)+abs(1-sin(1/(x.^2+1))) i receive error Error using / Matrix dimensions must agree. error is showing because sin(1/(x.^2+1) why?
  1 个评论
Mischa Kim
Mischa Kim 2014-1-5
Same thing as before, you need to use element-wise division:
f2 = sinh(x + 1) + tan(x.^2)./tan(x) + abs(1 - sin(1./(x.^2 + 1)))
By the way, you accepted the answer to the answer.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by