필터 지우기
필터 지우기

compute force matrix from positions matrix

조회 수: 3 (최근 30일)
Diego Soler Polo
Diego Soler Polo 2016년 3월 24일
답변: Jos (10584) 2016년 3월 25일
Hi,
I have the following problem. I want to create a function which takes as inputs a 1XN vector of masses and a Nx3 matrix of positions. The k-th row is the coordinates (x,y,z) of the k-th particle. The function should output a Nx3 matrix where the k-th row consists of the cartesian coordinates of the total gravitational force exerted upon the k-th particle.
This is very easy to achive by using loops in the function, but I was wondering whether there is some brief and more eficient way to do this without using any iteration loops.
Thank you for your help!

답변 (1개)

Jos (10584)
Jos (10584) 2016년 3월 25일
There surely is way to vectorise your code, using bsxfun, accumarray and/or arrayfun, for instance. However, this most likely to make your code less efficient and readable.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by