Effacer les filtres
Effacer les filtres

syntax for plot functions

1 vue (au cours des 30 derniers jours)
goran
goran le 5 Jan 2014
Commenté : Image Analyst le 5 Jan 2014
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

Réponses (2)

Mischa Kim
Mischa Kim le 5 Jan 2014
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 commentaire
Image Analyst
Image Analyst le 5 Jan 2014
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?

Connectez-vous pour commenter.


goran
goran le 5 Jan 2014
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 commentaire
Mischa Kim
Mischa Kim le 5 Jan 2014
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by