Azzera filtri
Azzera filtri

syntax for plot functions

1 visualizzazione (ultimi 30 giorni)
goran
goran il 5 Gen 2014
Commentato: Image Analyst il 5 Gen 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

Risposte (2)

Mischa Kim
Mischa Kim il 5 Gen 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 Commento
Image Analyst
Image Analyst il 5 Gen 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?

Accedi per commentare.


goran
goran il 5 Gen 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 Commento
Mischa Kim
Mischa Kim il 5 Gen 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.

Accedi per commentare.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by