how to calculate a serie of a function with two variables

조회 수: 2 (최근 30일)
Omidreza Ghafarinejad
Omidreza Ghafarinejad 2015년 2월 22일
댓글: Torsten 2022년 3월 29일
hi everybody. i want to calculate the sum of a serie that has a function which has two variables named 'xi' and 'eta'. 'xi' and 'eta' are the coordinates of 4 points. for example i want to calculate the sum of the serie from point 1 to point 4 and in each point 'xi' and 'eta' has a specific value. can anyone help me how to write the code??

답변 (4개)

dpb
dpb 2015년 2월 22일
xi=[list of four values];
eta=[list of four more presumably different values];
func=yourfunction(xi,eta); % compute the function
sumFunc=cumsum(func);
  댓글 수: 2
Omidreza Ghafarinejad
Omidreza Ghafarinejad 2015년 2월 22일
thanks but it didn't work.
dpb
dpb 2015년 2월 22일
How do we Know that? You didn't show any more of your work than your original question... :(

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


Shoaibur Rahman
Shoaibur Rahman 2015년 2월 22일
% xi eta
x =[1 2;...
3 4;...
4 5;...
6 7];
y = sum(x) % only sum of all elements along each column
y = cumsum(x) % cumulative sum along each column

Image Analyst
Image Analyst 2015년 2월 22일
Be more specific. Why can't you give us the series? Is it homework or something? If you don't get more specific then you'll just get more answers like dpb's (which is all your fault rather than dpb's because you were not specific enough to be able to answer your question).
What's wrong with using the sum() function, or even a brute force for loop()?
  댓글 수: 2
Omidreza Ghafarinejad
Omidreza Ghafarinejad 2015년 2월 22일
편집: Omidreza Ghafarinejad 2015년 2월 22일
ok i try to describe more. yes it is my homework in finite element. i am trying to write a code that meshes a 2d shape with quadrilateral elements. i have 4 functions named shape functions. these functions has two variable "xi" and "eta". you can assume x and y, it doesn't matter. the xi and eta are the coordinates of 4 points. it means that each shape function should be calculated in these 4 points. but i can not assign values to xi and eta until i do some calculations on these shape functions and obtain a final function that is also a function of xi and eta. at last i reach a matrix named j(n,m,z). For obtaining each element of this matrix, i should calculate the sum of that final function in those 4 points.also i should mention the final function is f(n,m,z) that has two variables xi and eta. i tries my best to explain it to you. sorry
Image Analyst
Image Analyst 2015년 2월 22일
If you want to sum a 3D matrix "j" between certain rows and columns, do this
subArray = j(row1:row2, col1:col2, :);
theSum = sum(subArray(:));

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


Omidreza Ghafarinejad
Omidreza Ghafarinejad 2015년 2월 24일
thanks people for your responces. i solved the problem. i used "subs" to assign values to my two variables in a loop.
  댓글 수: 2
Charu Yadav
Charu Yadav 2022년 3월 29일
I am facing the same problem. Can you help me?
Torsten
Torsten 2022년 3월 29일
Nobody will work through all the contributions to see what "the same problem" is.
Open a new question.

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

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by