How do you export your syms equation to a new/different .m file to be able to use the equation with parameters.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Feb. de 2025
As @Torsten says, you can just pass symbolic expressions as parameters.
However, you need to be careful about assumptions. All levels of MATLAB code share the same assumptions, and using syms on a variable resets assumptions.
syms x positive
assumptions
ans = 
f = sin(x)+x^2
f = 
testit(f, x)
ans = 
ans = Empty sym: 1-by-0
ans = 
ans = 
assumptions
ans = Empty sym: 1-by-0
function testit(f, var)
assumptions
syms x
assumptions
diff(f, x)
diff(f, var)
end

Más respuestas (1)

Torsten
Torsten el 22 de Feb. de 2025
Editada: Torsten el 22 de Feb. de 2025
Call the other .m-file with the syms-equation (or function) as input argument.
syms x
f = x.^2;
result = fun(f)
result = 
4
function result = fun(f)
syms x
result = subs(f,x,2);
end

Categorías

Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.

Productos

Versión

R2024b

Preguntada:

el 22 de Feb. de 2025

Respondida:

el 22 de Feb. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by