matlab - Solving a double integral equation for a third variable -


i've been trying solve double integral equation third variable in matlab.

an example:

at first, tried solve symbolically (when k=1) below:

syms x y h f = @(x,y,h) 2*x*y+4*h;  f = @(x) x/2; solve(int(int(f(x,y,h)*f(x),x,0,3)*f(y),y,0,1)-3, h) 

the code gives right answer, i.e. h=2/3 when k=1.

for real problem, however, functions f , f more complex. , when applied same code above complex f , f, matlab not solve in appropriate time. not know if ever solves - have let code run 30 mins , forced terminate. i'll have pursue further route now, i'm trying solve numerically. code below have tried:

f = @(x,y,h) 2.*x.*y+4.*h;  f = @(x) x./2; g1 = @(y,h) integral(@(x) f(x,y,h).*f(x),0,3) g2 = @(h) integral(@(y) g1(y,h).*f(y),0,1)-3 bsolve = fsolve(g2,0) 

why code give me wrong answer of 0.5833?

from documentation integral:

for scalar-valued problems function y = fun(x) must accept vector argument x , return vector result y, integrand function evaluated @ each element of x. array-valued problems (see 'arrayvalued' option below) fun must accept scalar , return array of values.

because you're nesting calls integral, outer integral passing vectors inner call. fix this, inner integral, g1 must configured operate on scalars:

g1 = @(y,h)integral(@(x)f1(x,y,h).*f1(x),0,3,'arrayvalued',true) 

the code return 2/3 in floating point. should use fzero instead of fsolve univariate root-finding problem.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -