implementation of the bisection method
Mostra commenti meno recenti
Hi everyone,
I'd like to use the bisection method to find the V values that will make my set of functions equal to zero (V_ls).
func=@(V) -Pstar+(R*T*(((1-c)/V)-((c/b)*log(1-b/V)))-a*c/V^2)
note that a,b,c,R retain always the same value, the difference that makes my set of equations is the values of Pstar,T that will then determine the V value that I'm looking for.
I successfully managed to do this process for one given function, by setting the value of Pstar and T.
I'd like to be able to repeat this process automatically for different values of Pstar and T that are stored in a vector.
Pstar=Pstars(i)
T=temp(i)
%i have 30 values (given by the problem) in each vector, i.e. i=30
%range values where the solution can be found.
V=0.0320;
lim_max= 0.1951;
%bisection method
number_iterations= 100 % i can set this value arbitrarily
for i=1:number_iterations
Vls=(V+lim_max)/2;
if fun(Vls)<0
lim_max=Vls;
else
V=Vls;
end
end
I suppose I should put this for cicle into a new one, but I really cant manage to get the results I want:
an output vector V_ls that contains each solution given by the bisection method for each of my 30 equations.
Many thanks !
4 Commenti
Torsten
il 5 Nov 2022
I don't see any executable code for one pair (T,Pstar).
Ivan De Fazio
il 5 Nov 2022
Torsten
il 5 Nov 2022
Yes, I understand this. But the code above does not work for one pair. How should I change it for 30 pairs then ?
If you want to try it on your own:
Make a function "bisection" that is called with the necessary inputs (temp(i),Pstar(i),fun,maximum number of iterations,...) and returns V(i). Then call this function in a loop like:
for i=1:30
Vsol(i) = bisection(temp(i),Pstar(i),fun,Vinit,max_iter,...);
end
Ivan De Fazio
il 5 Nov 2022
Modificato: Ivan De Fazio
il 5 Nov 2022
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Desktop in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

