Use workspace variable in equation solver
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have the equation x+y=25 and currently I have y as a predfined variable=5. so the equation becomes x+5=25. However I would like to change y from my script and the equation to automatically change based on my y value rather than me modifying my equations each time to edit the y value.
I currently do it this way:
y=5;
syms x
eqn = x+5=25;
S = solve(eqn,x);
0 comentarios
Respuestas (2)
Rik
el 9 de Ag. de 2022
If you don't want to use a function to wrap the input, you can use an anonymous function instead.
y=5;
syms x
eqn =@(y) x+y==25;
S = solve(eqn(y),x)
0 comentarios
Walter Roberson
el 9 de Ag. de 2022
syms x y
eqn = x + y == 25
y = 5
subs(eqn)
y = 9
subs(eqn)
0 comentarios
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!