How to perform symbolic integration?
52 views (last 30 days)
Show older comments
Md. Golam Zakaria
on 17 Feb 2022
Commented: Abolfazl Chaman Motlagh
on 17 Feb 2022
I am trying to perform symbolic integration of a complex equation. The code is given below. But every time I run the code the result in the command window displays the last line. What am I doing wrong. Can anyone help me solving this?
clc
clear all
syms phi wt pi
V=((cos(wt)-cos(phi)*((sin(phi)-(phi*cos(phi))))^(1/2))*(sin(phi)));
int(V,phi,wt,pi)
2 Comments
Abolfazl Chaman Motlagh
on 17 Feb 2022
Edited: Abolfazl Chaman Motlagh
on 17 Feb 2022
can you describe what you trying to do. you want to integrate V as a function of phi with lower bound of wt and upperbound of pi ?? or you want an indefinite triple integration over V ??
Accepted Answer
Abolfazl Chaman Motlagh
on 17 Feb 2022
it doesn't seems your function has a clear close form primitive function. (or at least it is not easy for matlab symbolic toolbox to find it.) so it's better to find functionality from numerical integration:
v = @(x,t0) (((cos(t0)-cos(x).*((sin(x)-(x.*cos(x)))).^(1/2)).*(sin(x))));
choose the and integrate it numerically:
t0 = 0;
integral(@(x) v(x,t0),t0,pi)
or if you want functionality over lowerbound numerically solve integration over some grid points.
your function depend on starting point of integration, that's why i use this form.
t0 = 0:0.05:pi;
int_V = zeros(length(t0),1);
for i=1:length(t0)
int_V(i) = integral(@(x) v(x,t0(i)),t0(i),pi);
end
plot(t0,int_V,'linewidth',2); xlabel('\theta_o'); ylabel('F(\theta_o)')
title('F(\theta_o)=\int_{\theta_o}^{pi}V(\theta) d\theta')
finally if you need a close expression for your function, you can interpolate this function. and of course made it more precise with increasing number of grid points in t0.
2 Comments
Abolfazl Chaman Motlagh
on 17 Feb 2022
Good to hear it works.
as i said the numerical array is now close to values of integration in points that we integrate. so a simple way to find a close expression is interpolation.
remember not all functions can be integrated Indefinitely. not all functions have perimiteve function. also not all functions are easy to integrate. maybe you need to define a new functions for their integration. like a common case integration of 1/x .in these cases the the interpolation can give you a functional expression close enough to real function.
there are a lot of method for interpolation. like polynomial interpolation, or spline interpolation. or maybe more efficient in your case (because you have trigonometric functions) trigonometric interpolation.
in matlab for this task you can use curve fitting toolbox. it also has an apps.
here's what you can do:
after running above code type this:
cftool(t0,int_V); % or sftool(t0,int_V)
wait for app to show up.
in top from list of equation select your desired type, for example fourier. and then select number of terms. more terms lead to less error. but lead to more complex expression. you can save it to workspace using fit tab. it will give you the expression and it's parameters that fitts to this data:
More Answers (1)
John D'Errico
on 17 Feb 2022
Do you presume that every integral you write down has a symbolic, analytical solution? Is that perhaps really a good idea?
syms phi wt pi
V=((cos(wt)-cos(phi)*((sin(phi)-(phi*cos(phi))))^(1/2))*(sin(phi)))
In this case, I'd suggest that phi inside and out of the trig functions, and inside a square root is a problem. So when int just gives up, and displays the result as what you wanted to solve, that means it was unable to find a solution.
By the way, declaring pi as a symbolic variable there is probably a bad idea.
vpa(pi)
pi is no longer defined as the number 3.14159..., but now as just a variable named pi. And now MATLAB can now no longer use known properties of pi and how trig functions behave in concert with pi.
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!