Effacer les filtres
Effacer les filtres

funzione non lineare, 3 incognite in tre equazioni. Ho bisogno di soluzioni delle incognite solo poitive

15 vues (au cours des 30 derniers jours)
Ciao, ho il seguente sistema di 3 equazioni in 3 incognite da risolvere con la funzione fsolve
function F = systemNL(V)
k1=0.7;
k2=0.8;
F(1) = V(1) - R * ((Iscr * G1 / Gref + ki * (T - Tr) + Irr * (exp(q * vvv(2) / (kb * A)) - 1)) * (1 - k1) + (Iscr * G2 / Gref + ki * (T - Tr) + Irr * (exp(q * vvv(3) / (kb * A)) - 1)) * (1 - k2));
F(2) = V(2) - V(1) * (1 - k1);
F(3) = V(3) - V(1) * (1 - k2);
end
Problema:
Come faccio a trovare una terna di inizializzazione positiva(V0) che mi renda una soluzione fattibile con V1, V2 ed V3 numeri positivi?

Réponses (1)

Divyam
Divyam le 12 Juil 2024 à 4:04
Hi Michele,
In this situation, the code seems to be interacting with physical systems, generally [0,0,0] is good initial guess. However, a multi-start approach can be applied to the "fsolve" function to get more solutions which can be excluded analytically.
To obtain a feasible solution, the "initial guess" should be a good starting point. However, there is no numerical way to get such starting points.
Further illustrating my point, consider the simple nonlinear equation, , using "fsolve" on this equation leads to the following results with initial guesses, [0, 1, 5].
% Setting fsolve display to off to remove iterations being printed out
options = optimoptions('fsolve','Display','off');
% Declaring (x-1)^2
function f = func(x)
f = x^2 - 2*x + 1;
end
% Storing initial guesses in an array
multiStart = [0,1,5];
% Iterating through each initial guess and using fsolve for them
for idx = 1:numel(multiStart)
sol = fsolve(@func, multiStart(idx), options);
fprintf("The solution for initial guess %d is: %.5f\n", multiStart(idx), sol)
end
The solution for initial guess 0 is: 0.99219 The solution for initial guess 1 is: 1.00000 The solution for initial guess 5 is: 1.00586
If the dimensions of the same function are increased, the impact of the initial guess increases too, as observed in the case of
% Declaring (x-1)^20
function f = funcHigher(x)
f = x^20 - 20*x^19 + 190*x^18 - 1140*x^17 + 4845*x^16 - 15504*x^15 + 38760*x^14 ...
- 77520*x^13 + 125970*x^12 - 167960*x^11 + 184756*x^10 - 167960*x^9 + 125970*x^8 ...
- 77520*x^7 + 38760*x^6 - 15504*x^5 + 4845*x^4 - 1140*x^3 + 190*x^2 - 20*x + 1;
end
% Iterating through each initial guess and using fsolve for them
for idx = 1:numel(multiStart)
sol = fsolve(@funcHigher, multiStart(idx), options);
fprintf("The solution for initial guess %d is: %.5f\n", multiStart(idx), sol)
end
The solution for initial guess 0 is: 0.36974 The solution for initial guess 1 is: 1.00000 The solution for initial guess 5 is: 1.75944
Upon running this code, the significantly off garbage floating point values can be observed on a seemingly "wrong" initial guess. The initial guess for the "right" answer was determined analytically since its evident that 1 is a root of .
The point stands, there is no right or wrong initial guess if the "fsolve" converges. There are merely more correct initial guesses which are determined by eliminating solutions or guessing values analytically.

Tags

Community Treasure Hunt

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

Start Hunting!