"Matrix dimensions must agree" and "error using /"

1 次查看(过去 30 天)
%{
This program computes temperature using the ideal gas law and
Van der Waal's equation.
%}
P= linspace(0,400,10); %bar
n=2; %mol
V=1; %L
a=5.536; %L^2 bar/ mol^2
b=0.03049; %L/mol
R=0.08314472; %L bar/ K mol
% Find the temperature using the ideal gas law
T_ideal_a= (P*V)/(n*R)
% Find the temperature using Van der Waal's equation
T_VW_a= (P+(((n^2)*a)/V.^2))*(V-n*b)/(n*R)
%% b
V= linspace(0.1,10,10);%L
P= 220; %bar
% Find the temperature using the ideal gas law
T_ideal_b=(P*V)/(n*R)
% Find the temperature using Van der Waal's equation
T_VW_b= (P+(((n^2)*a)/(V.^2)))*(V-n*b)/(n*R)
Error using /
Matrix dimensions must agree.
Error in solution (line 31)
T_VW_b= (P+(((n^2)*a)/(V.^2)))*(V-n*b)/(n*R)
I'm pretty new to MATLAB, so I might have made some stupid mistakes. Please help!

采纳的回答

David Hill
David Hill 2020-5-30
% Find the temperature using Van der Waal's equation
T_VW_b= (P+(((n^2)*a)./(V.^2))).*(V-n*b)/(n*R);%since V is an array, need ./ and .* to do element-wise operations

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Oil, Gas & Petrochemical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by