Prolate spheroid surface area

9 vues (au cours des 30 derniers jours)
Joshua Ustaran-Anderegg
Joshua Ustaran-Anderegg le 5 Oct 2022
I am trying to calculate the surface area of a prolate spheroid using matlab. I am using the equations for s and e as stated in the following article https://mathworld.wolfram.com/ProlateSpheroid.html. I already know the value of the polar radius c (25), but am wanting to insert a vector of possible answers for a so that I produce a vector of surface areas s. This is what I have coded so far but only works for individual values of a rather than vectors. Any help would be much appreciated.
function s = surface_area_calculator(c,a)
e = sqrt(c^2 - a^2)/25;
s = (2*pi*a^2) + ((2*pi*a*c)/e)*asin(sqrt(c^2 - a^2)/c));
end

Réponses (2)

John D'Errico
John D'Errico le 5 Oct 2022
You need to learn about the dotted operators, and why they are necessary.
Yuou want to compute an element-wise operation, one that applies to every element of a vector. These are the .*, .^ and ./ operators, as * and * and ^ do different things in MATLQAB when applied to matrices and vectors.
You don't need them when you multiply by a scalar, but be careful, as if you divide a scalar by a vector, you need the dotted operator.
And there are no .+ or .- operators, as they are not needed.
Since a is a vector, this will be sufficient:
e = sqrt(c^2 - a.^2)/25;
s = (2*pi*a.^2) + ((2*pi*a*c)./e)*asin(sqrt(c^2 - a.^2)/c));
See that 2*pi*a*c)/e was acceptable, since 2, pi and c are al assumed scalars. But e is a vector, as is a.
Had you just used the dotted operators through out that function, it would have worked too.
  1 commentaire
Joshua Ustaran-Anderegg
Joshua Ustaran-Anderegg le 5 Oct 2022
Thank you very much

Connectez-vous pour commenter.


Torsten
Torsten le 5 Oct 2022
Modifié(e) : Torsten le 5 Oct 2022
I calculated the surface area of a sphere of radius 1 which should be 4*pi.
The below formula from WolframAlpha seems to work for prolate spheroids while your implementation fails.
format shortE
c = [1 4 16 55];
a = [1 3 10 32];
s = 2*pi*(a.^2+c.^2.*hypergeom([0.5,1],[1.5],1-c.^2./a.^2))
s = 1×4
1.0e+00 * 1.2566e+01 1.3893e+02 1.7818e+03 1.9349e+04
4*pi
ans =
1.2566e+01
e = sqrt(c.^2 - a.^2)/25;
s = 2*pi*a.^2 + 2*pi*a.*c./e.*asin(sqrt(c.^2 - a.^2)./c)
s = 1×4
1.0e+00 * NaN 5.7146e+02 2.4306e+03 1.2304e+04

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by