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

조회 수: 6 (최근 30일)
%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
Nabagata Chaudhury
Nabagata Chaudhury 2022년 12월 30일
편집: Nabagata Chaudhury 2022년 12월 30일
If f(v1,r) and f(v2,r) should be of opposite sign according to initial condition of bisection method
Jan
Jan 2022년 12월 30일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2022년 12월 30일
편집: Jan 2022년 12월 30일
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

카테고리

Help CenterFile Exchange에서 Bartlett에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by