Graphing as a function of Y

조회 수: 6 (최근 30일)
MC
MC 2019년 9월 23일
댓글: Ankit 2019년 9월 23일
I want to use the function plot to plot the right-side of the equation f(y) = −2 + 5*y^2 − y*5 on the interval −2 ≤ y ≤ 2 (with y on horizontal axis).
The error message reads:
Error in assignment (line 1)
x = -2+5*y^2-y^5
How do I fix this?
x = -2+5*y^2-y^5
ylim([-2 -2])
plot (y,x)
  댓글 수: 1
Bjorn Gustavsson
Bjorn Gustavsson 2019년 9월 23일
If you have y as an array (either [n x 1] or [1 x n]) then matlab treats the operations * ^ as matrix-operations, for your case that means that y^2 and y^5 as matrix powers. You most likely want the element-wise power. In matlab that is written as y.^2 etc.
HTH

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

답변 (1개)

rough93
rough93 2019년 9월 23일
ylim([-2 -2])
x = -2+5.*y.^2-y.^5
plot (y,x)
As you are using a varying value of y in your x calculation, you need to include a . before your operations to make each calculation element-wise.
  댓글 수: 1
Ankit
Ankit 2019년 9월 23일
small correction
ylim([-2 2])

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by