Can not run function, written wrong?

조회 수: 4 (최근 30일)
Hanna Sundling
Hanna Sundling 2019년 10월 11일
댓글: Star Strider 2019년 10월 11일
I can nor run the function and do not understand where I have written it wrong.

채택된 답변

Star Strider
Star Strider 2019년 10월 11일
The order is reversed. The ‘x’ variable needs to be assigned before calculating ‘y’, since ‘y’ depends on ‘x’.
  댓글 수: 2
Hanna Sundling
Hanna Sundling 2019년 10월 11일
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 2019년 10월 11일
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 |')

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by