warning all the time, don't know what is wrong

2 vues (au cours des 30 derniers jours)
Xiao yang
Xiao yang le 22 Mar 2024
Commenté : Dyuman Joshi le 29 Mar 2024
syms m n p a x y z lambda real
g = x + y + z -a;
L = (x).^m.*(y).^n.*(z).^p - lambda.*g
L = 
Lx = diff(L,x)
Lx = 
Ly = diff(L,y)
Ly = 
Lz = diff(L,z)
Lz = 
sol = solve([Lx==0,Ly==0,Lz==0,g==0],[x y z lambda])
Warning: Unable to find explicit solution. For options, see help.
sol = struct with fields:
x: [0x1 sym] y: [0x1 sym] z: [0x1 sym] lambda: [0x1 sym]
sol.x
ans = Empty sym: 0-by-1
sol.y
ans = Empty sym: 0-by-1
sol.z
ans = Empty sym: 0-by-1
  1 commentaire
Xiao yang
Xiao yang le 22 Mar 2024
I can hand solve this problem, dont know what'wrong the code

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 22 Mar 2024
Déplacé(e) : Walter Roberson le 22 Mar 2024
The 0^n and 0^(m-1) occur because there are not constraints on m and n, so there is the possibility that 0^0 is being generated, and 0^0 is 1 whereas 0^anything_else is 0
syms m n p a x y z lambda real
g = x + y + z -a;
L = (x).^m.*(y).^n.*(z).^p - lambda.*g;
Lx = diff(L,x);
Ly = diff(L,y);
Lz = diff(L,z);
eqns = [Lx==0,Ly==0,Lz==0,g==0];
partial_lambda = solve(eqns(1), lambda, 'returnconditions', true);
%partial_lambda.conditions
eqns2 = subs(eqns(2:end), lambda, partial_lambda.lambda);
partial_x = solve(eqns2(3), x);
eqns3 = subs(eqns2([1:2 4:end]), x, partial_x);
partial_y = solve(eqns3(1), y, 'returnconditions', true);
%partial_y.y
%partial_y.conditions
eqns4 = subs(eqns3(2:end), y, partial_y.y);
syms parameter1 parameter2 real
partial_z1 = subs(solve(eqns4(1,1), z, 'returnconditions', true), sym('x'), parameter1);
partial_z2 = subs(solve(eqns4(2,1), z, 'returnconditions', true), sym('x'), parameter2);
partial_z3 = solve(eqns4(3,1), z, 'returnconditions', true);
%partial_z3.z
%partial_z3.conditions
back_z1 = partial_z1.z;
back_y1 = subs(partial_y.y(1), z, back_z1);
back_x1 = subs(partial_x, {y, z}, {back_y1, back_z1});
back_lambda1 = subs(partial_lambda, {x, y, z}, {back_x1, back_y1, back_z1});
solution1 = [x == back_x1, y == back_y1, z == back_z1, lambda == back_lambda1.lambda]
solution1 = 
back_z2 = partial_z2.z;
back_y2 = subs(partial_y.y(2), z, back_z2);
back_x2 = subs(partial_x, {y, z}, {back_y2, back_z2});
back_lambda2 = subs(partial_lambda, {x, y, z}, {back_x2, back_y2, back_z2});
solution2 = [x == back_x2, y == back_y2, z == back_z2, lambda == back_lambda2.lambda]
solution2 = 
back_z3a = partial_z3.z(1);
back_y3a = subs(partial_y.y(3), z, back_z3a);
back_x3a = subs(partial_x, {y, z}, {back_y3a, back_z3a});
back_lambda3a = subs(partial_lambda, {x, y, z}, {back_x3a, back_y3a, back_z3a});
solution3a = [x == back_x3a, y == back_y3a, z == back_z3a, lambda == back_lambda3a.lambda]
solution3a = 
back_z3b = partial_z3.z(2);
back_y3b = subs(partial_y.y(3), z, back_z3b);
back_x3b = subs(partial_x, {y, z}, {back_y3b, back_z3b});
back_lambda3b = subs(partial_lambda, {x, y, z}, {back_x3b, back_y3b, back_z3b});
solution3b = [x == back_x3b, y == back_y3b, z == back_z3b, lambda == back_lambda3b.lambda]
solution3b = 
back_z3c = partial_z3.z(3);
back_y3c = subs(partial_y.y(3), z, back_z3c);
back_x3c = subs(partial_x, {y, z}, {back_y3c, back_z3c});
back_lambda3c = subs(partial_lambda, {x, y, z}, {back_x3c, back_y3c, back_z3c});
solution3c = [x == back_x3c, y == back_y3c, z == back_z3c, lambda == back_lambda3c.lambda]
solution3c = 
  5 commentaires
Xiao yang
Xiao yang le 28 Mar 2024
thank you very much
Dyuman Joshi
Dyuman Joshi le 29 Mar 2024
Hello @Xiao yang, if this answer solved your problem, please consider accepting the answer.
Accepting the answer indicates that your problem has been solved (which can be helpful to other people in future) and it awards the volunteer with reputation points for helping you.
You can accept only 1 answer for a question, but you can vote for as many answers as you want. Voting an answer also provides reputation points.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by