Using vectors to all points on a meshgrid

I have a meshgrid across x y and z and need to produce vectors from the origin to all points in the meshgrid that can be used in an potential equation to find the potential at each point as from the origin. How would I go about doing this?
[X Y Z] = meshgrid((-4.05:0.1:4.05),(-4.05:0.1:4.05),(-4:0.1:4))

5 件のコメント

jonas
jonas 2018 年 11 月 10 日
What do you mean vectors? X Y Z already have the coordinates for each point and the other point is obviously [0 0 0]. What is the desired format?
James
James 2018 年 11 月 10 日
I am using an equation that has vector r in to find the potential. I am trying to use this equation for all values of the vector r from [0 0 0] so I can essentially have a array containing all values of potential for each point.
James
James 2018 年 11 月 10 日
編集済み: madhan ravi 2018 年 11 月 10 日
Adding on sorry, the problem I am having is that I dont know how to have this vector go across all values.
k*(dot(p,R))./rpo.^2 - k*(dot(p,R))./rne.^2;
The only bit I need help with is R, how do I define R so that is goes across all values?
Walter Roberson
Walter Roberson 2018 年 11 月 10 日
dot() as a call does not vectorize. For real valued vectors, dot = sum(x.*y) which can be extended to arrays if you are careful about shapes and directions and replication. In some cases you can use the * operator after having arranged the right orientation.
Bruno Luong
Bruno Luong 2018 年 11 月 10 日
"dot() as a call does not vectorize."
Not true:
>> y=rand(3,4)
y =
0.751267059305653 0.699076722656686 0.547215529963803 0.257508254123736
0.255095115459269 0.890903252535798 0.138624442828679 0.840717255983663
0.505957051665142 0.959291425205444 0.149294005559057 0.254282178971531
>> x=rand(size(y))
x =
0.814284826068816 0.349983765984809 0.616044676146639 0.830828627896291
0.243524968724989 0.196595250431208 0.473288848902729 0.585264091152724
0.929263623187228 0.251083857976031 0.351659507062997 0.549723608291140
>> dot(x,y)
ans =
1.144034879739528 0.660675444113866 0.455219273317489 0.845771767133647

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2018 年 11 月 10 日

コメント済み:

2018 年 11 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by