mathematical expression from string input
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Md. Ashikur Rahman Any
le 17 Avr 2021
Commenté : Stephan
le 19 Avr 2021
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/586366/image.png)
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
0 commentaires
Réponse acceptée
Stephan
le 17 Avr 2021
Modifié(e) : Stephan
le 17 Avr 2021
>> 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 commentaires
Stephan
le 19 Avr 2021
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--')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!