5
votes

We have an equation similar to the Fredholm integral equation of second kind.

enter image description here

To solve this equation we have been given an iterative solution that is guaranteed to converge for our specific equation. Now our only problem consists in implementing this iterative prodedure in MATLAB.

For now, the problematic part of our code looks like this:

function delta = delta(x,a,P,H,E,c,c0,w)

delt = @(x)delta_a(x,a,P,H,E,c0,w);

for i=1:500
    delt = @(x)delt(x) - 1/E.*integral(@(xi)((c(1)-c(2)*delt(xi))*ms(xi,x,a,P,H,w)),0,a-0.001);  
end
delta=delt;

end

delta_a is a function of x, and represent the initial value of the iteration. ms is a function of x and xi.

As you might see we want delt to depend on both x (before the integral) and xi (inside of the integral) in the iteration. Unfortunately this way of writing the code (with the function handle) does not give us a numerical value, as we wish. We can't either write delt as two different functions, one of x and one of xi, since xi is not defined (until integral defines it). So, how can we make sure that delt depends on xi inside of the integral, and still get a numerical value out of the iteration?

Do any of you have any suggestions to how we might solve this?

Using numerical integration

Explanation of the input parameters: x is a vector of numerical values, all the rest are constants. A problem with my code is that the input parameter x is not being used (I guess this means that x is being treated as a symbol).

2
Do you use symbolic or numerical integration?Jan
@Jan Numerical integration. (Edited my question)Linda
Maybe x is the vector of grid points where your function is to be approximated....?Jan

2 Answers

0
votes

It looks like you can do a nesting of anonymous functions in MATLAB:

f = 

    @(x)2*x

>> ff = @(x) f(f(x))

ff = 

    @(x)f(f(x))

>> ff(2)

ans =

     8

>> f = ff;


>> f(2)

ans =

     8

Also it is possible to rebind the pointers to the functions.

Thus, you can set up your iteration like

delta_old = @(x) delta_a(x)
for i=1:500
    delta_new = @(x) delta_old(x) - integral(@(xi),delta_old(xi))
    delta_old = delta_new
end

plus the inclusion of your parameters...

0
votes

You may want to consider to solve a discretized version of your problem.

Let K be the matrix which discretizes your Fredholm kernel k(t,s), e.g.

   K(i,j) = int_a^b K(x_i, s) l_j(s) ds

where l_j(s) is, for instance, the j-th lagrange interpolant associated to the interpolation nodes (x_i) = x_1,x_2,...,x_n.

Then, solving your Picard iterations is as simple as doing

  phi_n+1 = f + K*phi_n

i.e.

  for i = 1:N   
       phi = f + K*phi
  end

where phi_n and f are the nodal values of phi and f on the (x_i).