Filter löschen
Filter löschen

Can not run function, written wrong?

1 Ansicht (letzte 30 Tage)
Hanna Sundling
Hanna Sundling am 11 Okt. 2019
Kommentiert: Star Strider am 11 Okt. 2019
I can nor run the function and do not understand where I have written it wrong.

Akzeptierte Antwort

Star Strider
Star Strider am 11 Okt. 2019
The order is reversed. The ‘x’ variable needs to be assigned before calculating ‘y’, since ‘y’ depends on ‘x’.
  2 Kommentare
Hanna Sundling
Hanna Sundling am 11 Okt. 2019
yeah, I changed that so x is assigned before y but when I plot the graph does not look like it is supposed to. So I thought that i maybe have written the function wrong?
Star Strider
Star Strider am 11 Okt. 2019
Note that ‘y’ will be complex, since you are taking the square root of a negative numbers in ‘x’ and in some parts of ‘sin(x)’.
Try this:
x = -1:0.5:1;
y = (x-sqrt(x))./sqrt(sin(x));
plot(x, real(y), x, imag(y), x,abs(y))
grid
legend('Re(y)', 'Im(y)', '| y |')

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by