How to plot x=f(y) ?

조회 수: 164 (최근 30일)
huynh trong
huynh trong 2016년 11월 8일
편집: Thorsten 2016년 11월 8일
I'm new in matlab.I have function Y=x^3+x^2-x+6.I want to draw graph x=f(y).I don't know how to make it.Please support for me.Thank you so much

답변 (3개)

KSSV
KSSV 2016년 11월 8일
You have to mention x range. I am considering here 0 to 10.
x = linspace(0,10,500) ;
y=x.^3+x.^2-x+6 ;
plot(x,y)
xlabel('x')
ylabel('y')
title('y=x^3+x^2-x+6')
  댓글 수: 3
huynh trong
huynh trong 2016년 11월 8일
But I Have value of y.Example.Y=0:.1:100. Can I draw x=f(y)?.Thanks for your support
KSSV
KSSV 2016년 11월 8일
Ohhh John D'Errico I read it as y = f(x). Thanks for pointing out. How about this?
syms x
f(x) = x^3+x^2-x+6 ;
g = finverse(f) ;
y1 = linspace(0,10) ;
x1 = subs(g,y1) ;
plot(x1,y1)
Actually range of x should be given.

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


John D'Errico
John D'Errico 2016년 11월 8일
편집: John D'Errico 2016년 11월 8일
You wish to plot the inverse relationship, x=f(y), given the expression
y = x^3+x^2-x+6
Note that in general, this need not be a single valued function. In fact, your relationship is not:
ezplot('y=x.^3+x.^2-x+6',[-3,3],[-3,10])
So for some values of y, there are several values of x to be found. It looks like for y roughly in the interval [5,7] we will find three solutions.
I can convince ezplot to give that plot as:
ezplot('x=y.^3+y.^2-y+6',[-3,10],[-3,3])
ezplot is a bit dumb, but that is the plot you asked to see. It rather foolishly insists on putting x and y on their respective axes. We could as easily have done the work the hard way, using plot directly. But why bother?

Thorsten
Thorsten 2016년 11월 8일
편집: Thorsten 2016년 11월 8일
Instead of plot(x,y), you plot(y,x)
x = linspace(-3,3); plot(x.^3+x.^2-x+6, x), xlabel('y'), ylabel('x')

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by