フィルターのクリア

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

7 ビュー (過去 30 日間)
clc;clear;format compact;
syms V
P=[0.98 1.97 4.93 9.86 49.36 98.69]; %atm
T=[573 573 573 573 573 573]; %K
R=461.5; %Pa*m3/mol*K
R=convpres(R,'Pa','atm');
R=R*1000; %L*atm/mol*K
% Van der Waals
Tc=647.1;
Pc=convpres(22060000,'Pa','atm');
a1=(27*R^2*Tc^2)/(64*Pc);
b1=(R*Tc)/(8*Pc);
VW=((R*T)/(V-b1))-(a1/(V^2))==P;
for i=1:6
B(1,i)=solve(VW(i),V)
end
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in sym/privsubsasgn (line 1200)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in indexing (line 1031)
C = privsubsasgn(L,R,inds{:});

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 10 月 16 日
clc;clear;format compact;
syms V
P=[0.98 1.97 4.93 9.86 49.36 98.69]; %atm
T=[573 573 573 573 573 573]; %K
R=461.5; %Pa*m3/mol*K
R=convpres(R,'Pa','atm');
R=R*1000; %L*atm/mol*K
% Van der Waals
Tc=647.1;
Pc=convpres(22060000,'Pa','atm');
a1=(27*R^2*Tc^2)/(64*Pc);
b1=(R*Tc)/(8*Pc);
VW=((R*T)/(V-b1))-(a1/(V^2))==P
VW = 
for i=1:6
B{1,i}=solve(VW(i),V);
end
B
B = 1×6 cell array {3×1 sym} {3×1 sym} {3×1 sym} {3×1 sym} {3×1 sym} {3×1 sym}
Your equation is a cubic in V, and so it has three roots.
format long g
cell2mat(cellfun(@double, B, 'uniform', 0))
ans =
Columns 1 through 3 3.22856391464644 - 0.71413166224905i 3.23235043527525 - 0.710926542708146i 3.24382222761193 - 0.701023878142358i 3.22856391464644 + 0.71413166224905i 3.23235043527525 + 0.710926542708146i 3.24382222761193 + 0.701023878142358i 2658.31153778874 + 0i 1320.0066466243 + 0i 524.578769236741 + 0i Columns 4 through 6 3.26344891359564 - 0.683381010798684i 3.45021491277963 - 0.450133424499785i 3.11984383082587 + 0i 3.26344891359564 + 0.683381010798684i 3.45021491277963 + 0.450133424499785i 4.51149984762074 + 0i 259.852401068882 + 0i 47.6648286645631 + 0i 20.5054138525534 + 0i
Only one of the roots is real-valued -- but you asked to solve the equation, not to find real-valued solutions.
  5 件のコメント
Torsten
Torsten 2023 年 10 月 16 日
編集済み: Torsten 2023 年 10 月 17 日
clc;clear;format compact;
syms V
P=[0.98 1.97 4.93 9.86 49.36 98.69]; %atm
T=[573 573 573 573 573 573]; %K
R=461.5; %Pa*m3/mol*K
R=convpres(R,'Pa','atm');
R=R*1000; %L*atm/mol*K
% Van der Waals
Tc=647.1;
Pc=convpres(22060000,'Pa','atm');
a1=(27*R^2*Tc^2)/(64*Pc);
b1=(R*Tc)/(8*Pc);
VW=((R*T)/(V-b1))-(a1/(V^2))==P
VW = 
for i=1:6
B{1,i}=solve(VW(i),V);
end
format long g
M = cell2mat(cellfun(@double, B, 'uniform', 0))
M =
Columns 1 through 3 3.22856391464644 - 0.71413166224905i 3.23235043527525 - 0.710926542708146i 3.24382222761193 - 0.701023878142358i 3.22856391464644 + 0.71413166224905i 3.23235043527525 + 0.710926542708146i 3.24382222761193 + 0.701023878142358i 2658.31153778874 + 0i 1320.0066466243 + 0i 524.578769236741 + 0i Columns 4 through 6 3.26344891359564 - 0.683381010798684i 3.45021491277963 - 0.450133424499785i 3.11984383082587 + 0i 3.26344891359564 + 0.683381010798684i 3.45021491277963 + 0.450133424499785i 4.51149984762074 + 0i 259.852401068882 + 0i 47.6648286645631 + 0i 20.5054138525534 + 0i
for i = 1:size(M,2)
indices = find(abs(imag(M(:,i))) < 1e-6);
sol{i} = M(indices,i); % better save in cell array for the case of 3 real solutions
end
sol
sol = 1×6 cell array {[2658.31153778874]} {[1320.0066466243]} {[524.578769236741]} {[259.852401068882]} {[47.6648286645631]} {3×1 double}
Walter Roberson
Walter Roberson 2023 年 10 月 17 日
Your last P has three real-valued solutions.
clc;clear;format compact;
syms V real
P=[0.98 1.97 4.93 9.86 49.36 98.69]; %atm
T=[573 573 573 573 573 573]; %K
R=461.5; %Pa*m3/mol*K
R=convpres(R,'Pa','atm');
R=R*1000; %L*atm/mol*K
% Van der Waals
Tc=647.1;
Pc=convpres(22060000,'Pa','atm');
a1=(27*R^2*Tc^2)/(64*Pc);
b1=(R*Tc)/(8*Pc);
VW=((R*T)/(V-b1))-(a1/(V^2))==P;
for i=1:6
B{1,i} = solve(VW(i),V, 'maxdegree', 3);
end
cellfun(@double, B, 'uniform', 0)
ans = 1×6 cell array {[2.6583e+03]} {[1.3200e+03]} {[524.5788]} {[259.8524]} {[47.6648]} {3×1 double}
B{end}
ans = 
format long g
double(B{end})
ans =
20.5054138525534 - 7.21326454514511e-130i 3.11984383082587 + 3.60663227257255e-130i 4.51149984762074 + 3.60663227257255e-130i

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

カテゴリ

Help Center および File ExchangeFormula Manipulation and Simplification についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by