Error in plot... vectors must be same length

9 views (last 30 days)
Kuhu Singh
Kuhu Singh on 9 Apr 2022
Answered: KSSV on 9 Apr 2022
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;

Answers (1)

KSSV
KSSV on 9 Apr 2022
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.

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!