Unrecognized “spharm” for spherical harmonics plot?
Hi, I get the following error when trying to plot
Unrecognized function or variable ‘spharm’.
Error in FTyD (line 35)
Ylm = spharm(l, m, Y, X); % Evaluate spherical harmonic Y_lm(x,y)
% Define the function f(t)
f = @(t) 139.85 + (15.8404 + 4.76022i) * exp(-1i * t) + (15.8404 – 4.76022i) * exp(1i * t) + …
(4.64917 – 3.3024i) * exp(-2i * t) + (4.64917 + 3.3024i) * exp(2i * t) + …
(7.42191 – 0.300123i) * exp(-3i * t) + (7.42191 + 0.300123i) * exp(3i * t) + …
(0.340877 – 2.54665i) * exp(-4i * t) + (0.340877 + 2.54665i) * exp(4i * t) + …
(7.72422 + 6.71332i) * exp(-5i * t) + (7.72422 – 6.71332i) * exp(5i * t) + …
(3.16511 – 9.14479i) * exp(-6i * t) + (3.16511 + 9.14479i) * exp(6i * t) + …
(3.31502 + 2.18874i) * exp(-7i * t) + (3.31502 – 2.18874i) * exp(7i * t) + …
(9.31827 + 6.94538i) * exp(-8i * t) + (9.31827 – 6.94538i) * exp(8i * t) + …
(5.87173 + 18.8341i) * exp(-9i * t) + (5.87173 – 18.8341i) * exp(9i * t) + …
(8.75949 + 14.7107i) * exp(-10i * t) + (8.75949 – 14.7107i) * exp(10i * t) + …
(19.2903 + 7.78329i) * exp(-11i * t) + (19.2903 – 7.78329i) * exp(11i * t) + …
(-3.39063 – 18.5502i) * exp(-12i * t) + (-3.39063 + 18.5502i) * exp(12i * t) + …
(3.58427 + 18.7438i) * exp(-13i * t) + (3.58427 – 18.7438i) * exp(13i * t) + …
(2.66129 + 20.0781i) * exp(-14i * t) + (2.66129 – 20.0781i) * exp(14i * t) + …
(-8.46335 – 9.96867i) * exp(-15i * t) + (-8.46335 + 9.96867i) * exp(15i * t) + …
(-8.50037 – 1.20377i) * exp(-16i * t) + (-8.50037 + 1.20377i) * exp(16i * t) + …
(-1.36102 – 16.9315i) * exp(-17i * t) + (-1.36102 + 16.9315i) * exp(17i * t) + …
(-5.78964 – 2.96094i) * exp(-18i * t) + (-5.78964 + 2.96094i) * exp(18i * t) + …
(2.14681 + 8.29635i) * exp(-19i * t) + (2.14681 – 8.29635i) * exp(19i * t) + …
(-3.91145 – 10.7712i) * exp(-20i * t) + (-3.91145 + 10.7712i) * exp(20i * t);
% Parameters
lmax = 10; % Maximum degree for spherical harmonics expansion
% Create grid in x and y
x = linspace(-10, 10, 100);
y = linspace(-10, 10, 100);
[X, Y] = meshgrid(x, y);
% Compute f(x,y)
Fxy = zeros(size(X));
for l = 0:lmax
for m = -l:l
Ylm = spharm(l, m, Y, X); % Evaluate spherical harmonic Y_lm(x,y)
integral_value = integral(@(t) f(t) .* conj(Ylm), -pi, pi); % Compute integral
Fxy = Fxy + integral_value * Ylm; % Accumulate to f(x,y)
end
end
% Plot
figure;
surf(X, Y, real(Fxy), ‘EdgeColor’, ‘none’);
xlabel(‘x’);
ylabel(‘y’);
zlabel(‘Re(f(x,y))’);
title(‘Method 3: Expansion in Spherical Harmonics’);
colorbar;
Cant figure out why…Hi, I get the following error when trying to plot
Unrecognized function or variable ‘spharm’.
Error in FTyD (line 35)
Ylm = spharm(l, m, Y, X); % Evaluate spherical harmonic Y_lm(x,y)
% Define the function f(t)
f = @(t) 139.85 + (15.8404 + 4.76022i) * exp(-1i * t) + (15.8404 – 4.76022i) * exp(1i * t) + …
(4.64917 – 3.3024i) * exp(-2i * t) + (4.64917 + 3.3024i) * exp(2i * t) + …
(7.42191 – 0.300123i) * exp(-3i * t) + (7.42191 + 0.300123i) * exp(3i * t) + …
(0.340877 – 2.54665i) * exp(-4i * t) + (0.340877 + 2.54665i) * exp(4i * t) + …
(7.72422 + 6.71332i) * exp(-5i * t) + (7.72422 – 6.71332i) * exp(5i * t) + …
(3.16511 – 9.14479i) * exp(-6i * t) + (3.16511 + 9.14479i) * exp(6i * t) + …
(3.31502 + 2.18874i) * exp(-7i * t) + (3.31502 – 2.18874i) * exp(7i * t) + …
(9.31827 + 6.94538i) * exp(-8i * t) + (9.31827 – 6.94538i) * exp(8i * t) + …
(5.87173 + 18.8341i) * exp(-9i * t) + (5.87173 – 18.8341i) * exp(9i * t) + …
(8.75949 + 14.7107i) * exp(-10i * t) + (8.75949 – 14.7107i) * exp(10i * t) + …
(19.2903 + 7.78329i) * exp(-11i * t) + (19.2903 – 7.78329i) * exp(11i * t) + …
(-3.39063 – 18.5502i) * exp(-12i * t) + (-3.39063 + 18.5502i) * exp(12i * t) + …
(3.58427 + 18.7438i) * exp(-13i * t) + (3.58427 – 18.7438i) * exp(13i * t) + …
(2.66129 + 20.0781i) * exp(-14i * t) + (2.66129 – 20.0781i) * exp(14i * t) + …
(-8.46335 – 9.96867i) * exp(-15i * t) + (-8.46335 + 9.96867i) * exp(15i * t) + …
(-8.50037 – 1.20377i) * exp(-16i * t) + (-8.50037 + 1.20377i) * exp(16i * t) + …
(-1.36102 – 16.9315i) * exp(-17i * t) + (-1.36102 + 16.9315i) * exp(17i * t) + …
(-5.78964 – 2.96094i) * exp(-18i * t) + (-5.78964 + 2.96094i) * exp(18i * t) + …
(2.14681 + 8.29635i) * exp(-19i * t) + (2.14681 – 8.29635i) * exp(19i * t) + …
(-3.91145 – 10.7712i) * exp(-20i * t) + (-3.91145 + 10.7712i) * exp(20i * t);
% Parameters
lmax = 10; % Maximum degree for spherical harmonics expansion
% Create grid in x and y
x = linspace(-10, 10, 100);
y = linspace(-10, 10, 100);
[X, Y] = meshgrid(x, y);
% Compute f(x,y)
Fxy = zeros(size(X));
for l = 0:lmax
for m = -l:l
Ylm = spharm(l, m, Y, X); % Evaluate spherical harmonic Y_lm(x,y)
integral_value = integral(@(t) f(t) .* conj(Ylm), -pi, pi); % Compute integral
Fxy = Fxy + integral_value * Ylm; % Accumulate to f(x,y)
end
end
% Plot
figure;
surf(X, Y, real(Fxy), ‘EdgeColor’, ‘none’);
xlabel(‘x’);
ylabel(‘y’);
zlabel(‘Re(f(x,y))’);
title(‘Method 3: Expansion in Spherical Harmonics’);
colorbar;
Cant figure out why… Hi, I get the following error when trying to plot
Unrecognized function or variable ‘spharm’.
Error in FTyD (line 35)
Ylm = spharm(l, m, Y, X); % Evaluate spherical harmonic Y_lm(x,y)
% Define the function f(t)
f = @(t) 139.85 + (15.8404 + 4.76022i) * exp(-1i * t) + (15.8404 – 4.76022i) * exp(1i * t) + …
(4.64917 – 3.3024i) * exp(-2i * t) + (4.64917 + 3.3024i) * exp(2i * t) + …
(7.42191 – 0.300123i) * exp(-3i * t) + (7.42191 + 0.300123i) * exp(3i * t) + …
(0.340877 – 2.54665i) * exp(-4i * t) + (0.340877 + 2.54665i) * exp(4i * t) + …
(7.72422 + 6.71332i) * exp(-5i * t) + (7.72422 – 6.71332i) * exp(5i * t) + …
(3.16511 – 9.14479i) * exp(-6i * t) + (3.16511 + 9.14479i) * exp(6i * t) + …
(3.31502 + 2.18874i) * exp(-7i * t) + (3.31502 – 2.18874i) * exp(7i * t) + …
(9.31827 + 6.94538i) * exp(-8i * t) + (9.31827 – 6.94538i) * exp(8i * t) + …
(5.87173 + 18.8341i) * exp(-9i * t) + (5.87173 – 18.8341i) * exp(9i * t) + …
(8.75949 + 14.7107i) * exp(-10i * t) + (8.75949 – 14.7107i) * exp(10i * t) + …
(19.2903 + 7.78329i) * exp(-11i * t) + (19.2903 – 7.78329i) * exp(11i * t) + …
(-3.39063 – 18.5502i) * exp(-12i * t) + (-3.39063 + 18.5502i) * exp(12i * t) + …
(3.58427 + 18.7438i) * exp(-13i * t) + (3.58427 – 18.7438i) * exp(13i * t) + …
(2.66129 + 20.0781i) * exp(-14i * t) + (2.66129 – 20.0781i) * exp(14i * t) + …
(-8.46335 – 9.96867i) * exp(-15i * t) + (-8.46335 + 9.96867i) * exp(15i * t) + …
(-8.50037 – 1.20377i) * exp(-16i * t) + (-8.50037 + 1.20377i) * exp(16i * t) + …
(-1.36102 – 16.9315i) * exp(-17i * t) + (-1.36102 + 16.9315i) * exp(17i * t) + …
(-5.78964 – 2.96094i) * exp(-18i * t) + (-5.78964 + 2.96094i) * exp(18i * t) + …
(2.14681 + 8.29635i) * exp(-19i * t) + (2.14681 – 8.29635i) * exp(19i * t) + …
(-3.91145 – 10.7712i) * exp(-20i * t) + (-3.91145 + 10.7712i) * exp(20i * t);
% Parameters
lmax = 10; % Maximum degree for spherical harmonics expansion
% Create grid in x and y
x = linspace(-10, 10, 100);
y = linspace(-10, 10, 100);
[X, Y] = meshgrid(x, y);
% Compute f(x,y)
Fxy = zeros(size(X));
for l = 0:lmax
for m = -l:l
Ylm = spharm(l, m, Y, X); % Evaluate spherical harmonic Y_lm(x,y)
integral_value = integral(@(t) f(t) .* conj(Ylm), -pi, pi); % Compute integral
Fxy = Fxy + integral_value * Ylm; % Accumulate to f(x,y)
end
end
% Plot
figure;
surf(X, Y, real(Fxy), ‘EdgeColor’, ‘none’);
xlabel(‘x’);
ylabel(‘y’);
zlabel(‘Re(f(x,y))’);
title(‘Method 3: Expansion in Spherical Harmonics’);
colorbar;
Cant figure out why… 3d plots, spherical, harmonics MATLAB Answers — New Questions