Vectors must be the same length.

3 views (last 30 days)
Mariam Gasra on 1 May 2019
Commented: KSSV on 16 Oct 2020
lamda=0.2;
mu=1-lamda;
P1=mu^2/(mu+lamda)^2;
P2=2*lamda*mu/(mu+lamda)^2;
P3=lamda^2/(mu+lamda)^2;
display(P1);
display(P2);
display(P3);
t = 1:5:100 ;
P11 = zeros(size(t)) ;
P22 = zeros(size(t)) ;
P33 = zeros(size(t)) ;
for i = 1:length(t)
P11(t)=(lamda^2/(lamda+mu)^2)*exp(-2*(lamda+mu)*t)+((2*mu*lamda)/(lamda+mu)^2)*exp(-(mu+lamda)*t)+mu^2/(lamda+mu)^2;
P22(t)=((2*mu*lamda)/(lamda+mu)^2)+(((2*lamda*(lamda-mu))/(lamda+mu)^2)*exp(-(mu+lamda)*t(i)))-2*((lamda^2/lamda+mu)^2)*exp(-2*(mu+lamda)*t(i));
P33(t)=((lamda^2/(lamda+mu)^2)*exp(-2*(mu+lamda)*t(i)))-(2*lamda^2/(lamda+mu)^2)*exp(-(mu+lamda)*t(i))+lamda^2/(lamda+mu)^2;
end
A=P11;
B=P33;
C=P22;
plot(A,t,B,t,C,t)
legend({'A','B','C'})
how can i solve this problem? Vectors must be the same length.??
alex brown on 1 May 2019
Do you need something like this figure?
lamda=0.2;
mu=1-lamda;
P1=mu^2/(mu+lamda)^2;
P2=2*lamda*mu/(mu+lamda)^2;
P3=lamda^2/(mu+lamda)^2;
display(P1);
display(P2);
display(P3);
t = 1:5:100 ;
P11 = zeros(size(t)) ;
P22 = zeros(size(t)) ;
P33 = zeros(size(t)) ;
for i = 1:length(t)
P11(t)=(lamda^2/(lamda+mu)^2)*exp(-2*(lamda+mu)*t)+((2*mu*lamda)/(lamda+mu)^2)*exp(-(mu+lamda)*t)+mu^2/(lamda+mu)^2;
P22(t)=((2*mu*lamda)/(lamda+mu)^2)+(((2*lamda*(lamda-mu))/(lamda+mu)^2)*exp(-(mu+lamda)*t(i)))-2*((lamda^2/lamda+mu)^2)*exp(-2*(mu+lamda)*t(i));
P33(t)=((lamda^2/(lamda+mu)^2)*exp(-2*(mu+lamda)*t(i)))-(2*lamda^2/(lamda+mu)^2)*exp(-(mu+lamda)*t(i))+lamda^2/(lamda+mu)^2;
end
A=P11;
B=P33;
C=P22;
plot(A)
hold on
plot(B)
hold on
plot(C)
legend({'A','B','C'})

KSSV on 1 May 2019
YOu need to check the loop part.....
lamda=0.2;
mu=1-lamda;
P1=mu^2/(mu+lamda)^2;
P2=2*lamda*mu/(mu+lamda)^2;
P3=lamda^2/(mu+lamda)^2;
display(P1);
display(P2);
display(P3);
t = 1:5:100 ;
P11 = zeros(size(t)) ;
P22 = zeros(size(t)) ;
P33 = zeros(size(t)) ;
for i = 1:length(t)
P11(i,:)=(lamda^2/(lamda+mu)^2)*exp(-2*(lamda+mu)*t)+((2*mu*lamda)/(lamda+mu)^2)*exp(-(mu+lamda)*t)+mu^2/(lamda+mu)^2;
P22(i,:)=((2*mu*lamda)/(lamda+mu)^2)+(((2*lamda*(lamda-mu))/(lamda+mu)^2)*exp(-(mu+lamda)*t(i)))-2*((lamda^2/lamda+mu)^2)*exp(-2*(mu+lamda)*t(i));
P33(i,:)=((lamda^2/(lamda+mu)^2)*exp(-2*(mu+lamda)*t(i)))-(2*lamda^2/(lamda+mu)^2)*exp(-(mu+lamda)*t(i))+lamda^2/(lamda+mu)^2;
end
A=P11;
B=P33;
C=P22;
plot(A,t,B,t,C,t)
legend({'A','B','C'})
KSSV on 16 Oct 2020
It is a loop indexing, where loop starts from 1 till length(t), this will ensure the arrays formed will be of dimension of t.

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

R2015b

Community Treasure Hunt

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

Start Hunting!