Function handle, integral respect.

I have function u(x)=integral exp(5*i*abs(x-y))*(-1-2*sinh(y))*exp(i*5*y)dy y=0..2,when x=0..2,and I try to find her
for x=0:0.01:2
N=N+1;
syms f(x,y)
f(x,y)=exp(5*i*abs(x-y))*(-1-2*sinh(y))*exp(i*5*y);
f2=integral(f,0,2);
u(N)=integral(f2,0,2);
end
What wrong?

4 件のコメント

Adam
Adam 2017 年 4 月 24 日
I don't know. What is wrong? Are you getting an error? Incorrect result?
Opera Era
Opera Era 2017 年 4 月 24 日
I have error: First input argument must be a function handle.
Opera Era
Opera Era 2017 年 4 月 24 日
Modified to this:
syms x y
f=int(exp(5*i*abs(x-y))*(-1-2*sinh(y))*exp(i*5*y),y);
f2=vpa(subs(f,y,2))-vpa(subs(f,y,0));
u(N)=vpa(subs(f,x,k));
but get error
Steven Lord
Steven Lord 2017 年 4 月 24 日
And the full text of the error message ( EVERYTHING in red ) that you received from your modified code is ... ?

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2017 年 4 月 24 日

0 投票

There are two main functions for integrating a function.
Use the int function from Symbolic Math Toolbox to integrate a symbolic expression.
Use the integral function from MATLAB to numerically integrate a function handle.
Trying to use int to integrate a function handle won't work.
Trying to use integral to integrate a symbolic expression won't work.
You have a symbolic expression, so int is the right tool to use.

カテゴリ

質問済み:

2017 年 4 月 24 日

コメント済み:

2017 年 4 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by