How to perform symbolic integration?
52 views (last 30 days)
Md. Golam Zakaria 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?
syms phi wt pi
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;
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);
int_V(i) = integral(@(x) v(x,t0(i)),t0(i),pi);
plot(t0,int_V,'linewidth',2); xlabel('\theta_o'); ylabel('F(\theta_o)')
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.
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
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.
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.