'integral' with piecewise expressions
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 14 Jan 2023
1 vote
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 commentaires
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
anto
le 15 Jan 2023
Catégories
En savoir plus sur Assumptions dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




