how to write a code for two input -one output function (f=@(v,r)) using bisection method?
3 views (last 30 days)
Show older comments
%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 Comments
Jan
on 30 Dec 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.
Answers (1)
Jan
on 30 Dec 2022
Edited: Jan
on 30 Dec 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])
0 Comments
See Also
Categories
Find more on Bartlett in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!