How do I define this integral function?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
David Goodmanson
le 29 Juil 2021
Modifié(e) : David Goodmanson
le 29 Juil 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.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!