フィルターのクリア

How do I multiply two functions handles?

2 ビュー (過去 30 日間)
Tlotlo Oepeng
Tlotlo Oepeng 2022 年 6 月 14 日
コメント済み: Star Strider 2022 年 6 月 14 日
%%---------constants:
Gma_32 = 100
Gma = 210e-15
gamma_u = 500
gamma_c = 50
a = Gma_32/sqrt(2*gamma_u*Gma)
n = 4e10
c1 = -4
c2 = 2.05
c3 = 1
K = 10
%--------Function
%
% X = @(k) -4*n - a^2*n*sqrt(n) + 4*c1*k.^4 + (2*a*sqrt(n)-16*K^2 + 4*a*c1*c3*sqrt(n) + 8*n*c1*c2)*k.^2
% Sq = @(k) sqrt((-X(k) + sqrt(X(k).^2 + Y^2 ))/2)
% f = @(k) -2*k.^2 - 2*n - a*sqrt(n) + Sq(k)
% f2 = @(k) -2*k.^2 - 2*n - a*sqrt(n) - Sq(k)
%------------------------------Fns:
b_i = @(k) -4*c1*k*K
b_r = @(k) 2*k.^2 +2*n + a*sqrt(n)
c_i = @(k) ( 4*n*c2* - 2*(2*n + a*sqrt(n))*c1 + 2*a*sqrt(n)*c3 )*K*k
c_r = @(k) -(1 + c1^2)*k.^4 - (2*n -4*(1 + c1^2)*K^2 + sqrt(n)*c3*c1 + 2*n*c1*c2 )*k.^2
D_r = @(k) b_r(k).^2 - b_i(k).^2 -4*c_r(k)
D_i = @(k) 2*b_i(k).*b_r(k) - 4*c_i
f = @(k) -b_i(k) + sqrt( -D_r(k) + sqrt(D_i(k)^2 + D_r(k)^2))/4
%-------Grid:
k = -200:0.1:200
% %-------Plot
%
plot(k,f(k))
%plot(k,f2(k))
theres an error on line with function f, how do i multiply two functoin handles. or suggest a bwtter way of plotting this function.
  1 件のコメント
Steven Lord
Steven Lord 2022 年 6 月 14 日
FYI for the future, when you're asking for help with code that throws an error message or issues a warning message please include the full and exact text of the error or warning message in your original question. This information may help readers determine the cause of the error and how to correct it more quickly. Thanks.

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

採用された回答

Star Strider
Star Strider 2022 年 6 月 14 日
In the ‘D_i’ function, ‘c_i’ was originally missing its argument, and that threw the error.
Correcting that, and vectorising the exponentiations produces —
%%---------constants:
Gma_32 = 100;
Gma = 210e-15;
gamma_u = 500;
gamma_c = 50;
a = Gma_32/sqrt(2*gamma_u*Gma);
n = 4e10;
c1 = -4;
c2 = 2.05;
c3 = 1;
K = 10;
%--------Function
%
% X = @(k) -4*n - a^2*n*sqrt(n) + 4*c1*k.^4 + (2*a*sqrt(n)-16*K^2 + 4*a*c1*c3*sqrt(n) + 8*n*c1*c2)*k.^2
% Sq = @(k) sqrt((-X(k) + sqrt(X(k).^2 + Y^2 ))/2)
% f = @(k) -2*k.^2 - 2*n - a*sqrt(n) + Sq(k)
% f2 = @(k) -2*k.^2 - 2*n - a*sqrt(n) - Sq(k)
%------------------------------Fns:
b_i = @(k) -4*c1*k*K;
b_r = @(k) 2*k.^2 +2*n + a*sqrt(n);
c_i = @(k) ( 4*n*c2* - 2*(2*n + a*sqrt(n))*c1 + 2*a*sqrt(n)*c3 )*K*k;
c_r = @(k) -(1 + c1^2)*k.^4 - (2*n -4*(1 + c1^2)*K^2 + sqrt(n)*c3*c1 + 2*n*c1*c2 )*k.^2;
D_r = @(k) b_r(k).^2 - b_i(k).^2 -4*c_r(k);
D_i = @(k) 2*b_i(k).*b_r(k) - 4*c_i(k);
f = @(k) -b_i(k) + sqrt( -D_r(k) + sqrt(D_i(k).^2 + D_r(k).^2))/4;
%-------Grid:
k = -200:0.1:200;
% %-------Plot
%
plot(k,f(k))
%plot(k,f2(k))
.

その他の回答 (1 件)

Tlotlo Oepeng
Tlotlo Oepeng 2022 年 6 月 14 日
thank you
  1 件のコメント
Star Strider
Star Strider 2022 年 6 月 14 日
As always, my pleasure!

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by