"Arrays have incompatible sizes for this operation" with for loop in integral2

4 views (last 30 days)
I am going to find a fixed point for some intergal represented function.
(this is just an example, I do not know if the fixed point exists or not) by the iteration:
My code is like that:
input = @(y,s) y;
N_it=10;
output=cell(1, N_it);
output{1}=input;
density = @(z,t,s) exp( -(z.^2)./(2.*(s-t)) ) ./ (sqrt(2*pi).*sqrt(s-t));
for i=1:N_it
input=output{i};
integral = @(y,t) integral2( @(z,s) input(z,s).*density(z-y,t,s),0,100,@(t)t,T,'RelTol',0,'AbsTol',1e-5);
n_output=@(y,t)integral(y,t);
output{i+1}=n_output;
end
For N_it =1, I can get the answer, there is no error. For N_it>1, when I find the value of n_output(1,1), there is an error "Arrays have incompatible sizes for this operation." and then a very long list indicating my problematic lines.

Answers (1)

VBBV
VBBV on 13 Mar 2024
input = @(y,s) y;
N_it=10;
output=cell(1, N_it);
output{1}=input;
density = @(z,t,s) exp( -(z.^2)./(2.*(s-t)) ./ (sqrt(2*pi).*sqrt(s-t)));
for i=1:N_it
input=output{i};
integral = @(y,t) integral2( @(z,s) input(z,s).*density(z-y,t,s),0,100,@(t)t,T,'RelTol',0,'AbsTol',1e-5);
n_output=@(y,t)integral(y,t);
output{i+1}=n_output;
end
output(1,1)
ans = 1×1 cell array
{@(y,s)y}
  8 Comments
ho man
ho man on 13 Mar 2024
Yes, your code is correct. Thank you so much. My code is the same as yours but the last line "output(1,1)" is replaced by "n_output(1,1)". What is the mistake here?
ho man
ho man on 13 Mar 2024
@VBBV I finally see the extra ) in the exp function in the very beginnin code, thank you.

Sign in to comment.

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!