0

I want to solve the following integral using numerical techniques. My integral are

1.) I want to solve a PDE system which is given by

PDE system

I only required the integral terms. Here what I tried

%% Discretization of Age , Space and Time

% Time discretization
dt=0.04;
t=0:dt:20;
m=length(t);

% Age discretization
da=0.08;
a=0:da:60;
n=length(a);

% Space discretization
dx=0.06;
x=0:dx:20;
p=length(x);

%% Size of Matrices
f=zeros(m,n,p);
g=zeros(m,n,p);

%% Initial Data
for j=1:n
    for k=1:p
        f(1,j,k)=0.0009.*exp(-0.01.*a(j))+(sin(0.05*x(k)))^2;                 
        g(1,j,k)=0.0009*exp(-0.08.*a(j)) +(sin(0.05*x(k))^2)^2;                     
       
    end
end

%% Initial function 
for j=1:n
    r(j)=exp(-2*a(j));                                                                                                                               
end

r=@(a) r(j);
J=@(x)(1./sqrt(pi)).*exp(-x.^2);
f_space=@(x) f(1,j,k);
g_space=@(x) g(1,j,k);
g_age=@(a) g(1,j,k);

for j=1:n
     for k=1:p                                             
         B(j,k)=(1)./(exp{a(j)}+10);                                          
     end  
end

for j=1:n
   for k=1:p
P(1,j,k)=trapz(r(a(j)).*g_age(a(j)),a)*da;
J_1(1,j,k)= conv(J(x(k)),f_space(x(k)))*dx;
J_2(1,j,k)= conv(J(x(k)),g_space(x(k)))*dx;
   end
end

%% Finite difference Scheme (Forward)
for i=2:m
   for j=1:n-1
        for k=1:p
 f(i,j,k)=dt*(-P(i-1,j,k).*(f(i-1,j,k)))+dt*(J_1(i-1,j,k)-f(i-1,j,k))-f(i-1,j,k);
 g(i,j,k)=dt*(P(i-1,j,k).*(f(i-1,j,k)))+dt*(J_2(i-1,j,k)-I(i-1,j,k))-I(i-1,j,k);
 g_age=@(a) g(i,j,k);
 f_space=@(x) f(i,j,k);
 g_space=@(x) g(i,j,k);
 P(i,j,k)=trapz(r(a(j)).*g_age(a(j)),a);
 J_1(i,j,k)=conv(J(k),f(i,j,k)); 
 J_2(i,j,k)=conv(J(k),g(i,j,k));  
 I(i,1,k)=0;
        end
    end
 end

This code doesn't seems to work first of all it shows the same value for function P for all i,j and k. Also the code doesn't run in last step. Can you tell me where I went wrong and how can I improve this code.

Adriaan
  • 17,741
  • 7
  • 42
  • 75

0 Answers0