How do I define this integral function?

1 view (last 30 days)
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.

Accepted Answer

David Goodmanson
David Goodmanson on 29 Jul 2021
Edited: David Goodmanson on 29 Jul 2021
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.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!