I want to make a equation solver which will take any type of mathmatical equation as input .and return the roots.For that reason ,first the program need to read the equation.I want to input the equation in string format.then matlab will consider this as a function of x.
for example if i give input as
(sin(sqrt(x)+a) * e^sqrt(x)) / sqrt(x)
Matlab will read this as
and then i will plot the curve ,and the intersecting point with x axis is the solution of the equation.
How to do that?
Thanks in Advance

 채택된 답변

Stephan
Stephan 2021년 4월 17일
편집: Stephan 2021년 4월 17일

1 개 추천

>> fun = str2sym("(sin(sqrt(x)+a) * e^sqrt(x)) / sqrt(x)")
fun =
(e^(x^(1/2))*sin(a + x^(1/2)))/x^(1/2)
>> pretty(fun)
sqrt(x)
e sin(a + sqrt(x))
-------------------------
sqrt(x)

댓글 수: 4

Thanks.It worked .
How to plot this sym function like this way and get intersecting point.
Note that you have to rewrite e^x to exp(x) in you string input:
syms x a
fun = str2sym("(sin(sqrt(x)+a) * exp(sqrt(x))) / sqrt(x)")
fun = subs(fun, a, 1)
intersect = solve(fun==0)
fplot(fun)
The equation has multiple solution.But it only shows one.
How to show multiple solutions as output.
I know there are infinite number of solution.But if i want to get solution in a sfecific range ,how to get that??
Make assumptions on x and solve then:
syms x a
fun = str2sym("(sin(sqrt(x)+a) * exp(sqrt(x))) / sqrt(x)")
fun = subs(fun, a, 1)
assume([x>25, x<30])
intersect = solve(fun==0)
fplot(fun,[25,30])
xline(double(intersect),'k--')
yline(0,'k--')

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

추가 답변 (0개)

카테고리

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

질문:

2021년 4월 17일

댓글:

2021년 4월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by