How to plot different lengths of vectors?

1 回表示 (過去 30 日間)
asli eylul sert
asli eylul sert 2021 年 6 月 11 日
コメント済み: asli eylul sert 2021 年 6 月 12 日
Hello, I have this code
I want to plot (T vs yCO) but for some reason I have 250 values from "eqn" but 125 temperature values. So, naturally I am getting the error of different lengths. Can anyone help me?
T = 298:1:422; %Temperature Values
K1 = exp((-deltaHrxn1*1000 + T.*deltaSrxn1.*1000)./(R.*T)); %equilibrium constant for reaction 1
K2 = exp((-deltaHrxn2*1000 + T.*deltaSrxn2.*1000)./(R.*T)); %equilibrium constant for reaction 2
syms ksi1 ksi2
eqn = [(((ksi1)./(1-ksi1-ksi2))./((2-2*ksi1-ksi2)/(4-2*ksi1))^2)==K1, (((1+ksi2).*(2-2*ksi1-ksi2))./((-ksi2).*(1+ksi2)))==K2];
S = arrayfun(@(X)vpasolve(X), eqn, 'uniform', 0);
S = [S{:}];
S.ksi2; %ksi2 = 0 for all values
S.ksi1;
ksi2 = 0;
ksi1 = [S.ksi1];
yCO = ((1 - ksi1)./(4 - 2*ksi1))
  1 件のコメント
vimal kumar chawda
vimal kumar chawda 2021 年 6 月 11 日
There might be few conditions are as
1- Temp will be same although yCO still getting value and last it will be equal number.
2- you have to take equal number , which you can delete or not considering yco values.
3- Increase the interval of the temperature so that both index will be equal.
Please put the whole code it will never going to be answer in the short time like half code ?

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

採用された回答

Walter Roberson
Walter Roberson 2021 年 6 月 12 日
T = 298:1:422; %Temperature Values
That is a row vector of 125 values
K1 = exp((-deltaHrxn1*1000 + T.*deltaSrxn1.*1000)./(R.*T)); %equilibrium constant for reaction 1
That is a row vector of 125 values
K2 = exp((-deltaHrxn2*1000 + T.*deltaSrxn2.*1000)./(R.*T)); %equilibrium constant for reaction 2
That is a row vector of 125 values
syms ksi1 ksi2
eqn = [(((ksi1)./(1-ksi1-ksi2))./((2-2*ksi1-ksi2)/(4-2*ksi1))^2)==K1, (((1+ksi2).*(2-2*ksi1-ksi2))./((-ksi2).*(1+ksi2)))==K2];
Because K1 is a row vector of 125 values, the first component before the comma is a row vector of 125 values, and because K2 is a row vector of 125 values, the second component is a row vector of 125 values. You [] the two row vectors together to get a row vector of 250 values.
S = arrayfun(@(X)vpasolve(X), eqn, 'uniform', 0);
You arrayfun over the row vector of 250 values. That will cause vpasolve() to be invoked 250 times, each time being given one equation that involves two symbolic variables. vpasolve() will hunt around and find some pair of symbolic values that solves the one equation in two unknowns, and will return a struct for each one.
You need to arrange so that you vpasolve() a pair of equations at a time. For example if you had done
eqn = [(((ksi1)./(1-ksi1-ksi2))./((2-2*ksi1-ksi2)/(4-2*ksi1))^2)==K1; (((1+ksi2).*(2-2*ksi1-ksi2))./((-ksi2).*(1+ksi2)))==K2];
then now eqn would be a 2 x 125 array with the first row being the first of the equations and the second being the second of the equations. Then
arrayfun(@(COL) vpasolve(eqn(:,COL)), 1:size(eqn,2), 'uniform', 0)
  1 件のコメント
asli eylul sert
asli eylul sert 2021 年 6 月 12 日
Thank you so much. It seems to be working out. I have 2x125 array like you said. But now I have imaginary solutions and my real solutions is always between 0 and 1. How can I put this information into arrayfun so that I only get the real solutions between [0 1] ?

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

その他の回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 6 月 12 日
Check your constants, R, deltaHrxn1, deltaHrxn2,...
Note that the solutions might have two components, real and imaginary parts
deltaHrxn1 = 3;
deltaSrxn1 = 3.5;
deltaSrxn2 = 2*pi;
deltaHrxn2 = pi/2;
R = 5;
T = 298:422; %Temperature Values
...
plot(T, real(yCO),'b', T, imag(yCO), 'r'), legend('Real','Imag') %% Works ok

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by