So I have a Double Difference equation in the form of y = (sqrt(BR^2 - B1^2) - sqrt(BB^2 - B1^2)) - (sqrt(BR^2 - B2^2) - sqrt(BB^2 - B2^2)).......
and so on with B(i) being 901 numbers so (n1 - n2 - n3 - n4 - n5 ....... - n901)
How would I even begin to write a loop to do this so I don't have to cut and paste 901 times?
Please be patient with me my brain is so far gone, i've been at this code for about 100 hours now.
B = [X_mat_base, Y_mat_base, Z_mat_base];
BB = [xyz(1), xyz(2), xyz(3)];
BR = zeros(1, 3);
B = [X_mat_base, Y_mat_base, Z_mat_base];
for i = 1:length(BB(:, 1))
yx(i) = (sqrt(BR(1)^2 - B(i, 1).^2) - sqrt(BB(1)^2 - B(i, 1).^2));
end

답변 (2개)

Walter Roberson
Walter Roberson 2022년 3월 1일

0 개 추천

y = sqrt((BR - B).^2 + (BB - B).^2);

댓글 수: 4

Terry Poole
Terry Poole 2022년 3월 1일
but thats only the first iteration, i need it to loop through all of B,
y = sqrt((BR - B1).^2 + (BB - B1).^2) - sqrt((BR - B2).^2 + (BB - B2).^2) - sqrt((BR - B3).^2 + (BB - B3).^2) .....
- sqrt(BR- B901).^2 - (BB - B901).^2
Like this.
I'm trying something like this, and I think I'm on the right track.
B = [X_mat_base, Y_mat_base, Z_mat_base];
BB = [xyz(1), xyz(2), xyz(3)];
BR = zeros(1, 3);
for i = 1:length(BB(:, 1))
yx = (sqrt(BR(1)^2 - B(i, 1).^2) - sqrt(BB(1)^2 - B(i, 1).^2));
yx_new = yx...
- (sqrt(BR(1)^2 - B(i+1, 1).^2) - sqrt(BB(1)^2 - B(i+1, 1).^2));
yx = yx_new;
end
Walter Roberson
Walter Roberson 2022년 3월 1일
"and so on with B(i) being 901 numbers so (n1 - n2 - n3 - n4 - n5 ....... - n901)"
That implied to me that you have a single variable named B and that where you wrote B2 in your code you meant B(2) .
If you have individual variables B1, B2, B3, ... B901 then... don't .
David Hill
David Hill 2022년 3월 1일
Your signs are making no sense to me. Your question had all minus signs after the first term. I am confused as to what you want. You should be able to excute without a for-loop. Above some of your BB terms are plus and some are minus

댓글을 달려면 로그인하십시오.

David Hill
David Hill 2022년 3월 1일

0 개 추천

yx=sqrt(BR^2-B(1)^2)-sum(sqrt(BB^2-B.^2))-sum(sqrt(BR^2-B(2:end).^2));

카테고리

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

제품

릴리스

R2021b

질문:

2022년 3월 1일

댓글:

2022년 3월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by