How to write summation in matlab with two variables?

조회 수: 24 (최근 30일)
Alicia
Alicia 2021년 4월 21일
편집: Alicia 2021년 4월 22일
I am having trouble transferring these formulas onto matlab. My code compiles, however, my variables are all 1x1 and 0. I'm not sure why it is not calculating these values using my data properly. Here is my code so far:
syms u(i) v(i)
ubar = (1/N)*symsum(u,i,1,N);
uprime2 = (1/N)*symsum(u-ubar,i,1,N);
vbar = (1/N)*symsum(v,i,1,N);
vprime2 = (1/N)*symsum(v-vbar,i,1,N);
uprimevprime = (1/N)*symsum((u-ubar)*(v-vbar),i,1,N);
  댓글 수: 2
Paul Hoffrichter
Paul Hoffrichter 2021년 4월 21일
편집: Paul Hoffrichter 2021년 4월 21일
Could you tell me what the last equation represents? I was a little surprised about the subscript i being used for both u and v.
Alicia
Alicia 2021년 4월 22일
Yes, u represents the 2D matrix of the u-component of the velocity on the vector grid with likely erroneous vectors replaced by NaN with units of m/s, and v represents the 2D matrix of the v-component of the velocity on the vector grid with likely erroneous vectors replaced by NaN with units of m/s

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

채택된 답변

Paul Hoffrichter
Paul Hoffrichter 2021년 4월 21일
I am new to sym, so I thought I would give this a try. Please check carefully, as I did not have time to do so. I hope you are doing this in Live Editor. Will be back in 16 hours to see if any problems.
N=4;
u = (sym('u%d',[1 N])).';
ubar = mean(u);
u_ubar = (u - ubar);
uprime2 = mean( u_ubar.^2);
v = (sym('v%d',[1 N])).';
vbar = mean(v)
v_vbar = (v - vbar)
vprime2 = mean(v_vbar.^2)
uprimevprime = mean(dot(u_ubar, v_vbar))
  댓글 수: 1
Alicia
Alicia 2021년 4월 22일
That gave me much better results, I am not receiving any 0 values anymore. Thank you for your help

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numbers and Precision에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by