Integration of piecewise function with integral

Hi, I have piecewise function J(t,m).
function [j] = functionJ (t,m)
model = @(t) -(0.0008.*m./(-0.01-0.07.*exp(-2.*t))-0.000112.*m.*t.*exp(-2.*t)./(-0.01-0.07.*exp(-2.*t)).^2).*exp(0.0008.*m.*t./(-0.01-0.07.*exp(-2.*t)));
j = (t<20).*((1/20)*integral(model,0,t)) + (t>=20).*((1/20)*integral(model,(t-20),t)); end
Now I need another function R(x,m) to integrate J in respect to t from 0 to x I'm still new with Matlab. Could you please give me hint how to do that?

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2013년 5월 6일
편집: Andrei Bobrov 2013년 5월 7일

0 개 추천

function J = R(f,x,m)
t = x >= 20;
p = zeros(numel(x),1);
p(t) = x(t) - 20;
J = arrayfun(@(x,y)integral(@(t)f(t,m),y,x),x,p);
eg use:
f = @(t,m) -(0.0008.*m./(-0.01-0.07.*exp(-2.*t))-0.000112.*m.*t.*exp(-2.*t)./...
(-0.01-0.07.*exp(-2.*t)).^2).*exp(0.0008.*m.*t./(-0.01-0.07.*exp(-2.*t)));
m = 1;
x = randi(40,20,1);%eg
out = R(f,x,m)
OR
function J = R(x,m)
t = x >= 20;
p = zeros(numel(x),1);
p(t) = x(t) - 20;
f = @(t,m) -(0.0008.*m./(-0.01-0.07.*exp(-2.*t))-0.000112.*m.*t.*exp(-2.*t)./...
(-0.01-0.07.*exp(-2.*t)).^2).*exp(0.0008.*m.*t./(-0.01-0.07.*exp(-2.*t)));
J = arrayfun(@(x,y)integral(@(t)f(t,m),y,x),x,p);
ADD
function J = pwint(x,m)
f = @(t,m) -(0.0008.*m./(-0.01-0.07.*exp(-2.*t))-0.000112.*m.*t.*exp(-2.*t)./...
(-0.01-0.07.*exp(-2.*t)).^2).*exp(0.0008.*m.*t./(-0.01-0.07.*exp(-2.*t)));
t = x >= 20;
p = zeros(numel(x),1);
p(t) = x(t) - 20;
J = arrayfun(@(x,y)integral(@(t)f(t,m),y,x),x,p);
eg use:
R = @(x,m)arrayfun(@(t)integral(@(x)pwint(x,m),0,t,'ArrayValued',true),x);
m = 1;
out = R([30,15],m);

댓글 수: 2

Lukas
Lukas 2013년 5월 6일
Thank you for the answer. But this gives me the same result as function J(t,m). I need to integrate J(t,m).
Please, see ADD part in my answer.

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

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

질문:

2013년 5월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by