how to replace a symbolic variable with a real one after computation?

9 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Paul
Paul am 13 Okt. 2022
Use subs or symfun objects and covert to double are two options
syms I3 I4
d = I3 + I4;
double(subs(d,[I3 I4],[1.1 2.2]))
ans = 3.3000
d(I3,I4) = I3 + I4;
double(d(1.1,2.2))
ans = 3.3000

Weitere Antworten (1)

Bjorn Gustavsson
Bjorn Gustavsson am 13 Okt. 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 Kommentare
Bjorn Gustavsson
Bjorn Gustavsson am 13 Okt. 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
Paul am 13 Okt. 2022
Well, I wouldn't go so far as to being damned and cursed. How could such things ever occur when using Matlab? :)

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by