I need to find out the integral of some function Let's say f(x).*sin(x). I define a function handle y=@(x)f(x); Now I want to define another function handle z as z = @(x)y.*sin(x) so that I can integrate: int = integral(z,x1,x2). Matlab does not allow me to do this. Is there a way so I can define the function separately and then define the function handle for the integrand?
MATLAB: Use a function handle inside another function handle
function handleintegration
Related Solutions
The @ operator creates a function handle. An anonymous function is already a function handle. Consider:
integral(@sin, 0, pi/2) % @ creates a temporary function handle to the sin function
f = @sin;integral(f, 0, pi/2) % The same as the above, just split across two lines using an intermediate variable
integral(@(x) sin(x), 0, pi/2) % The same as the above, just using an anonymous function
Hi
The problem is not in solving
x = 0:0.8:pi;A = sin(x).^(1/3)B = cos(x).^(1/3)
the operator
.^
solves for either real or complex.
The problem lays in the fact that surf doesn't take in complex values.
To solve the long expression of H, since you are dealing with complex numbers, you have to plot 2 surfs, not one: Real and Imaginary, or Modulus and Phase
clctheta5=[0:0.1:pi];theta4=[0:0.1:pi];[X,Y]=meshgrid(theta4,theta5);H=(((((cos(Y).^2-cos(X).^2-sin(X).^2+cos(X).^2.*sin(Y).^2+sin(X).^2.*sin(Y).^2).*(cos(X).^2.*cos(Y).^2-cos(X).^2*sin(X).^2+cos(Y).^2.*sin(X).^2+cos(X).^2.*cos(Y).^4.*sin(X).^2+2*cos(X).^2.*sin(X).^2.*sin(Y).^2-cos(Y).^2.*sin(X).^2.*sin(Y).^2-cos(X).^2.*sin(X).^2.*sin(Y).^4))./6+(cos(Y).^2-cos(X).^2-sin(X).^2+cos(X).^2.*sin(Y).^2+sin(X).^2.*sin(Y).^2).^3./27+(cos(X).^2.*cos(Y).^2.*sin(X).^2)./2-(cos(X).^2.*cos(Y).^6.*sin(X).^2)./2-(cos(X).^2.*cos(Y).^2.*sin(X).^2.*sin(Y).^2)./2-cos(X).^2.*cos(Y).^4.*sin(X).^2.*sin(Y).^2).^2-((cos(X).^2.*cos(Y).^2)./3-(cos(X).^2.*sin(X).^2)./3+(cos(Y).^2.*sin(X).^2)./3+(cos(Y).^2-cos(X).^2-sin(X).^2+cos(X).^2.*sin(X).^2+sin(X).^2.*sin(Y).^2).^2./9+(cos(X).^2*cos(Y).^4.*sin(X).^2)./3+(2.*cos(X).^2.*sin(X).^2.*sin(Y).^2)./3-(cos(Y).^2.*sin(X).^2.*sin(Y).^2)./3-(cos(X).^2.*sin(X).^2.*sin(Y).^4)./3).^3).^(1/2)-((cos(Y).^2-cos(X).^2-sin(X).^2+cos(X).^2.*sin(Y).^2+sin(X).^2.*sin(Y).^2).*(cos(X).^2.*cos(Y).^2-cos(X).^2.*sin(X).^2+cos(Y).^2.*sin(X).^2+cos(X).^2.*cos(Y).^4.*sin(X).^2+2.*cos(X).^2.*sin(X).^2.*sin(Y).^2-cos(Y).^2.*sin(X).^2.*sin(Y).^2-cos(X).^2.*sin(X).^2.*sin(Y).^4))./6-(cos(Y).^2-cos(X).^2-sin(X).^2+cos(X).^2.*sin(Y).^2+sin(X).^2.*sin(Y).^2).^3./27-(cos(X).^2.*cos(Y).^2.*sin(X).^2)./2+(cos(X).^2.*cos(Y).^6.*sin(X).^2)./2+(cos(X).^2.*cos(Y).^2.*sin(X).^2.*sin(Y).^2)./2+cos(X).^2.*cos(Y).^4.*sin(X).^2.*sin(Y).^2).^(1/3)+cos(X).^2./3-cos(Y).^2./3+sin(X).^2./3+((cos(X).^2.*cos(Y).^2)./3-(cos(X).^2.*sin(X).^2)./3+(cos(Y).^2.*sin(X).^2)./3+(cos(Y).^2-cos(X).^2-sin(X).^2+cos(X).^2.*sin(Y).^2+sin(X).^2.*sin(Y).^2).^2./9+(cos(X).^2.*cos(Y).^4.*sin(X).^2)./3+(2*cos(X).^2.*sin(X).^2.*sin(Y).^2)./3-(cos(Y).^2.*sin(X).^2.*sin(Y).^2)./3-(cos(X).^2.*sin(X).^2.*sin(Y).^4)./3)./(((((cos(Y).^2-cos(X).^2-sin(X).^2+cos(X).^2.*sin(Y).^2+sin(X).^2.*sin(Y).^2).*(cos(X).^2.*cos(Y).^2-cos(X).^2.*sin(X).^2+cos(Y).^2.*sin(X).^2+cos(X).^2.*cos(Y).^4.*sin(X).^2+2.*cos(X).^2.*sin(X).^2.*sin(Y).^2-cos(Y).^2.*sin(X).^2.*sin(X).^2-cos(X).^2.*sin(X).^2.*sin(Y).^4))./6+(cos(Y).^2-cos(X).^2-sin(X).^2+cos(X).^2.*sin(Y).^2+sin(X).^2.*sin(Y).^2).^3./27+(cos(X).^2.*cos(Y).^2.*sin(X).^2)./2-(cos(X).^2.*cos(Y).^6.*sin(X).^2)./2-(cos(X).^2.*cos(Y).^2.*sin(X).^2.*sin(Y).^2)./2-cos(X).^2.*cos(Y).^4.*sin(X).^2.*sin(Y).^2).^2-((cos(X).^2.*cos(Y).^2)./3-(cos(X).^2.*sin(X).^2)./3+(cos(Y).^2.*sin(X).^2)./3+(cos(Y).^2-cos(X).^2-sin(X).^2+cos(X).^2.*sin(Y).^2+sin(X).^2.*sin(Y).^2).^2./9+(cos(X).^2.*cos(Y).^4.*sin(X).^2)./3+(2.*cos(X).^2.*sin(X).^2.*sin(Y).^2)./3-(cos(Y).^2.*sin(X).^2.*sin(Y).^2)./3-(cos(X).^2.*sin(X).^2.*sin(Y).^4)./3).^3).^(1/2)-((cos(Y).^2-cos(X).^2-sin(X).^2+cos(X).^2.*sin(Y).^2+sin(X).^2.*sin(Y).^2).*(cos(X).^2.*cos(Y).^2-cos(X).^2.*sin(X).^2+cos(Y).^2.*sin(X)^2+cos(X).^2.*cos(Y).^4.*sin(X).^2+2.*cos(X).^2.*sin(X).^2.*sin(Y).^2-cos(Y).^2.*sin(X).^2.*sin(Y).^2-cos(X).^2.*sin(X).^2.*sin(Y).^4))./6-(cos(Y).^2-cos(X).^2-sin(X).^2+cos(X).^2.*sin(Y).^2+sin(X).^2.*sin(Y).^2).^3./27-(cos(X).^2.*cos(Y).^2.*sin(X).^2)./2+(cos(X).^2.*cos(Y).^6.*sin(X).^2)./2+(cos(X).^2.*cos(Y).^2.*sin(X).^2.*sin(Y).^2)./2+cos(X).^2.*cos(Y).^4.*sin(X).^2.*sin(Y).^2).^(1/3)-(cos(X).^2.*sin(Y).^2)./3-(sin(X).^2.*sin(Y).^2)./3;figure(1);surf(X,Y,abs(H))figure(2);surf(X,Y,angle(H))
.
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance for time and attention
John BG
Related Question
- Subtracting two function handles
- How to generate an .stl file from a symbolically generated 3D surface
- Integration of a function of two variables in which the limits of integral on one are functions of the other
- How to speed up evaluation of symbolic expression to numerical values for large number of evaluations
- How to make a function handle of another function handle
- How to transform this handle into a string
Best Answer