How to plot two variables in a single function?

조회 수: 3 (최근 30일)
sashil dath
sashil dath 2016년 11월 27일
답변: Walter Roberson 2016년 11월 27일
How do I create a plot that shows the variation of k with respect to x in the following function without actually rearranging it? y-a*x + sin(b*x^2) + k*m=0
Assume the remaining terms have fixed values.
syms y a b k x
b*x^2 - a*x + y + k*m == 0
>> a=2, b=3,y=4;
>> x= 1:0.5:5;
>> plot(x,m)
The above code results in the following message "Error using plot Conversion to double from sym is not possible."

답변 (2개)

Walter Roberson
Walter Roberson 2016년 11월 27일
Your line
b*x^2 - a*x + y + k*m == 0
does not define anything. It creates an expression and prints the value of the expression to the screen, but it does not create any assignment.
Perhaps you want something like
eqn = b*x^2 - a*x + y + k*m == 0;
and then later
M = double( solve(subs(eqn), m) );
plot(x, M)

KSSV
KSSV 2016년 11월 27일
a=2, b=3,k=1:4;
x= 1:0.5:5;
X=zeros(length(k),length(x));
Y=zeros(length(k),length(x));
for i=1:length(k)
Y(i,:)= -b*x^2 +a*x-k(i)*m ;
end
plot(X,Y)
The above plots x,y for k = 1,2,3,4.

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by