how to replace a symbolic variable with a real one after computation?
Show older comments
I have supposed to variable as symbolic and after some calculation I want to remove those symbolic variables and replace them with other real variable to that the output can be calculated for those real variables. Attached is the problem:
Here after syms I3 and I4. I applied some operators to a which is composed of symbolic varaibles I3 and I4. to the end I get symbolic variable d which is like "xyz * I3 - abc" here I want to create a new variable z which is composed of d but the it shouldn't be symbolic and I3 has to be replaced by I5(real variable). I have tried to alot but couldn't find the accurate solution to my problem. Many thanks

1 Comment
Davide Masiello
on 13 Oct 2022
Accepted Answer
More Answers (1)
Bjorn Gustavsson
on 13 Oct 2022
Perhaps straight conversion of the symbolic expressions to functions (function-handles, dynamical functions) with the matlabFunction-function:
d_fcn = matlabFunction(d)
Since you presented your code as an image it is impossible for me to check that this actually returns a function with all the input-parameters you want - without typing in your code from that image, and that's not going to happen. Hopefully you can adapt or use this solution. That function will allow you to plug in whatever values you want for the different input parameters.
HTH
5 Comments
matlabFunction is usally a good option, but because it uses all floating point I keep in mind that there can be cases where it's susceptible to round-off that can be mitigated by staying in the sym world as long as possible and converting to double at the end
syms x y real
d = (x + y)/x - x;
df = matlabFunction(d)
df (1,eps/4)
Doing it all in sym and then converting to double at the end
double(subs(d,[x y],[1 eps/4]))
Bjorn Gustavsson
on 13 Oct 2022
That is a fair point, but as far as I understand limited to example-sized problems.
Paul
on 13 Oct 2022
I think I've been bit by that or something similar, in actual work, maybe for overflow or something, I don't recall, so just thought I'd mention it. I use matlabFunction quite a bit, oftentimes because it's a lot faster than staying in sym world.
Bjorn Gustavsson
on 13 Oct 2022
So something like: damned if you do or cursed if you don't? Drowning in a half-full glass, or dehydration in a half-empty glass?
Paul
on 13 Oct 2022
Well, I wouldn't go so far as to being damned and cursed. How could such things ever occur when using Matlab? :)
Categories
Find more on Conversion Between Symbolic and Numeric in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!