how to write a code for two input -one output function (f=@(v,r)) using bisection method?
3 次查看(过去 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 个评论
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
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])
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bartlett 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!