12 views (last 30 days)

This part is included in a function called myf2(w,k):

function f= myf2(w,k)

i = sqrt(-1);

fm = @(x) (1/sqrt(2*pi))* exp(-x.^2/2);

dfm = @(x) -x.*fm(x);

fun = @(x) dfm(x) / (x-w/k);

w0 = max(imag(w/k),0);

a = -10+w0*i;

b = 10+w0*i;

N = 100;

R = dfm(w/k);

x = linspace(a,b,N+1);

syms wn x

wn = sym(zeros(1, N)); % <------- Something is wrong here

f_int = int(fun, x, a, b);

A = vpa(f_int);

f = k^2 - A - 2*pi*i*R;

return

This is where I call the function:

for ix = 1:Nx

for iy = 1:Ny

z = x(ix) + I*y(iy);

tmp = myf2(z,k);

f(ix,iy) = abs(tmp);

end

end

After this I'm getting an error! Please help me out!

David Hill
on 17 Jun 2020

Do you have to perform symbolically? Does not look like the integral exists. Why not numerically?

function f= myf2(w,k)

dfm =@(x) -x.*(1/sqrt(2*pi)).* exp(-x.^2/2);

fun =@(x) -x.*(1/sqrt(2*pi)).* exp(-x.^2/2)./ (x-w/k);

w0 = max(imag(w./k),0);

a = -10+w0*1i;

b = 10+w0*1i;

R = dfm(w./k);

A = integral(fun,a,b);

f = k^2 - A - 2*pi*1i*R;

end

David Hill
on 17 Jun 2020

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/550143-the-following-error-occurred-converting-from-sym-to-double-unable-to-convert-expression-into-double#comment_902556

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/550143-the-following-error-occurred-converting-from-sym-to-double-unable-to-convert-expression-into-double#comment_902556

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/550143-the-following-error-occurred-converting-from-sym-to-double-unable-to-convert-expression-into-double#comment_902619

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/550143-the-following-error-occurred-converting-from-sym-to-double-unable-to-convert-expression-into-double#comment_902619

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/550143-the-following-error-occurred-converting-from-sym-to-double-unable-to-convert-expression-into-double#comment_903729

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/550143-the-following-error-occurred-converting-from-sym-to-double-unable-to-convert-expression-into-double#comment_903729

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/550143-the-following-error-occurred-converting-from-sym-to-double-unable-to-convert-expression-into-double#comment_904045

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/550143-the-following-error-occurred-converting-from-sym-to-double-unable-to-convert-expression-into-double#comment_904045

Sign in to comment.