wrote the code but the error says Unrecognized function or variable 'a'. Error in firle (line 13) Z = A(a)*B(b);

1 view (last 30 days)
x= (0:.1:5);
y= (0:.1:5);
[X,Y] = meshgrid(x,y);
for n=1:7
for m=1:7
A = @(a) (2/sqrt(a))*sin((m*pi/5)*a);
B = @(b) sin((n*pi/5)*b);
Z = A(a)*B(b);
[X,Y,Z] = meshgrid(x,y,z);
surf(x,y,Z)
end
end

Answers (2)

Cris LaPierre
Cris LaPierre on 30 Jul 2020
The issue is with the line Z = A(a)*B(b);
You have not defined the variable 'a' or 'b'. That is resulting in the error you see. Did you mean to use n and m?

Image Analyst
Image Analyst on 31 Jul 2020
Perhaps you wanted this:
x = 0 : 0.1 : 5;
y = 0 : 0.1 : 5;
[X, Y] = meshgrid(x, y);
a = X(:);
b = Y(:);
numElements = numel(a);
n = linspace(1, 7, numElements)';
m = n;
A = (2 ./ sqrt(a)) .* sin((m * pi/5) .* a);
B = sin((n * pi/5) .* b);
Z = A .* B;
% Reshape from column vector into 2-D
Z = reshape(Z, length(x), length(y));
surf(X, Y, Z)
xlabel('x', 'FontSize', 18);
ylabel('y', 'FontSize', 18);
zlabel('z', 'FontSize', 18);
Riddhi, is this what you wanted?

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!