Matlab 中有沒有一種方法可以從向量的模數開始撰寫向量的分量?也許以隨機方式,但是這樣,通過執行反向操作,我獲得了啟動模塊
例如:
V_0 = 60 % starting modulus
也許我應該使用 for 回圈,但是如何?
uj5u.com熱心網友回復:
我假設您正在尋找一種方法,從向量的長度開始生成具有隨機方向但指定長度的向量?
我將在這里考慮幾個案例。首先,對于一個二維的實向量。這只是極坐標到直角坐標轉換的簡單應用。
v0 = 60; % Desired length
theta = 2 * pi * rand(1,1); % Random angle between 0 and 2pi
x0 = v0 * cos(theta);
y0 = v0 * sin(theta);
v = [x0 y0]; % Assemble the new vector
% Could also reduce line count by: v = v0 * [cos(theta) sin(theta)]
vLength = norm(v); % Should be the same as v0
第二種情況是如果您對具有指定模數的復數感興趣。他我們利用歐拉公式。
v0 = 60; % Desired length
theta = 2 * pi * rand(1,1); % Random angle between 0 and 2pi
v = v0 * exp(1j * theta);
vLength = abs(v); % Should be the same as v0
對于第三種情況,我將考慮任意尺寸的向量。這利用了什么是當 n 很大時在 n 球上找到隨機點的好方法中的一種技術?
v0 = 60; % Desired length
N = 7; % Number of dimensions
rndVector = randn(1, N); % Random, Gaussian, vector with N elements
rndVectorNorm = rndVector / norm(rndVector); % Normalized to unit length
v = v0 * rndVectorNorm; % Scale to desired length
vLength = norm(v); % Should be the same as v0
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/531276.html
標籤:matlab向量成分模数
