簡體   English   中英

MATLAB:我正在嘗試 plot 向量的表面表示 function 但使用 * 符號相乘時出現錯誤

[英]MATLAB: I am trying to plot the surface representation of a vector function but I get an error for using the * symbol to multiply

我想要 plot 一個球面坐標的表面:

% Define tensor components
sigma11 = 20;
sigma22 = 10;
sigma33 = 10;
sigma23 = -40;
sigma13 = 0;
sigma12 = 0;
sigma32 = sigma23;
sigma31 = sigma13;
sigma21 = sigma12;

% Set ranges for theta and phi
phi = 0:0.01:360;
theta = 0:0.01:180;

% Define sigma_n
sigma_n = sigma11 * cosd(theta).^2 * sind(phi).^2 + 2 * sigma12 * sind(phi).^2 * cosd(theta) * sind(theta) + 2 * sigma13 * cosd(phi) * cosd(theta) * sind(phi) + sigma22 * sind(theta).^2 * sind(phi).^2 + 2 * sigma23 * cosd(phi) * sind(theta) * sind(phi) + sigma33 * cosd(phi).^2;

% Define spherical coordinates
x_n = abs(sigma_n).* cosd(theta) * sind(phi);
y_n = abs(sigma_n).* sind(theta) * sind(phi);
z_n = abs(sigma_n).* cosd(phi);

index_pos = (sigma_n >= 0);
index_neg = (sigma_n < 0);

% Plot positive values and negative values in different colors
surf(x_n(index_pos), y_n(index_pos), z_n(index_pos));
hold on;
surf(x_n(index_neg), y_n(index_neg), z_n(index_neg));

可能還有其他錯誤,但我什至無法檢查,因為我立即收到以下錯誤:

Error using  * 
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To operate on each element of the
matrix individually, use TIMES (.*) for elementwise multiplication.

Error in extratask1 (line 14)
sigma_n = sigma11 * cosd(theta).^2 * sind(phi).^2 + 2 * sigma12 * sind(phi).^2 * cosd(theta) * sind(theta) + 2 * sigma13 * cosd(phi) * cosd(theta) * sind(phi) + sigma22 * sind(theta).^2 * sind(phi).^2 + 2 * sigma23 * cosd(phi) * sind(theta) * sind(phi) + sigma33 * cosd(phi).^2;

我無法修復它。

請幫忙!

我特此附上我定義為 sigma_n 的矢量 function:我正在嘗試在球坐標中使用 plot 的方程

我希望得到一個與此類似的表面 plot:我的 plot 應該看起來像這樣

*做矩陣乘法, .*做逐元素乘法。 如果要進行矩陣乘法,則兩個矩陣的內部維數必須匹配。 檢查你對sigma_n的定義並決定你想在哪里做矩陣以及在哪里進行元素乘法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM