how to write a code for two input -one output function (f=@(v,r)) using bisection method?

3 visualizzazioni (ultimi 30 giorni)
%declaration of constants and variables
pi=3.14;
G=6.67*10^(-11);M=2*10^30;c=10^4;rho=10^(-21);n=2.5;
gamma=1+(1/n);
dotm=pi*G^2*M^2*(rho/c^3)*(2/(5-3*gamma))^((5-3*gamma)/(2*gamma-2));
u=(dotm/(4*pi*rho))*c^(2*n);
%span of v
v1=10;
v2=10^5;
tol=10^-10;
v=v1:c:v2;
%span of r
r1=.1*7*10^8;
r2=3.8*7*10^8;
r=r1:7*10^8:r2;
%function declaration
f=@(v,r)((v.^2)./2)+(n.*((u./(v.*r.^2)).^(1./n)))-((G*M)./r)-(n.*c.^2);
  6 Commenti
Nabagata Chaudhury
Nabagata Chaudhury il 30 Dic 2022
Modificato: Nabagata Chaudhury il 30 Dic 2022
If f(v1,r) and f(v2,r) should be of opposite sign according to initial condition of bisection method
Jan
Jan il 30 Dic 2022
Before we can suggest some code, you have to mention explicitly, what you want to calculate. I guess, you wanted to use the bisection method to find a root of the function? Then an optimization tool should be applicable for the 2-dim case.

Accedi per commentare.

Risposte (1)

Jan
Jan il 30 Dic 2022
Modificato: Jan il 30 Dic 2022
pi = 3.14; % Brrrr
G = 6.67e-11; M = 2e30; c = 1e4; rho = 1e-21; n = 2.5;
gamma = 1 + 1/n;
dotm = pi*G^2*M^2*(rho/c^3) * (2/(5-3*gamma))^((5-3*gamma)/(2*gamma-2));
u = dotm / (4*pi*rho) * c^(2*n);
v1 = 10;
v2 = 1e5;
r1 = 0.7e8; % .1*7*10^8;
r2 = 3.8*7e8;
f = @(y) y(1)^2 / 2 + (n * ((u / (y(1)*y(2)^2)).^(1/n))) - (G*M)/y(2) - n*c^2;
x = fmincon(f, [v1+v2, r1+r2]/2, [], [], [], [], [v1, r1], [v2, r2])
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 1×2
1.0e+07 * 0.0100 7.0000

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by