简体   繁体   中英

using Matlab fsolve() to find the zero points of 2 function with 2 variables

im using Matlab to trying to solve 2 equations with 2 variables.

I define the 2 functions, f2(n_1,n_2),f3(n_1,n_2) which both depend on f1(n_1,n_2) , then I defined the vectorised function G(n_1,n_2) which contain both of them.

Later I defined a the desired stating point, and tried to solve. but when running the code it raise an error which I'm not fully understand.

the above mentioned is displayed in the code below:

the code:

clear, close all; clc
%Const
N0=25;
G1=1;G2=1;
a1=6;a2=3;
k1=1;k2=4;
%main
syms n_1 n_2
X_0=[-5;5];
f1=N0-a1.*n_1-a2.*n_2;
f2=f1.*G1.*n_1-k1.*n_1;
f3=f1.*G2.*n_2-k2.*n_2;
G=@(n_1,n_2) [f2;f3];
s = fsolve(G,X_0);

the error:

Error using fsolve (line 269)
FSOLVE requires all values returned by functions to be of data type     double.

Error in Ex1_Q3_DavidS (line 37)
s = fsolve(G,X_0);

thanks

fsolve is a function that uses numerical methods to find the root of a numerical function.

A numerical function is, for example f=@(x)x^2=2; . In MATLAB, you can evaluate f() at any number and it will return a number, but there is no higher order mathematical abstraction to it. This is however the fastest way to do maths in a computer, as it is not a higher intelligence, just a glorified calculator.

Some people however, want to give higher intelligence to computers and coded very complex symbolic toolboxes that with sets of rules try to teach computers to think semi-like humans and solve symbolic equations, as you do in paper. To solve those equations a function called solve is introduced in MATLAB.

You are doing symbolic math, but using the numeric solver. It does not work, just use the symbolic solver for symbolic math.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM