How to properly create function for integration?

3 ビュー (過去 30 日間)
KG573
KG573 2021 年 9 月 19 日
コメント済み: Star Strider 2021 年 9 月 21 日
Hi i'm trying to create functions that I can then use to compute a definite integral, here are the functions:
\\
Integral I'm trying to compute:
The Error i'm getting:
My Attempt:
syms theta_func
z_func = @(theta_func) exp(1i*pi*cos(theta_func));
E_func = @(theta_func) sin(theta_func).*(z_func(theta_func)-1).*((z_func(theta_func).^3)-1);
E_func = @(theta_func) abs(E_func(theta_func))^2;
expr = @(theta_func) E_func(theta_func).*sin(theta_func);
q = 2*pi*int(expr,theta,0,pi);
  1 件のコメント
Jan
Jan 2021 年 9 月 20 日
Prefer to post code as text, not as screenshot.
You show your apporach. Does it work? We cannot try this by our own, because it is a screenshot only. Most of the readers will not take the time to type this code again, most of all because it is not clear, how this code is related to your question.

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

回答 (1 件)

Star Strider
Star Strider 2021 年 9 月 20 日
There are several problems with the posted code image.
First, ‘z’ is not defined anywhere, and it is not an argument to ‘E_func’, and the second ‘E_func’ line should be:
E_func = @(theta_func) abs(E_func(theta_func)).^2;
It may also not be necessary to use the Symbolic Math Toolbox for this, anyway.
.
  3 件のコメント
KG573
KG573 2021 年 9 月 21 日
I also updated the question and showed the error I was getting
Star Strider
Star Strider 2021 年 9 月 21 日
The way the code is written means that the Symbolic Math Toolbox functions are not appropriate.
Try this —
z_func = @(theta_func) exp(1i*pi*cos(theta_func));
E_func = @(theta_func) sin(theta_func).*(z_func(theta_func)-1).*((z_func(theta_func).^3)-1);
E_func = @(theta_func) abs(E_func(theta_func)).^2;
expr = @(theta_func) E_func(theta_func).*sin(theta_func);
q = 2*pi*integral(expr,0,pi) % Use 'integral' For Numeric Integration
q = 20.6011
.

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

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by