Error in plot... vectors must be same length
9 次查看(过去 30 天)
显示 更早的评论
N=30; %no of divisions;
l=30;
delta_x=l/N;
M(1,1)=0;
N(1,1)=1;
O(1,1)=0;
P(1,1)=100;
M(N+1,1)=0;
N(N+1,1)=1;
O(N+1,1)=0;
P(N+1,1)=100;
M(2:N,1)=1;
N(2:N,1)=-(2+0.071^2);
O(2:N,1)=1;
P(2:N,1)=0;
x(1,1)= 100;
x(N+1,1)=100;
%Thomas Algorithm
for p=2:N+1
N(p,1)=N(p,1)-(M(p,1)/N(p-1,1))*O(p-1,1);
P(p,1)=P(p,1)-(M(p,1)/N(p-1,1))*P(p-1,1);
M(p,1)=0;
end
for p=N:-1:2
x(p,1)=(P(p,1)-O(p,1)*x(p+1,1))/N(p,1);
end
plot((0:1:30),x);
grid on;
xlabel("Variation of Length (x) in (cm) ");
ylabel("Temperature in Celsius");
title("Temperature vs Variation of length (TDMA)");
hold on;
0 个评论
回答(1 个)
KSSV
2022-4-9
These lines:
N=30; %no of divisions;
l=30;
delta_x=l/N;
M(1,1)=0;
N(1,1)=1; % <---- over writitng values of N
Why you are overwrititng the value of N? You have defined it to 30, but later you over write it to 1. So at the end, your x size is 1x2, you tried plotting it w.r.t. a vector of size 1x30 so error popped out. Modify your code.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!