-1

I have a working function of an integral that I would like to expand. I want to consider different parameters dependent on age.

param_1938 for ages >=76
param_1945 for ages 66 to75
param_1955 for ages 61 to 65

The working function that I would like to expand looks like this

x=(0:1:106)';
mu_x=@(t) f_lx(t,param_in);
for ii=1:size(x,1)-61
    l_x(ii,1) = exp(-integral(mu_x,0,60+ii));
end
%%
function res=f_lx(x,param)
a=param(1);
b=param(2);
c=param(3);
res = zeros(size(x));
ind = x>100;
res(ind) = a+b*exp(c*100)+(x(ind)-100)*0.001;
res(~ind) =a+b*exp(c*x(~ind));
end

I'm thinking changing param_in in f_lx(x,param) to f_lx(x,param1938,param_1945,param_1955). How can I do this?

Amendment: This is the mathematical expression of what I'm trying to do

enter image description here

Orongo
  • 285
  • 1
  • 6
  • 16
  • It's unclear what you expect to happen with the additional inputs... – Wolfie Jan 28 '19 at 12:15
  • The limits to the integral is between 61 and 106. So when the integral falls in the different age groups it need to consider the different parameters. So for example, integral_61^65 will use param_1955, and integral_61^77 will use param_1955 for ages 61-65, param_1945 for ages 66-75 and finally param_1938 for ages 76-77. – Orongo Jan 28 '19 at 13:11
  • So you want to evaluate the ux value for all integer x between 60 and 106? – Wolfie Jan 28 '19 at 19:44

1 Answers1

0

You can define the changeable input on the fly in your loop, and redefine the function accordingly

x=(0:1:106)';
for ii=1:size(x,1)-61
    age = 60 + ii; 
    % Define p for the age bracket of the current 'age'
    if age < 66
       p = param_1955;
    elseif age < 76
       p = param_1945;
    else
       p = param_1938;
    end
    % Define a new function, param_in defined by p
    mu_x = @(t) f_lx(t, p);
    % Integrate the new function
    l_x(ii,1) = exp( -integral(mu_x, 0, age) );
end  
Wolfie
  • 27,562
  • 7
  • 28
  • 55
  • Not convinced this solution would work. For age=77 then p=param_1938, and l_x(ii,1) = exp( -integral(mu_x, 0, 77) ); But the integral start from 0, and consider only using p=param_1938 because it is sent in as a parameter to mu_x = @(t) f_lx(t, p);. Right? – Orongo Jan 28 '19 at 14:28
  • I don't think I understand. Please edit your question with expected outputs for specific example inputs... Your first clarification comment suggested you want different parameters depending on the age brackets - that's what I've shown. – Wolfie Jan 28 '19 at 15:12
  • I amended my question, I hope this explains better. – Orongo Jan 28 '19 at 16:11