How to change anonymous function to take array parameter and subject to ranges
1 ビュー (過去 30 日間)
Hi, I have a working anonymous function that takes a vector of size 1x3 and I want to expand this to 3x3. The function is named mu_x and looks like this
res = zeros(size(x));
ind = x>100;
res(ind) = a+b*exp(c*100)+(x(ind)-100)*0.001;
The 1x3 param is now [a b c] and the 3x3 parameter I want to use is subject to x such as:
just to clarify the new param looks something like this
a1 b1 c1
a2 b2 c2
a3 b3 c3
How can the anonymous function be changed to consider the ranges of x and new format of param?
James Tursa 2018 年 10 月 31 日
編集済み: James Tursa 2018 年 10 月 31 日
You need to be careful with how you build your anonymous function:
mu_x = @(t) f_lx(t,param);
In the above line, t is an argument that can change with every call, but param is a fixed snapshot of whatever it happens to be at the time you create mu_x. Changing param downstream in your code will have no effect on mu_x. The param in mu_x will still be that fixed snapshot of the param that existed at the time mu_x was created. If you want to use a new param with mu_x, you will need to recreate mu_x from scratch (i.e., execute the above line again).
Bottom line: If you originally created mu_x with a 1x3 param, and then downstream in your code change param in any way (to a new 1x3 or to a 3x3 etc), then you will have to recreate mu_x from scratch in order for it to use that new param.
Simpler: Just call f_lx directly ... what do you need that mu_x for?