Unrecognized function or variable 'x'.

Hello.
I don’t understand why I don’t have x defined after running the code, if initially it says errors. Help me please
function F=M36(x)
F=[3*x(1)*x(2) - x(1)^2 - x(2)^2 - 5;
7*x(1)^2 * x(2)^2 - x(1)^4 - x(2)^4 - 155];
options = optimoptions('fsolve','Display','iter');
[~,~] = fsolve(F,[-4,0],options);
[~,~] = fsolve(F,[0,4],options);
disp('Plotting graphs of the left sides of the system equations:')
x=-5:0.1:5;
y= (3/2).*x+ sqrt((13/4).*x.^2+5);
plot(y,x,'b')
hold on
x=-5:0.1:5;
y = sqrt((x^4 + 155) / (7*x^2 - y^2));
plot(y,x,'b')
hold on
grid on
legend('Graphic solution');
end

댓글 수: 3

It's not clear to me what you want to do.
However, I have cleaned some things up in the code, check it out -
M36
Norm of First-order Trust-region Iteration Func-count ||f(x)||^2 step optimality radius 0 3 169362 1.05e+05 1 1 6 55891.4 1 2.56e+04 1 2 9 29320.3 1 5.51e+03 1 3 12 24368.2 1 633 1 4 15 24050.7 1 6.04 1 5 18 23882 1 387 1 6 21 2418.33 2.5 6e+03 2.5 7 24 1421.97 5.08058 1.33e+04 6.25 8 27 46.4093 0.628623 1.54e+03 6.25 9 30 0.202455 0.0731741 99.1 6.25 10 33 5.13304e-07 0.00327403 0.158 6.25 11 36 4.6714e-17 9.04034e-06 1.5e-06 6.25 12 39 0 5.10498e-11 0 6.25 Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Norm of First-order Trust-region Iteration Func-count ||f(x)||^2 step optimality radius 0 3 169362 1.05e+05 1 1 6 55891.4 1 2.56e+04 1 2 9 29320.3 1 5.51e+03 1 3 12 24368.2 1 633 1 4 15 24050.7 1 6.04 1 5 18 23882 1 387 1 6 21 2418.33 2.5 6e+03 2.5 7 24 1421.98 5.08058 1.33e+04 6.25 8 27 46.4089 0.628623 1.54e+03 6.25 9 30 0.202457 0.0731742 99.1 6.25 10 33 5.13306e-07 0.00327404 0.158 6.25 11 36 4.6841e-17 9.04036e-06 1.51e-06 6.25 12 39 3.2438e-27 5.02268e-11 1.25e-11 6.25 Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Plotting graphs of the left sides of the system equations:
Warning: Imaginary parts of complex X and/or Y arguments ignored.
ans = function_handle with value:
@(x)[3*x(1)*x(2)-x(1)^2-x(2)^2-5;7*x(1)^2*x(2)^2-x(1)^4-x(2)^4-155]
function F = M36
% Correction
% vvvv
F = @(x) [3*x(1)*x(2) - x(1)^2 - x(2)^2 - 5;
7*x(1)^2 * x(2)^2 - x(1)^4 - x(2)^4 - 155];
options = optimoptions('fsolve','Display','iter');
[~,~] = fsolve(F,[-4,0],options);
[~,~] = fsolve(F,[0,4],options);
disp('Plotting graphs of the left sides of the system equations:')
x=-5:0.1:5;
y1 = (3/2).*x+ sqrt((13/4).*x.^2+5);
figure
plot(y1,x,'b')
hold on
%Correction
%vv vv vv vv vv vv
y2 = sqrt((x.^4 + 155) ./ (7*x.^2 - y1.^2));
%Changed the color of the plot to differentiate
plot(y2,x,'r')
hold off
grid on
legend('Graphic solution');
end
Maria
Maria 2023년 11월 16일
편집: Maria 2023년 11월 17일
I want to solve a system of nonlinear equations 3*x(1)*x(2) - x(1)^2 - x(2)^2 = 5;
7*x(1)^2 * x(2)^2 - x(1)^4 - x(2)^4 = 155 create a file - m using the extended function fzero, check the solution using the roots function, and also plot solutions
syms x [1 2]
eqns = [3*x(1)*x(2) - x(1)^2 - x(2)^2 == 5;
7*x(1)^2 * x(2)^2 - x(1)^4 - x(2)^4 == 155]
eqns = 
sol = solve(eqns)
sol = struct with fields:
x1: [4×1 sym] x2: [4×1 sym]
subs([x1, x2], sol)
ans = 

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

답변 (1개)

Walter Roberson
Walter Roberson 2023년 11월 16일

2 개 추천

F = @(x)[3*x(1)*x(2) - x(1)^2 - x(2)^2 - 5;
7*x(1)^2 * x(2)^2 - x(1)^4 - x(2)^4 - 155];

카테고리

질문:

2023년 11월 16일

편집:

2023년 11월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by