Borrar filtros
Borrar filtros

Iterative solution for a non-linear equation

13 visualizaciones (últimos 30 días)
Raihan Rahmat Rabi
Raihan Rahmat Rabi el 23 de Jul. de 2021
Comentada: Walter Roberson el 24 de Jul. de 2021
I am looking for a solution to the problem:
ag_p*Gamma_p - Sa = 0 with Gamma_p = A+B*ag_p.
A, B and Sa are constants.
This can be solved by iterations starting with a certain guess value for ag_p. I tried to use the following code:
Sa = 2.7956;
A = 2.24;
B = 0.5547;
f = @(ag_p) ag_p*Gamma_p - Sa;
Gamma_p = A+B*ag_p;
z = fzero(@(ag_p) f(ag_p), 1E-3);
My code cant be run because the Gamma_p is a function of ag_p which is unknown. What would be the efficient way to tell the program to start with a guess value for ag_p ?

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Jul. de 2021
format long g
Sa = 2.7956;
A = 2.24;
B = 0.5547;
Gamma_p = @(ag_p) A+B*ag_p;
f = @(ag_p) ag_p*Gamma_p(ag_p) - Sa;
z = fzero(@(ag_p) f(ag_p), 1E-3)
z =
1.00026869288617
f(z)
ans =
-4.44089209850063e-16
  3 comentarios
Raihan Rahmat Rabi
Raihan Rahmat Rabi el 23 de Jul. de 2021
Can you suggest another method, where the problem in question is solved by providing guess values to ag_p, let's say from [0...inf], and Gamma_p is updated based on the guess values of ag_p and the iterations are performed until the solution is found. I need to have a numerical value for Gamma_p in each iteration because I will be comparing its value with another constant parameter to define some "if" conditions before the fzero function is written.
Thank you,

Iniciar sesión para comentar.

Más respuestas (1)

Chunru
Chunru el 23 de Jul. de 2021
Sa = 2.7956;
A = 2.24;
B = 0.5547;
% Change the original code to the following. Otherwise not working.
f = @(ag_p) ag_p*(A+B*ag_p) - Sa;
%Gamma_p = A+B*ag_p;
z = fzero(@(ag_p) f(ag_p), 1E-3) % 1E-3 is the initial value
z = 1.0003
z0 = 0.99; % a closer initial value
z = fzero(@(ag_p) f(ag_p), z0)
z = 1.0003

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by