Synthax Question for Equation

4 ビュー (過去 30 日間)
Briana Canet
Briana Canet 2022 年 3 月 17 日
回答済み: Walter Roberson 2022 年 3 月 17 日
I am trying to code out this equation: K_traction
I am not sure if I am expressing it correctly synthax wise in order to plot.
% Part A for COMP1
E_m = 70000; % Elastic modulus of matrix, MPa
v_m = .33; % Poisson ratio of matrix
E_i = 250000; % Elastic modulus of inclusion, MPa
v_i = .2; % Poisson ratio of inclusion
% Fiber volume fraction
f_i = 0:0.01:1;
% 0 is 0% fiber and 1 is 100% fiber content
% points to be plotted
K_m = (E_m)/(3*(1-2*(v_m))); % Bulk modulus of matrix, MPa
K_i = (E_i)/(3*(1-2*(v_i))); % Bulk modulus of inclusion, MPa
s1 = (1+v_m)/(3*(1+v_m));
K_traction = K_m*((1+(f_i*(((K_m)/(K_m-K_i))-s1).^-1).^-1));
K_disp = K_m*((1-(f_i*(((K_m)/(K_m-K_i))-s1)^-1).^-1));
% Plotting
plot(f_i,K_traction, 'Color', 'red', 'LineWidth', 2.5);
grid off;
title('Bulk Modulus vs. Inclusion Volume Fraction')
xlabel('Inclusion Volume Fraction, f_i')
ylabel('Bulk Modulus, K [MPa]')
  4 件のコメント
Briana Canet
Briana Canet 2022 年 3 月 17 日
My question is more with respect to I am not sure how to put the periods/dots that I know are used in MATLAB when writing equations.
Walter Roberson
Walter Roberson 2022 年 3 月 17 日
{} is not just another type of parentheses here. Parentheses do not have tailing subscripts.
does not mean the same thing as

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

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 3 月 17 日
Rules for dots:
  • The dotted versions of the operators are generally different operators than the non-dotted versions. The dotted versions are for element-by-element calculations. When using the dotted operations, the arrays must be "compatible" sizes. Arrays are "compatible" sizes if they are the same length in every non-singular dimension but dimensions that are size 1 in one of the arrays can be non-1 in the corresponding position in the other. For example a 3 x 2 can be .^ with a 1 x 2 and the 1 x 2 will be replicated to be 3 x 2 before the 3 x 2 is .^ with the (expanded to) 3 x 2.
  • In all cases, when the two operands are both scalars, the dotted operations and the non-dotted operations are the same. So 3*5 and 3.*5 are the same
  • If one of the two operands are scalar then the .* and * operations are the same. This does not generally hold true for the ^ or / or \ operations.
  • When the left operand is scalar, then the \ and .\ operations are the same. 3\[5 7] and 3.\[5 7] for example
  • When the right operand is scalar, then the / and ./ operations are the same. [5 7]/3 and [5 7]./3 for example
  • The ^ and .^ operations are never the same if either operand is non-scalar
So:
You can use constant*array or array*constant or array/constant or constant\array instead of using constant.*array or array.*constant or array./constant or constant.\array if you want.
But constant^array and constant.^array are different, and constant/array and constant./array are different, and array^constant and array.^constant are different.
array^array is never permitted for non-scalar arrays.
array*array and array/array and array\array have size constraints and are only the same as the corresponding dotted operator under some conditions.

カテゴリ

Help Center および File ExchangeElementary Math についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by