I'm trying to solve two non-linear equations using fsolve
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi I am trying to solve the two non-linear equations below with the initial x = 6 and y =6. I keep getting errors shown at the bottom that I dont understand how to fix. Any suggestions?
% Given: two non-linear simutaneous equations
% f(x,y) = 4 - y - 2x^2 and g(x,y) = 8 - y^2 - 4x
% Find:
% (1) Provide a function for storing f and g
% (2) Provide a test script to call the function storing the system
% of nonlinear equations and solve the two equations. Use xo = 6 and
% yo=6 as initial values.
% Solution:
% Let the initial conditions be plugged into the equations.
[x,fx] = fsolve(@fun,[6;6]);
% Set up the functions that will store the equations that can be
% called
function [f,g] = fun(x,y)
f = 4-y-2*x^2;
g = 8-y^2-4*x;
end
ERRORS I RECIEVED:
Not enough input arguments.
Error in Homework4_5>fun (line 36)
f = 4-y-2*x^2;
Error in fsolve (line 264)
fuser = feval(funfcn{3},x,varargin{:});
Error in Homework4_5 (line 29)
[x,fx] = fsolve(@fun,[6;6]);
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.
댓글 수: 0
답변 (1개)
Torsten
2022년 10월 31일
Variables and residuals must be put into one single vector:
[x,fx] = fsolve(@fun,[6;6])
% Set up the functions that will store the equations that can be
% called
function res = fun(z)
x = z(1);
y = z(2);
f = 4-y-2*x^2;
g = 8-y^2-4*x;
res = [f;g];
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!