%%---------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일

1 개 추천

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일

0 개 추천

thank you

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

질문:

2022년 6월 14일

댓글:

2022년 6월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by