I need to solve the non linear equation

74 views (last 30 days)
gopu777
gopu777 on 23 Nov 2015
function F =root2d(x)
F(1) = (P-G)*(x+a*x^(b+1)/(b+1));
F(2)= G*((h-x)+a*(h-x)^(b+1)/(b+1));
fun = @root2d;
x0=[0 0];
x= fsolve(fun,x0)
i have tried in this way it shows error

Answers (1)

Walter Roberson
Walter Roberson on 23 Nov 2015
None of the variables a, b, G, h, P are defined in your function root2d() . The only way you could get that to work is if you were to use a nested function with the outer function defining those values. But in order to use a nested function, you would need to add an "end" statement to the code
function x = solve_my_function
%give values to the variables you are going to use in the nested function
a = randn();
b = randn();
G = randn();
h = rand();
P = randn();
%define a nested function
function F = root2d(x)
F(1) = (P-G)*(x+a*x^(b+1)/(b+1));
F(2)= G*((h-x)+a*(h-x)^(b+1)/(b+1));
end %*need* this 'end' for nested function
%finished defining the nest function. Now we can use it
fun = @root2d;
x0 = [0 0];
x = fsolve(fun, x0);
end %*need* this 'end' in the outer function to use nested functions
  1 Comment
mohammed aadil ahmed
mohammed aadil ahmed on 25 Feb 2019
is it necessary to use nested function ? or can we use in a regular script?

Sign in to comment.

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!