필터 지우기
필터 지우기

How to take an equation as input from user and read the coefficient from it?

조회 수: 3 (최근 30일)
Sourin Dey
Sourin Dey 2016년 12월 27일
답변: Walter Roberson 2016년 12월 27일
How to take an equation as input from user and read the coefficient from it?

답변 (1개)

Walter Roberson
Walter Roberson 2016년 12월 27일
If you have the Symbolic toolbox, then you could convert the string representing the equation to a function handle using str2func() and then you could pass symbolic arguments to it to get a symbolic representation of it.
At that point, if the equation is known to represent a polynomial, then you can use coeffs() to get the coefficients.
If the equation is not known to represent a polynomial then you can use children() to break it into pieces, and examine the pieces using symvar() to determine whether they contain the variable of interest. However, in such a case it gets tricky to define what the coefficients are. For example, for sin(2*x) it is not really correct to say that the coefficient of x is 2.

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by