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!