I Truly appreciate if somebody check my code. I should measure a parameter of a long vector and I have wrtten the code but my prof. says it is something wrong. I am new in MATLAB:( .Thank you.
The equation is:
RC = ½(deltaVp/averageVp + deltaRHO/averageRHO). % reflection coefficients
My code is:
for j=2:l;
r2(j)=1/2.*((v(j)-v(j-1))/(v(j)+v(j-1))+(d(j)-d(j-1))/(d(j)+d(j-1))); % reflection coefficients
end

댓글 수: 2

Bobby Fischer
Bobby Fischer 2021년 1월 14일
Hi, for the average of a vector shouldn't you use 'mean' or 'sum' and then divide by the length of the vector (number of elements)?
Maria Amr
Maria Amr 2021년 1월 14일
Thank you!

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

 채택된 답변

Walter Roberson
Walter Roberson 2021년 1월 14일

0 개 추천

Average is sum divided by two. You do not divide by two.

댓글 수: 4

Bobby Fischer
Bobby Fischer 2021년 1월 14일
편집: Bobby Fischer 2021년 1월 14일
I think the problem is, the way she has it written could be adding some (almost all) elements twice.
Walter Roberson
Walter Roberson 2021년 1월 14일
No, because sum of the result is not taken. You get a local result at each point.
Because of the way the equation is structured, the easiest way to correct the problem is to remove the leading 1/2. Each of the mean involves dividing by 2 but because you are dividing by that the effect is a multiplication by 2 when you leave out the division by two. The denominator is the sum of two terms that each have this issue, so the multiplication is in common and can be factored out. This leads to 1/2 times 2 times the + that has the divisions omitted and the 1/2 and 2 cancel. Therefore remove the 1/2 will give a mathematical correction.
Of course instead putting the divisions by 2 into the code will give you code that is easier to match to the formula...
Maria Amr
Maria Amr 2021년 1월 14일
Thank you!
Bobby Fischer
Bobby Fischer 2021년 1월 14일
Okay, now I understand.
Regards.

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

추가 답변 (0개)

카테고리

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

태그

질문:

2021년 1월 14일

댓글:

2021년 1월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by