Integrate multivariate fuction with respect to one variable and pass the result to another function for integration.
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Shweta Rajoria
am 28 Sep. 2017
Kommentiert: Shweta Rajoria
am 28 Sep. 2017
Hi.. I a trying to evaluate the integral in matlab but not able to getting error in matlab. code is given below:
fun= @(x, y) x.*exp(-y.*x);
c= @(y)integral(@(x) fun, 0,1);
fun1= @(y) 1/2-(1/pi).*y.*c;
c1 = integral(fun1, 0,1);
Could any one can help me regard this. Any suggestions will be appreciated. Thanks in advance.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 28 Sep. 2017
Notice you have:
fun= @(x, y) x.*exp(-y.*x);
which is a function of two variables. But you try
c= @(y)integral(@(x) fun, 0,1);
which does not pass any parameters to the function. You probably intended
c= @(y)integral(@(x) fun(x), 0,1);
But notice that you are not passing y, so you would need
c= @(y) integral(@(x) fun(x, y), 0,1);
Then you have
fun1= @(y) 1/2-(1/pi).*y.*c;
c1 = integral(fun1, 0,1);
this attempts to invoke c, but c is a function handle. You have to pass a value to the handle:
fun1 = @(y) 1/2-(1/pi).*y.*c(y);
c1 = integral(fun1, 0,1);
I think that should work.
Weitere Antworten (1)
KSSV
am 28 Sep. 2017
You have to provide the value of c. Check the below code for c = 1 ;
fun= @(x, y) x.*exp(-y.*x);
c= @(y)integral(@(x) fun, 0,1);
% fun1= @(y) 1/2-(1/pi).*y.*c;
fun1= @(y) 1/2-(1/pi)*y;
c1 = integral(fun1, 0,1);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!