I am using the curve fitting app on matlab to fit the following function to my data set:
y(x) = (a0*(1-exp(-b0*(x-c0))))+(a1*(1-exp(-b1*(x-c1))))
However, I would like to alter the equation to be:
y(x) = ((a0*(1-exp(-b0*(x-c0))))*u0)+((a1*(1-exp(-b1*(x-c1))))*u1)
with the following command
u0 = if(x<c0,0,1)
u1= if(x<c1,0,1)
i.e. y would equal 0 until x passes c0 and y(x) would equal the first part of the equation between c0 and c1 and the full model from c1 onwards.
Please see page three on the attached pdf under VO2 kinetics for a similar example.
Any help would be greatly appreciated.

 採用された回答

Walter Roberson
Walter Roberson 2019 年 5 月 23 日
編集済み: Walter Roberson 2019 年 5 月 23 日

1 投票

y = @(x) ((a0*(1-exp(-b0*(x-c0)))).*(x>=c0)) + ((a1*(1-exp(-b1*(x-c1)))).*(x>=c1))

2 件のコメント

Julian Dale
Julian Dale 2019 年 5 月 23 日
Hi Walter,
Thanks for your quick response. Would it be correct to say that .* means when.
Thanks
Julian
Walter Roberson
Walter Roberson 2019 年 5 月 23 日
.* means element-by-element multiplication.
The result of a logical test is a logical array of true and false values. In many circumstances, the value false is automatically converted to 0, and the value true is automatically converted to 1. So if you multiply by a logical value, then if the logical value was false, that is multiplication by 0, and if the logical value was true, then that is multiplication by 1.
The situation you need to watch out for is the case where an unselected case generates infinity:
(1./x).*(x ~= 0) + -1 .* (x == 0)
looks like it should express:
x == 0 -> -1
x ~= 0 -> 1/x
However, when x is 0, then 1/x is inf, and you would be calculating (inf).*(0) but inf*0 is NaN, and NaN + anything is NaN.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

製品

リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by