MATLAB Answers

converting sym function to string MATLAB

61 views (last 30 days)
Andromeda
Andromeda on 17 Oct 2021
Commented: Star Strider on 17 Oct 2021
I am attempting to convert a symbolic expression to a string using the function sym2str but I am getting an error. How can I convert a symbolic expression to a string? See attachment below

Accepted Answer

Star Strider
Star Strider on 17 Oct 2021
Try this —
syms x y
eqn = x^2+2*x*y+3*y^2;
partial_eqn = diff(eqn, x);
fprintf("The partial derivative of %s w.r.t. x is %s \n", string(eqn), string(partial_eqn))
The partial derivative of 2*x*y + x^2 + 3*y^2 w.r.t. x is 2*x + 2*y
Also, using fprintf is easier and creates a more pleasing result.
.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by