about separating the variable.

i have x = 0 and 2. is there a way to separate those numbers using x1=0 and x2=2 ? i'll use this using programming in matlab.

 채택된 답변

Wayne King
Wayne King 2011년 9월 13일

0 개 추천

Yes, you can also store them in a vector
x = [0 2];
% or as a column vector
x =[0;2];
and then access them by their indices:
x(1)
x(2)

댓글 수: 6

Ejay Kasai
Ejay Kasai 2011년 9월 13일
i mean i created a program that computes for x. when the user inputs a polynomial function the program will find the x. in my case i find the x to have 2 numbers. what will i do?
Wayne King
Wayne King 2011년 9월 13일
Why can't you store them in a vector?
Ejay Kasai
Ejay Kasai 2011년 9월 13일
because it is a matlab program. if user input a polynomial function and the program finds two number of x how can i store them in vector? for example the user inputs a polynomial function and my program automatically finds the x. how can it be automatically store in a vector?
Jan
Jan 2011년 9월 13일
@Ejay: The question is not clear. Storing two values in a vector is trivial in Matlab.
Please post the relevant part of the code. Perhaps then it is getting clearer what you mean by: "input a polynomial function" and "the program finds two numbers".
Ejay Kasai
Ejay Kasai 2011년 9월 13일
ok so, this is the program
poly1=input('First polynomial function: ','s');
poly2=input('Second polynomial function: ','s');
syms y;
z1=solve(poly1,'y');
z2=solve(poly2,'y');
xi=solve(z1-z2);
yi(1)=eval(subs(z1,xi(1)));
yi(2)=eval(subs(z1,xi(2)));
ezplot(poly1)
hold all
ezplot(poly2)
plot(xi,yi,'o')
what if the user input poly1: y=x^2 and ply2: y=2*x then xi will be 0 and 2. and i want to separate those two number of xi to x1=0 and x2=2 automatically if the program finds the two x's.
Ejay Kasai
Ejay Kasai 2011년 9월 13일
i got it. Thank you very much!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Polynomials에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by