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개)
Youssef Khmou
2013년 5월 6일
hi, try
doc quad
doc trapz
Andrei Bobrov
2013년 5월 6일
편집: Andrei Bobrov
2013년 5월 7일
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);
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!