Help with Coding problem
1 回表示 (過去 30 日間)
古いコメントを表示
I am trying to code the following in matlab.
<<
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191697/image.png)
Following is my matlab code. But this doesn't give me the right result. Can somebody point out what am I doing wrong?
function [J] = funtc(x_t,c_mn,theta,M,N )
L = length(x_t );
l = 0:L-1;
m = 0:M-1;
n = 0:N-1;
J = 0 ;
for t = 1:L
xs = 0 ;
xp = 0 ;
for j = 1: length(n)
for k = 1: length(m)
xs = xs + c_mn(k,j)*exp(-pi*(l(t)-n(j))^2/theta^2)*exp(1i*2*pi*m(k)*(l(t)- n(j))/M);
xp = xp + c_mn(k,j)*exp(-pi*(l(t)-n(j))^2/theta^2)*exp(1i*2*pi*m(k)*(l(t)- n(j))/M)*(l(t)-n(j))^2/theta^3;
end
end
J = J + ((x_t (t) -xs) * conj (xp));
end
J = real(-4*J);
end
7 件のコメント
回答 (1 件)
Abraham Boayue
2018 年 7 月 10 日
編集済み: Abraham Boayue
2018 年 7 月 10 日
Try this
function [J] = funtc(x_t,c,theta,M,N,L)
J = zeros(1,L);
for t = 1:L
xs = 0 ;
xp = 0 ;
for n = 1: N
for m = 1: M
xs = xs + c(n,m)*exp(-pi*((t-n)./theta)).^2*exp(1i*2*pi*m*(t- n)/M);
xp = xp + c(n,m)*exp(-pi*((t-n)./theta).^2)*exp(1i*2*pi*m*(t- n)/M)*(t-n)^2./theta.^3;
end
end
J = J + ((x_t (t) -xs).*conj (xp));
end
J = -4*real(J);
end
I tested this function using the mfile below.
L = 20;
N = 10;
M = 5;
c =round(10*rand(N,M));
theta0 = 0.96;
x0 = 4;
theta = 0:theta0/(L-1):theta0;
x_t = 0:x0/(L-1):x0;
J = funtc(x_t,c,theta,M,N ,L);
plot(theta,J);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!