Integration of a function

I want to integrate fp(z) with z(0,x). I want an analytic expression.
I have done this:
f2z=@(z) 1./(z.^2+1);
fpz=@(z) f2z(z)./quadl(f2z,0,1);
--> the answer must be:4/(pi*(1 + x^2)) but it doesn't work
sol=int('fpz','z',0,'x')
y=solve('y=sol',x)
xf=@ (y) y ;
and it gives me -->
sol = fpz*x
Warning: Explicit solution could not be found.
In solve at 81
In sampling2 at 81 y = [ empty sym ] ,
(81 line is :y=solve('y=sol',x) )

답변 (2개)

Oleg Komarov
Oleg Komarov 2011년 2월 2일

0 개 추천

This is what I get:
syms z
f = 1./(z.^2+1);
sol = f./int(f,z,0,1)
sol =
4/(pi*(z^2 + 1))
Oleg

댓글 수: 1

George
George 2011년 2월 2일
Hello,
there is no problem with int(f,z,0,1).The problem is with int(f,z,0,x)

댓글을 달려면 로그인하십시오.

Walter Roberson
Walter Roberson 2011년 2월 2일

0 개 추천

sol=int('fpz(z)','z',0,'x'); %different
y = solve(subs('y=sol'),x); %different
A) You cannot use symbolic integration on a function handle.
B) When you create a variable at the Matlab level, then by default it is not known in a quoted string being passed to the MuPad level.

댓글 수: 7

George
George 2011년 2월 2일
Hello,
i tried what you said but still the same problem..In order to use symbolic integration i must create a function file?
Walter Roberson
Walter Roberson 2011년 2월 2일
I probably should have said
sym x z
sol = int(fpz(z),z,0,x);
y = solve(subs('y=sol'),x);
Though on the other hand, instead of using subs, just use
sym y
yinv = solve(sol - y,x);
xf = @(y) yinv(y);
Having y as both the name assigned to and the name to be solved for is likely to cause problems later, such as the next time through the loop.
George
George 2011년 2월 3일
The first (with y=solve(subs('y=sol'),x)) worked (with wrong result) ,because i have problem with fpz.Instead having as an exit "4/pi*(1+x^2)" it gives me the "fpz= @(z)f2z(z)./quadl(f2z,0,1)"
George
George 2011년 2월 9일
Hello ,i did "sol=int(fpz(z).*z,0,x)" but still gives me the wrong result .It must give "4*tan^-1 /pi)
Walter Roberson
Walter Roberson 2011년 2월 9일
No, with your fpz, the integral of fpz(z)*z from 0 to x is
2*ln(x^2+1)/Pi
The result you say it "must" give is obviously wrong, as you are integrating to the indefinite endpoint x but your result has no x in it.
George
George 2011년 2월 10일
Sorry,i didn't wrote it right.The result is "4*tan^-1(x)/pi".I can't figure what it's going wrong here!
T
T 2013년 2월 27일
When I attempt to integrate functions with MATLAB, I get an error when I declare the variable:
syms x Undefined function 'syms' for input arguments of type 'char'.
What's wrong?

댓글을 달려면 로그인하십시오.

질문:

2011년 2월 2일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by