Raising a matrix to a power

40 ビュー (過去 30 日間)
Nathan Stawasz
Nathan Stawasz 2019 年 9 月 7 日
コメント済み: Walter Roberson 2019 年 9 月 10 日
I want to raise the Tr value to the power of 1/2. I keep getting the same error. Screen Shot 2019-09-07 at 6.53.10 PM.png

回答 (2 件)

Guillaume
Guillaume 2019 年 9 月 7 日
The problem is not the .^0.5, it's the ^2, which probably should be .^2. Note that x.^0.5 is the same as sqrt(x).
However, If Tr is a matrix, then it's unlikely that alpha(Tr) is a valid target for assignment.
  4 件のコメント
madhan ravi
madhan ravi 2019 年 9 月 9 日
Also note don’t name variable in the name of MATLAB’s inbuilt function. alpha() is an inbuilt function.
Guillaume
Guillaume 2019 年 9 月 9 日
Yes, as said, the current error is trivially fixed by replacing ^2 by .^2. As for the alpha(Tr) =, it's not clear what you intended to do with that.

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


Bruno Luong
Bruno Luong 2019 年 9 月 9 日
% This script will generate a plot of pressure P (in bar) as a function of molar
% volume V (in cm^3/mol) for various values of temperature T (in K) for
% ethylene as described by the Peng-Robinso n equation of state.
T=[260;270;280;282.4;290;300;310];
V=[50:400];
R= 83.14; % cm^3bar/mol K
Tc= 282.4; %K
Tr= T./Tc;
a= 5.001*10^6;% barcm^6/mol^2
b= 36.24; % cm^3/mol
k= 0.5098;
alpha = (1+k*(1-((Tr).^0.5)).^2);
P= (((R*T)./(V-b))- (a*alpha)./((V.^2)+((2*b*V)-b.^2 ))) ;
surf(V,alpha,P)
  7 件のコメント
madhan ravi
madhan ravi 2019 年 9 月 10 日
編集済み: madhan ravi 2019 年 9 月 10 日
The comment wasn’t meant to you , it was meant for the OP who reads it, if you took it that way then I apologise. As I said earlier it is not a problem for you but for others it might.

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

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by