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

조회 수: 1 (최근 30일)
Xiao yang
Xiao yang 2024년 3월 22일
댓글: Dyuman Joshi 2024년 3월 29일
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
Xiao yang
Xiao yang 2024년 3월 22일
I can hand solve this problem, dont know what'wrong the code

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2024년 3월 22일
이동: Walter Roberson 2024년 3월 22일
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
Xiao yang
Xiao yang 2024년 3월 28일
thank you very much
Dyuman Joshi
Dyuman Joshi 2024년 3월 29일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by