'integral' with piecewise expressions
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Torsten
am 13 Jan. 2023
Bearbeitet: Torsten
am 13 Jan. 2023
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 Kommentare
Torsten
am 14 Jan. 2023
Bearbeitet: Torsten
am 14 Jan. 2023
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)
Weitere Antworten (1)
Walter Roberson
am 14 Jan. 2023
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 Kommentare
Walter Roberson
am 14 Jan. 2023
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
Siehe auch
Kategorien
Mehr zu Assumptions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!