How do I define this integral function?
1 回表示 (過去 30 日間)
古いコメントを表示
Attached is a pdf of the function I am trying to define. t' is the integral variable (which in the code I name x). ω, s, μ are variable parameters that will take a range of values that the user chooses. AT is a vector of 12054 temperatures which, for simplicity, we can consider all values in the vector as 1. My function so far is this:
% Lambda needs to contain all the values for each value of t.
function integral = lamb(s,om,mu,AT)
t = max(s)+1:numel(AT);
for ti = 1:numel(t)
fun1 = @(x) om.^abs(x-s).*AT(t(ti)-x); % Numerator
q = @(x) integral(fun1,0,t(ti)); % Integral of the numerator
fun2 = @(x) om.^abs(x-s); % Denominator
p = @(x) integral(fun2,0,t(ti)); % Integral of the denominator
lambda = mu + q/p; % Function seen in pdf
end
I run this function using this script:
% Here I would load AT but for simplicity let it be vector of 1's.
s = 0:60; % lag range
om = 0.1:0.1:1; % decay rate range
mu = 1:10; % baseline rate range
Ns = numel(s);
Nom = numel(om);
Nmu = numel(mu);
nll = nan(Ns,Nom,Nmu);
for si = 1:Ns
omi = 1:Nom;
mui = 1:Nmu;
integral(si,omi,mui) = lamb(s(si),om(omi),mu(mui),AT);
end
I end up with the error:
Error using /
Arguments must be numeric, char, or logical.
% This error is for the final line in the for loop in the function.
If anyone could help me with this function it would be much appreciated, thank you.
0 件のコメント
採用された回答
David Goodmanson
2021 年 7 月 29 日
編集済み: David Goodmanson
2021 年 7 月 29 日
Hello LT,
fun1 = @(x) x.^2
q1 = @(x) integral(fun1,0,4)
q2 = integral(fun1,0,4)
q1 = function_handle with value:
@(x)integral(fun1,0,4)
q2 = 21.3333
I assume that you want a numerical result for q, but the extra @(x) creates a function handle instead.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Numerical Integration and Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!