Investing of a string/function and listing of variables
Show older comments
i want to make a program that separates the variables and coefficients from the entered function for example
the program will prompt user to enter a function if user enters 2x1+3x3 then the result/output should be var=[x1 x3] coefficients= [2 3]
if user enters x+y1+3y3-irt-2x2+3n then output should be var=[x y1 y3 irt x2 n] coefficients= [1 1 3 -1 -2 3] if user enters abcd then result should be var=[abcd] coefficients=[1] . I know its difficult but guys plz help me out. Thanx in advance.
Answers (1)
Azzi Abdelmalek
on 30 Apr 2013
Edited: Azzi Abdelmalek
on 30 Apr 2013
y=input('enter y','s')
y=sym(y)
[coefficient,var]=coeffs(y)
%you should enter y like below
12*x1+14*x2
4 Comments
irtiza zafar
on 30 Apr 2013
Azzi Abdelmalek
on 30 Apr 2013
I am not getting your result
irtiza zafar
on 30 Apr 2013
Azzi Abdelmalek
on 30 Apr 2013
Edited: Azzi Abdelmalek
on 30 Apr 2013
>> y=input('enter y=','s')
y=sym(y)
[coefficient,var]=coeffs(y)
enter y=2*x1+3*x3
y =
2*x1 + 3*x3
coefficient =
[ 2, 3]
var =
[ x1, x3]
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!