function l=LCR_CF(k,c,sigma)
%% pdf of process of various values of system parameters
for x=0:.0625:10
temp=0;
LCR=0;
ro=(x.^2/sigma);
ro=20*log10(ro);
for p=0:10
for n=0:p+1
% closed term expansion
b=nchoosek(p+(1/2),n);
% gamma term calculation
f=factorial(p);
g=(gamma(p+1))*(gamma(c));
g_ma=((ro.^(p+0.5))*(k.^c)*(2*sqrt(2*pi)))/(g*f);
% bessel function term calculation
z=2*sqrt(k*(1+ro));
K = besselk(p-n+c,z);
% Exponential term calculation
exponential=exp(-ro);
% Last term
q=(p-n+c)/2;
last_term=((k/(1+ro)).^q);
% Final pdf function
temp1= b*g_ma*K*exponential*last_term;
temp=temp+temp1;
end
LCR=LCR+temp;
end
l(1,x/(.0625)+1)=LCR;
end
THIS IS THE FUNCTION I AM TRYING TO PLOT BUT I AM GATTING AN ERROR ,""Undefined function 'LCR_CF' for input arguments of type 'double'.""
HOW CAN I SOLVE THIS?
I HAVE CALLED THIS FUNCTION BY THE FOLLOWING CODE:
clc
clear all
close all
syms x ;
%% For different values of k and c. Change the value of k and c according to figure.
sig=1;
y1=LCR_CF(0.2,1.5,sig); % Put the values of k,c,sig accordingly
y2=LCR_CF(0.5,1.5,sig);
y3=LCR_CF(1,1.5,sig);
y4=LCR_CF(1.5,1.5,sig);
y5=LCR_CF(.2,2,sig);
y6=LCR_CF(.5,2,sig);
y7=LCR_CF(1,2,sig);
y8=LCR_CF(1.5,2,sig);
%% Ploting data
x=0:0.0625:10;
figure
% plot(y1,x,'b',y2,x,'b',y3,x,'b',y4,x,'b',y5,x,'g--',...
% y6,x,'g--',y7,x,'g--',y8,x,'g--');
plot(x,y1,'b',x,y2,'b',x,y3,'b',x,y4,'b',x,y5,'g--',...
x,y6,'g--',x,y7,'g--',x,y8,'g--');
xlim([0 10]);
ylim([0 1]);
title('Normalized LCR');
xlabel('x');
ylabel('N(x)');
txt = {'Sigma=1','C=1.5, Solid Line', 'C=2, Dotted Line'};
text(6,6,txt);
txt = {'k=1.5'};
text(1,6,txt);

13 件のコメント

David Hill
David Hill 2020 年 4 月 2 日
If you want us to check it you should at least put your code in a code block with proper indenting.
Atrolita afra
Atrolita afra 2020 年 4 月 2 日
OK, MY MISTAKE
Ameer Hamza
Ameer Hamza 2020 年 4 月 2 日
We don't know the purpose of your code, whether the issue is related to an error or you think that some part of the code can be optimized. See this: https://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
Atrolita afra
Atrolita afra 2020 年 4 月 2 日
i was trying to plot an equation
Atrolita afra
Atrolita afra 2020 年 4 月 2 日
The error message is given below:
Undefined function 'LCR_CF' for input arguments of type 'double'.
Error in LCR_main (line 10)
y1=LCR_CF(0.2,1.5,sig); % Put the values of k,c,sig accordingly
Ameer Hamza
Ameer Hamza 2020 年 4 月 2 日
編集済み: Ameer Hamza 2020 年 4 月 2 日
Amrin, where have you placed the file LCR_CF.m file which contains your function code?
Atrolita afra
Atrolita afra 2020 年 4 月 2 日
in the same folder why i have placed the file LCR_main.m
Atrolita afra
Atrolita afra 2020 年 4 月 2 日
Sorry , it was on the different folder and after solving this i have got another error:
Error using +
Matrix dimensions must agree.
Error in LCR_CF (line 37)
temp=temp+temp1;
Error in LCR_main (line 10)
y1=LCR_CF(0.2,1.5,sig); % Put the values of k,c,sig accordingly
Ameer Hamza
Ameer Hamza 2020 年 4 月 2 日
yes, I could see the error in your function LCR_main. Can you describe what are you trying to do in that function. Are you implementing some equations?
Atrolita afra
Atrolita afra 2020 年 4 月 2 日
yes i was trying to plot an equation
Ameer Hamza
Ameer Hamza 2020 年 4 月 2 日
Can you attach the equation?
Atrolita afra
Atrolita afra 2020 年 4 月 2 日
Atrolita afra
Atrolita afra 2020 年 4 月 2 日
instead of infinity i was trying with 10

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

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 2 日

0 投票

I have corrected the syntax issue in your code. The MATLAB function nchoosek does not work for fractional numbers. However, Now it gives infinity at 0 and also gives complex values. I am not sure whether this is correct or wrong.
function l=LCR_CF(k,c,sigma)
%% pdf of process of various values of system parameters
nck = @(n, k) gamma(n+1)./(gamma(k+1).*gamma(n-k+1));
X = 0:.0625:10;
l = zeros(size(X));
for i=1:numel(X)
x = X(i);
temp=0;
LCR=0;
ro=(x.^2/sigma);
ro=20*log10(ro);
for p=0:10
for n=0:p+1
% closed term expansion
b=nck(p+(1/2),n);
% gamma term calculation
f=factorial(p);
g=(gamma(p+1))*(gamma(c));
g_ma=((ro.^(p+0.5))*(k.^c)*(2*sqrt(2*pi)))/(g*f);
% bessel function term calculation
z=2*sqrt(k*(1+ro));
K = besselk(p-n+c,z);
% Exponential term calculation
exponential=exp(-ro);
% Last term
q=(p-n+c)/2;
last_term=((k/(1+ro)).^q);
% Final pdf function
temp1= b*g_ma*K*exponential*last_term;
temp=temp+temp1;
end
LCR=LCR+temp;
end
l(i)=LCR;
end

3 件のコメント

Atrolita afra
Atrolita afra 2020 年 4 月 2 日
But already i have solved an equation using nchoosek.
Atrolita afra
Atrolita afra 2020 年 4 月 2 日
Oh i got your logic thanks for the infornation. though i don't know wheather it is the correct figure or not but i got that i will manage the rest !
Ameer Hamza
Ameer Hamza 2020 年 4 月 2 日
Glad to be of help. Best of luck for your project.

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

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by