How to define a function with multiple handle in a loop?
显示 更早的评论
I have a situation where I need to use a function that can take different number of input (depnding upon the number of treatment considered).
The function has a general expression (Attached as Pic for readability)
Currently I am defining the function (for different number of treatment) seperately (as bellow)
%% Parameters
par.a=80/365;% %; %bitting frequiency (per day)
par.g=1/10; %mosquito death rate (per day)
par.n=12; %duration of sporogony in mopsquito
par.b=.5; %transmission probability: mosquito to human
par.c=.23; %transmission probability: human to mosquito
par.r=1/60; %rate of blood stage infection clearance
par.omega=1/425 ; %hypnozoites death rate
par.nu=8.5; %Number of hypnozoites per infection
par.alpha=1/332;%1/332;
p_blood=.9; %treatment effect
p_rad=.9; %treatment effect
% tau is the current time
% s1,s2,s3 are treatment time.
pA=@(tau) par.alpha*(exp(-par.r*tau)-exp(-(par.alpha+par.omega)*tau))/(par.alpha+par.omega-par.r); %Base function without treatment
pA_rad=@(tau,s1) (1-p_blood)*exp(-par.r*(tau-s1)).*pA(s1)+(1-p_rad)*(pA(tau)-exp(-par.r*(tau-s1)).*pA(s1)); %with one treatment
pA_rad2=@(tau,s1,s2) (1-p_blood)*exp(-par.r*(tau-s2)).*pA_rad(s2,s1)+(1-p_rad)^2*(pA(tau)-exp(-par.r*(tau-s2)).*pA(s2)); %with two treatment
pA_rad3=@(tau,s1,s2,s3) (1-p_blood)*exp(-par.r*(tau-s3)).*pA_rad2(s3,s1,s2)+(1-p_rad)^3*(pA(tau)-exp(-par.r*(tau-s3)).*pA(s3)); %with three
as I couldn't figure out how to define these in a single function. The main issue is that as the number of treatment increases, the function handle increases as well and the function with larger handles utilise the function with lower handles for different inputs (as is attached pic). This is making me crazy. Is there any way that I can define these in a loop or nested function? Any help is much appreciated.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Manage Products 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


