Nested Anonymous Function in fminsearch not enough inputs
古いコメントを表示
I created a script as follows:
clear, clc, close all
a = 0.1;
b = 0.05;
m =0;
n = 0;
%Number of iterations
iter = 10;
%Vector Arrays
x = linspace(0,0.1,iter);
y = linspace(0,0.05,iter);
%Grid Array
[X,Y] = meshgrid(x,y);
%Nested Loops
for m = 0:iter
for n = 0:iter
P = ((sin(m*pi*X/a)).^2.*(cos(n*pi*Y/b)).^2)+((cos(m*pi*X/a)).^2.*(sin(n*pi*Y/b)).^2);
n = n+1;
end
m = m+1;
end
contour(X,Y,P)
title('Electromagnetic Power Density (W/m2)');
grid on;
Now I want to perform a fminsearch and am using the following code:
clear, clc, close all
a = 0.1;
b = 0.05;
m = 0;
n = 0;
%Number of iterations
iter = 10;
%Vector Arrays
x = linspace(0,0.1,iter);
y = linspace(0,0.05,iter);
WGPower = @(a,b,m,n,x,y)((sin(m*pi*x/a)).^2.*(cos(n*pi*y/b)).^2)+((cos(m*pi*x/a)).^2.*(sin(n*pi*y/b)).^2);
[pos,fmin]=fminsearch(WGPower,[0.01 0.01]);
fprintf('\nThe position of the min is: %2.4f\n',pos)
fprintf('The value of the min position is: %2.4f \n',fmin)
I keep getting the 'Not enough input arguments' error, however all the inputs have been accounted for.
Any assistance would be appreciated.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!