How to retrieve the values and substitute to get all the functions

1 vue (au cours des 30 derniers jours)
MINATI
MINATI le 20 Juin 2020
Commenté : Ameer Hamza le 20 Juin 2020
x = sym('x');f(x) = sym('f(x)');g(x) = sym('g(x)'); h(x) = sym('g(x)');a = sym('a');b = sym('b');c= sym('c');
f = x+(1/2).*a.*x.^2+0.3E0.*x.^3+(1/24).*(2.*a+(-0.1E0).*b+(-0.1E0).*c).*x.^4+(1/60).*(0.9E0+(1/2).*a.^2).*x.^5+(1/120).*( ...
0.6E0.*a+0.118333E-1.*b+(1/2).*(2.*a+(-0.1E0).*b+(-0.1E0).*c)+(1/2).*((-2).*a+0.1E0.*b+0.1E0.*c)+0.366667E-2.*c).*x.^6;
g = 1+b.*x+(-0.118333E0).*b.*x.^3+(-0.295833E-1).*a.*b.*x.^4+0.19525E-2.*b.*x.^5+(-0.236667E-1).*((-0.295833E0).*a.*b+ ...
(1/24).*b.*(2.*a+(-0.1E0).*b+(-0.1E0).*c)).*x.^6;
h = 1+c.*x+(-0.366667E-1).*c.*x.^3+(-0.916667E-2).*a.*c.*x.^4+(-0.209E-2).*c.*x.^5+(-0.733333E-2).*(( ...
-0.916667E-1).*a.*c+(1/24).*(2.*a+(-0.1E0).*b+(-0.1E0).*c).*c).* x.^6;
f22 = pade(diff(f),x,0,'Order',[2 2]); g22 = pade(g,x,0,'Order',[2 2]); h22 = pade(h,x,0,'Order',[2 2]);
f1 = limit(f22,x,Inf);g1 = limit(g22,x,Inf); h1 = limit(h22,x,Inf);
eqns = [f1 == 0, g1 == 0, h1 == 0];
S2 = vpasolve(eqns,[a b c]); a = S2.a; b = S2.b; c = S2.c;
vars = [a b c]; %%All values
a = a(real(a)&imag(a) == 0); b = b(real(b)&imag(b) == 0); c = c(real(c)&imag(c) == 0);
% a(1) = -1.3364112199640579935131912697803; b(1) = -0.35418080373051794261506359075758;
%c(1) = -0.10974681880027031234427109278927;
F = vpa ( subs ([f, g, h], [a, b, c], [a(1) b(1) c(1)]) );
f = F(1); g = F(2); h = F(3);
disp([f g h])
%%% I want to substitute particular values of a, b, c difectly from the code in F to get f , g, h
%% Try please

Réponse acceptée

Ameer Hamza
Ameer Hamza le 20 Juin 2020
At this line
a = S2.a; b = S2.b; c = S2.c;
You are overwriting the variables a, b, and c. Converting them from symbolic to numeric. Use a different variable name. See the following code
syms x a b c
f = x+(1/2).*a.*x.^2+0.3E0.*x.^3+(1/24).*(2.*a+(-0.1E0).*b+(-0.1E0).*c).*x.^4+(1/60).*(0.9E0+(1/2).*a.^2).*x.^5+(1/120).*( ...
0.6E0.*a+0.118333E-1.*b+(1/2).*(2.*a+(-0.1E0).*b+(-0.1E0).*c)+(1/2).*((-2).*a+0.1E0.*b+0.1E0.*c)+0.366667E-2.*c).*x.^6;
g = 1+b.*x+(-0.118333E0).*b.*x.^3+(-0.295833E-1).*a.*b.*x.^4+0.19525E-2.*b.*x.^5+(-0.236667E-1).*((-0.295833E0).*a.*b+ ...
(1/24).*b.*(2.*a+(-0.1E0).*b+(-0.1E0).*c)).*x.^6;
h = 1+c.*x+(-0.366667E-1).*c.*x.^3+(-0.916667E-2).*a.*c.*x.^4+(-0.209E-2).*c.*x.^5+(-0.733333E-2).*(( ...
-0.916667E-1).*a.*c+(1/24).*(2.*a+(-0.1E0).*b+(-0.1E0).*c).*c).* x.^6;
f22 = pade(diff(f),x,0,'Order',[2 2]);
g22 = pade(g,x,0,'Order',[2 2]);
h22 = pade(h,x,0,'Order',[2 2]);
f1 = limit(f22,x,Inf);
g1 = limit(g22,x,Inf);
h1 = limit(h22,x,Inf);
eqns = [f1 == 0, g1 == 0, h1 == 0];
S2 = vpasolve(eqns,[a b c]);
a_val = S2.a;
b_val = S2.b;
c_val = S2.c;
vars = [a b c]; %%All values
a_val = a_val(real(a_val)&imag(a_val) == 0);
b_val = b_val(real(b_val)&imag(b_val) == 0);
c_val = c_val(real(c_val)&imag(c_val) == 0);
% a(1) = -1.3364112199640579935131912697803; b(1) = -0.35418080373051794261506359075758;
%c(1) = -0.10974681880027031234427109278927;
F = vpa (subs ([f, g, h], [a, b, c], [a_val(1) b_val(1) c_val(1)]) );
f = F(1); g = F(2); h = F(3);
disp([f g h])
  2 commentaires
MINATI
MINATI le 20 Juin 2020
Thank you
Dear
Ameer Hamza
it worked
Ameer Hamza
Ameer Hamza le 20 Juin 2020
I am glad to be of help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by