How I could solve the for loop problem?
Mostra commenti meno recenti
I couldn't solve the for loop program. I couldn't find where i make mistake. I couldn't get the answer for TC, TCC
clc
close all
k=50;
c=20;
h=2;
H=2;
w0=20;
w1=0.1;
c0=1;
lambdai = [220 250 280 310 400];
b=[50 70 100 120 130];
M = zeros(length(lambdai));
for i=1:M
C1(i) = lambdai;
rho1(i)= (1-(lambdai(i)./mu));
B1(i)=((b(i).*lambdai(i))./lambda);
q1(i)=sqrt((2.*k.*lambdai(i).*(h+c0.*w1.*the2+b(i)))./((H+c0.*w1.*the2).*rho(i).*b(i)));
v1(i)=-((H+c0.*w1.*the2).*rho(i).*q(i))./((H+c0.*w1.*the2+b(i)));
i=i+1;
end
C
rho
B1
q1
v1
N = zeros(length(q1),length(rho),length(v1));
for j=1:N
TCC(i)=c.*lambdai(i)+((k.*lambdai(i))./q1(i))+((H.*(rho(i).*q1(i)+v1(i)).^2)./(2.*rho(i).*q1(i)))+((b(i).v1(i).^2)./(2.*rho(i).*q1(i)))+c0.*(w0+w1.*((rho(i).*q1(i)+v1(i)).^2)./(2.*rho(i).*q1(i))).* the2
TC(i)=c.*lambdai(i)+c0.*w0.*the2+ sqrt((2.*k.*lambdai(i).*b(i)).*rho(i).*(H+c0.*w1.*the2)./((H+c0.*w1.*the2.*b(i))))
j=j+1;
end
TCC
TC
C1 = sum(C(:));
Q=sum(q(:));
rhoo=sum(rho(:));
V=sum(v(:));
B=sum(B1(:));
TCP= c.*lambda+((k.*lambda)./Q) + (H+c0.*w1.*the2).*((rhoo.*Q+V).^2)./(2.*rhoo.*Q)+((B.*V.^2)./(2.*rhoo.*Q))+c0.*w0.*the2
TCPP=c.*lambda+c0.*w0.*the2+sqrt((2.*k.*lambda.*B.*rhoo.*(H+c0.*w1.*the2))./(H+B+c0.*w1.*the2))
Z=TCPP-TCC
R=(Z./TCC).*100
4 Commenti
KSSV
il 12 Lug 2022
You code is a full of mess with lot of corrections. What exactly you are trying to solve?
We suggest you to go through the basics of MATLAB.
M.Rameswari Sudha
il 12 Lug 2022
KSSV
il 12 Lug 2022
It is because:
M = zeros(length(lambdai));
for i=1:M
What does it mean? M is a matrix, you have used it in loop indexing. So, this loop does not get executed.
M.Rameswari Sudha
il 12 Lug 2022
Risposta accettata
Più risposte (1)
M.Rameswari Sudha
il 12 Lug 2022
0 voti
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!