why am i getting this errror "Index exceeds matrix dimensions"
1 view (last 30 days)
Show older comments
Ahmed Saleem
on 31 Dec 2020
Commented: Ahmed Saleem
on 3 Jan 2021
% Following is a function which performs Dew T calculation for
% Water-Ethanol system using Raoults LAw
% Similar Method can be followed for Modified Raoults Law and Dew P, Bubble
% P, Bubble T calculations
function F=system(x,a)
% Specie 1 is water and specie 2 is ethanol
%x(1) is x1
%x(2) is x2
%x(3) is y1
%x(4) is y2
%x(5) is T
%x(6) is P
%x(7) is P1sat
%x(8) is P2sat
F(1)= exp(x(7))==(16.3872-((3885.70)/(x(5)+230.170)));% Water Antoine Equation
F(2)= exp(x(8))==(16.8958-((3795.17)/(x(5)+230.918))); % Ethanol Antoine Equation
F(3)= x(1)*x(7)- x(3)*x(6); % Raoiults Law for water
F(4)= x(2)*x(8)- x(4)*x(6); % Raoiults Law for Ethanol
F(5)= x(1)+x(2)-1; % fractions reation to each other
F(6)=x(3)+ x(4)-1; % fractions reation to each other
F(7)=x(6)-(200); % input of Pressure
F(8)=x(3)-a; % input of y1
% number of variables are now equal to number of equations
a=0:0.1:1;
for ct = 1:numel(a)
x0 = [0.5,0.5,0.5,0.5,273,100,200,200];
options = optimoptions('fsolve','Display','iter');
x(ct,:)= fsolve(@(x)system(x,a(ct)),x0)
end
for i=1:1:10
xvalue(1,i)=x(i,4);
yvalue(1,i)=x(i,2);
end
plot(xvalue,yvalue)
Error:
Index exceeds matrix dimensions. Error in Sample13 (line 16) F(1)= exp(x(7))==(16.3872-((3885.70)/(x(5)+230.170)));% Water Antoine Equation
0 Comments
Accepted Answer
Walter Roberson
on 31 Dec 2020
Move the function to the end of the file.
Also,
F(1)= exp(x(7))==(16.3872-((3885.70)/(x(5)+230.170)));% Water Antoine Equation
F(2)= exp(x(8))==(16.8958-((3795.17)/(x(5)+230.918))); % Ethanol Antoine Equation
Rewrite those as left side minus right side. MATLAB needs the sign information to know which direction to steer the variables.
More Answers (0)
See Also
Categories
Find more on General Physics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!