Error in plot... vectors must be same length

8 visualizzazioni (ultimi 30 giorni)
Kuhu Singh
Kuhu Singh il 9 Apr 2022
Risposto: KSSV il 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;

Risposte (1)

KSSV
KSSV il 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.

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by