Info

# Forming function handles in matrix

2 views (last 30 days)
Bathala Teja on 6 Oct 2021
Closed: Stephen23 on 6 Oct 2021
I want to form array of function handles first.
After that i need to form 20*20 matrix by involving integration of these function handles.
I provided my script below, iam facing the below error.
Ginvi = @(phi)zeros(size(phi));
for i=2:10
Ginvi = @(phi)Ginvi(phi)+3.56*cos(2*i*(phi-1.5));
end
nr = cell(1, 20);
wr = cell(1, 20);
for j = 1:4
for n = (((j-1)*5)+2):(j*5)
nr{n} = @(phi)50*cos(phi+n*2)+32*2/3;
wr{n} = @(phi)50*cos(phi+n*2);
end
end
for n = 1:5:20
nr{n} = @(phi)60*cos(phi-3.56+(n-1)*5)+32*2/3;
wr{n} = @(phi)60*cos(phi-3.56+(n-1)*5);
end
nr
nr = 1×20 cell array
{@(phi)60*cos(phi-3.56+(n-1)*5)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)60*cos(phi-3.56+(n-1)*5)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)60*cos(phi-3.56+(n-1)*5)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)60*cos(phi-3.56+(n-1)*5)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3} {@(phi)50*cos(phi+n*2)+32*2/3}
lrr = ones(20, 20);
for i = 1:20
for j = 1:20
lrr(i, j) = 55*integral(@(phi)(nr{i}*wr{j}*Ginvi(phi)), 0, 2*pi);
end
end
Operator '*' is not supported for operands of type 'function_handle'.

Error in solution (line 24)
lrr(i, j) = 55*integral(@(phi)(nr{i}*wr{j}*Ginvi(phi)), 0, 2*pi);

Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);

Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);

Error in integralCalc (line 75)

Error in integral (line 87)
Q = integralCalc(fun,a,b,opstruct);
lrr

R2021b

### Community Treasure Hunt

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

Start Hunting!