Why do i get a blank graph?

8 ビュー (過去 30 日間)
jpmontoya
jpmontoya 2019 年 6 月 1 日
コメント済み: jpmontoya 2019 年 6 月 2 日
Hello, as you can see in the code below I am trying to make two plots but the problem is that the subplot (2,1,2) goes blank. I got nothing. I think maybe there is something wrong with the variables k1 and v1 since they depend on X(1) and X(3) which come from the solution of an ODE. Can somebody help me? Thanks in advance.
function [T,X] = call_osc()
tspan = [0 2000];
x1_0=0.05;
x2_0=0.05;
x3_0=298.15;
x4_0=0.1;
odeset('RelTol', 1e-10, 'AbsTol', 1e-12);
[T,X]=ode15s(@osc,tspan,[x1_0 x2_0 x3_0 x4_0]);
R=8.314;
Ea1=80000;
alpha=11;
A=1;
k1= 0.8*exp(-Ea1/(alpha*R*X(3)));
v1=k1*A*X(1);
subplot(2,1,1)
plot(T,X(:,3))
grid on
xlabel('tiempo(s)','Fontsize',13,'FontWeight','Bold')
ylabel('Temperatura (K)','Fontsize',13,'FontWeight','Bold')
subplot(2,1,2)
plot(X(:,1),v1)
grid on
end
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 6 月 2 日
It would help to have your osc function

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

採用された回答

gonzalo Mier
gonzalo Mier 2019 年 6 月 2 日
編集済み: gonzalo Mier 2019 年 6 月 2 日
You are computing v1 as
k1= 0.8*exp(-Ea1/(alpha*R*X(3)));
v1=k1*A*X(1);
v1 is a matriz of size 1x1. So when you do plot( "vector of size 1xn" , "cte" ) the output is an empty plot.
Check if the way to compute v1 is correct or you have to use X(:,1).
PD: You also can check this doing:
plot(X(:,1),v1,'*')
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 6 月 2 日
tspan = [0 2000];
[T,X]=ode15s(@osc,tspan,[x1_0 x2_0 x3_0 x4_0]);
X will be output as something with an unpredictable number of rows, and 4 columns.
k1= 0.8*exp(-Ea1/(alpha*R*X(3)));
v1=k1*A*X(1);
X is a 2D array. X(1) and X(3) are linear indexing, so X(3) is X(3,1) ans X(1) is X(1,1) . X(1,1) should be the same as x1_0 but X(3,1) will be the x1 output at the third time point, whatever the third time point happens to be.
jpmontoya
jpmontoya 2019 年 6 月 2 日
Thank you so much. I did a lot of things considering the answers of Gonzalo and Walter and finally everything works perfect.

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by