Which one is the correct one to calculate
1 次查看(过去 30 天)
显示 更早的评论
I tried both of those instruction to calculate as :
where and with are vectors ( zeros(15,1))
Both leads to different results, i don't know which one is the correct one , Can you hepl me ? .
R=0;
for j=1:L
s(j)=(1-q(j))/(1+q(j));
A(j)=4*sin(pi*alpha)*lamnda(j)/(pi*(1+q(j))^2);
R = R+A(j)*exp(-s(j)*dt);
end
% or
R=sum((4*sin(pi*alpha).*lambda/(pi.*(1+q)^2))*exp(-dt*(1-q)./(1+q)));
1 个评论
Jan
2021-7-1
编辑:Jan
2021-7-1
If you do not provide L, q, alpha, lamnda and dt, we cannot check your code.
Is "lamnda" a typo? In the 2nd formula it is "lambda".
"Both leads to different results" ist strange, because the 2nd fails with an error. Do you mean:
R=sum((4*sin(pi*alpha).*lambda ./ (pi.*(1+q).^2)).*exp(-dt*(1-q)./(1+q)));
% elementwise: ^ ^ ^
采纳的回答
Jan
2021-7-1
编辑:Jan
2021-7-1
R = 0;
L = 30; % Some educated guesses
q = rand(1, L);
lambda = rand(1, L);
alpha = rand;
dt = rand;
for j = 1:L
s(j) = (1 - q(j)) / (1 + q(j));
A(j) = 4 * sin(pi * alpha) * lambda(j) / (pi * (1 + q(j))^2);
R = R + A(j) * exp(-s(j) * dt);
end
R
% R2 = sum((4*sin(pi*alpha) .* lambda / ...
% (pi.*(1+q)^2)) * exp(-dt*(1-q) ./ (1+q)))
% Failing: Several operations must be made elementwise:
R2 = sum((4 * sin(pi * alpha) .* lambda ./ ...
(pi* (1 + q) .^ 2)) .* exp(-dt * (1 - q) ./ (1 + q)))
更多回答(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!