'integral' with piecewise expressions
조회 수: 11 (최근 30일)
이전 댓글 표시
I have the following expression for the angle Beta:
L = 1;
syms y
Beta = piecewise(0<=y<L/2, pi/2, ...
L/2 <=y <L*(3/4),pi/2+0.3491, ...
(3/4)*L <=y <=L,pi/2-0.3491);
i want to compute this integral:
a = pi/4;
fun_f=@(y) (1./(50*(1+y)*(cos(a)*cos(Beta)+sin(a)*sin(Beta))+470));
int= integral(fun_f,0,L)
Does anybody know how to calculate the integral with using integral, but with Beta defined as a piecewise function?
I looked for documentation for piecewise but I don't really know if it's needed to use it. I'd prefer not to.
If you need further information i'll be happy to provide it in order to solve my problem
댓글 수: 0
채택된 답변
Torsten
2023년 1월 13일
편집: Torsten
2023년 1월 13일
L = 1;
Beta = @(y,L) pi/2.*((0<=y) & (y<L/2)) + (pi/2+0.3491).*((L/2<=y) & (y<3/4*L)) + (pi/2-0.3491).*((3/4*L<=y) & (y<=L));
figure(1)
plot((0:0.01:L),Beta(0:0.01:L,L))
a = pi/4;
fun_f=@(y,L) (1./(50*(1+y).*(cos(a)*cos(Beta(y,L))+sin(a)*sin(Beta(y,L)))+470));
figure(2)
plot((0:0.01:L),fun_f(0:0.01:L,L))
format long
int_value= integral(@(y)fun_f(y,L),0,L)
int_value_improved = integral(@(y)fun_f(y,L),0,L/2) + integral(@(y)fun_f(y,L),L/2,3*L/4) + integral(@(y)fun_f(y,L),3/4*L,L)
댓글 수: 5
Torsten
2023년 1월 14일
편집: Torsten
2023년 1월 14일
I doubt that Beta is what you want since the result is of type "logical".
What function do you want to use (in a mathematical notation) ?
But if you think everything is as wanted - here is the result:
LATO = 1;
intersezione_34LATO= (3/4)*LATO;
i = 1;
p = [0.125000000000000 0];
L_AB= 0.625000000000000;
alpha_1 = pi/2;
Beta = @(l,p,alpha_1,LATO) (pi/2+0.3491).*(LATO/2<=(p(i,1)+l.*sin(alpha_1(i)))) & ((p(i,2)+l.*sin(alpha_1(i)) <intersezione_34LATO)) + (pi/2-0.3491).*(intersezione_34LATO<=(p(i,2)+l.*sin(alpha_1(i)))) & ((p(i,2)+l.*sin(alpha_1(i))<= LATO));
fun_f=@(l) (1./(cos(double(Beta(l,p,alpha_1,LATO)))));
l=0:0.01:L_AB;
plot(l,fun_f(l))
tau_f(i) = integral(@(l)fun_f(l),0,L_AB(i))%,'AbsTol',0,'RelTol',1e-20,'ArrayValued',false)
추가 답변 (1개)
Walter Roberson
2023년 1월 14일
Use matlabFunction with the piecewise expression, giving the 'file' option and 'optimize' false. And when you integral specify 'arrayvalued' true
matlabFunction can convert piecewise to if/else but only when writing to file, and the result cannot accept vectors
댓글 수: 2
Walter Roberson
2023년 1월 14일
format long g
L = 1;
syms y
Pi = sym(pi);
Beta = piecewise(0<=y<L/2, Pi/2, ...
L/2 <= y < L*(3/4), Pi/2 + sym(3491)/10^4, ...
(3/4)*L <= y <=L, Pi/2 - sym(3491)/10^4);
a = Pi/4;
fun_f = (1./(50*(1+y)*(cos(a)*cos(Beta)+sin(a)*sin(Beta))+470))
result_symbolic = int(fun_f, y, 0, L)
result_vpa = vpa(result_symbolic, 16)
fun_f_h = matlabFunction(fun_f, 'vars', y, 'File', 'fun_f.m', 'optimize', false)
result_numeric = integral(fun_f_h, 0, L, 'arrayvalued', true)
dbtype fun_f.m
참고 항목
카테고리
Help Center 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




