Plot function is blank
1 次查看(过去 30 天)
显示 更早的评论
Hey guys
I was working on displaying a function but my plot would just not display the graph I'd like to see
Here is the function I created
function yp=file(t,y)
a_1= -0.04;
a_2= -0.19;
a_3= 0.12;
b_1= 0.02;
b_2= -0.13;
b_3= 0.23;
c_1= 0.14;
c_2= 0.01;
c_3= 0.37;
d_1= -0.14;
d_2= -0.25;
d_3= -0.15;
yp = [(a_1 - b_1*y(1)- c_1*y(2)- d_1*y(3))*y(1);
(a_2 - b_2*y(1)- c_2*y(2)- d_2*y(3))*y(2);
(a_3- b_3*y(1)- c_3*y(2)- d_3*y(3))*y(3);
(a_1-2*b_1*y(1)-c_1*y(2)-d_1*y(3))*y(4)-c_1*y(1)*y(5)-d_1*y(1)*y(6);
-b_2*y(2)*y(4)+(a_2-b_2*y(1)-2*c_2*y(2)-d_2*y(3))*y(5)-d_2*y(2)*y(6);
-b_3*y(3)*y(4)-c_3*y(3)*y(5)+(a_3-b_3*y(1)-c_3*y(2)-2*d_3*y(3))*y(6)];
Here's the function I'd like to graph in
y0 = [0.31;0.20;0.49;0.00001;0.00001;0.00001];
t0 = 0;
tfinal = 100;
[t,y] = ode45(@file,[t0 tfinal],y0);
e=sqrt(y(:,4).^2+y(:,5).^2+y(:,6).^2);
e0=sqrt(0.00001^2+0.00001^2+0.00001^2);
f=abs(e/e0);
g=log(f);
a=1/t*g;
plot(t,a)
of course file referring to the above function yp
I don't think there are any erros in the code, but the plot just shows blank
Thank you in advance
0 个评论
采纳的回答
Ameer Hamza
2020-12-1
Change the line
a=1/t*g;
to
a=1./t.*g;
Read about element-wise operators: https://www.mathworks.com/help/matlab/matlab_prog/array-vs-matrix-operations.html
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!