MATLAB Answers

How do I define this integral function?

조회 수: 1(최근 30일)
Leo Tu
Leo Tu 2021년 7월 29일
댓글: Leo Tu 2021년 7월 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.

채택된 답변

David Goodmanson
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.
  댓글 수: 1
Leo Tu
Leo Tu 2021년 7월 30일
Thank you @David Goodmanson, that certainly helps!

댓글을 달려면 로그인하십시오.

추가 답변(0개)

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by