How to substitute the values of two variables in an expression at the same time - Matlab
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Myrto Kasioumi
am 13 Dez. 2021
Kommentiert: Myrto Kasioumi
am 14 Dez. 2021
Hello,
I have the following expression:
Q1sym =
6562864383290039/3377699720527872 - (1321331071190089*(-(10*(b/5 - 1)*((2*b)/5 + b*(2*b + 1) - t*(b/5 - 1) + 2))/3)^(3/10))/1125899906842624
for which I want to substitute at the same time the two unknowns (b,t) for which I have the following 5 values:
b1 =
[ 19/12 - 457^(1/2)/12, 317/200 - 1138401^(1/2)/600, 119/75 - 283576^(1/2)/300, 953/600 - 1130209^(1/2)/600, 159/100 - 281529^(1/2)/300]
t =
[ 1/2, 11/20, 3/5, 13/20, 7/10]
and I am using the following code:
Q1 = subs(Q1sym, [b t] ,[b1 t])
but it doesn't work.
Do you know how I can solve that?
Thanks a lot
0 Kommentare
Akzeptierte Antwort
Paul
am 14 Dez. 2021
Can you define Q1sym as a symfun?
% simple example
syms b t
Q1sym(b,t) = b + t;
b1 = sym(1:5);
t1 = sym([ 1/2, 11/20, 3/5, 13/20, 7/10]);
Q1sym(b1,t1)
Weitere Antworten (1)
Walter Roberson
am 14 Dez. 2021
Q1 = subs(Q1sym, {b, sym('t')}, {b1, t});
Notice you had to create a local symbolic variable named 't' to pass in, to be a reference for the t variable that is no longer a simple symbolic variable.
I recommend that you get in the practice of avoiding writing over any symbolic variable that there is still any reference to. In this case, there was still a reference to t at the time you overwrote the MATLAB variable t with the vector. If you had named the vector of replacement values something like t1 (in analogy with b1) then you could have done
Q1 = subs(Q1sym, {b, t}, {b1, t1});
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!