I'm trying to solve two non-linear equations using fsolve
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Torsten
am 31 Okt. 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu Systems of Nonlinear Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!