For Loop Starting at Zero
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'd like to run my Theta for loop across the length of X ( 0 to 1) with my stored values of BI
H = 0.1;
I = 200;
Y = 0;
BI = zeros(I,1);
b = pi;
for i = 1:I
b = fzero(@(b)(b*tan(b)-H),b);
BI(i,1) = b;
end
BI(end);
X = linspace(0,1,I);
Theta = zeros(I,1);
for k = 1:length(X)
Theta(k) = ((((1.\BI).*(1-cos(BI))).\(0.5-(1.\(4.*BI)))).*sin(BI.*Y).*(cosh(2.*BI.*(k-1))-tanh(2.*BI).*sinh(2.*BI.*(k-1))));
end
0 comentarios
Respuestas (1)
dpb
el 7 de Mzo. de 2023
H = 0.1;
I = 200;
Y = 0;
BI = zeros(I,1);
b = pi;
for i = 1:I
b = fzero(@(b)(b*tan(b)-H),b);
BI(i,1) = b;
end
unique(BI)
shows you're starting guess isn't good enough to do more than find the same root over and over and over...try (for a much smaller sample size)
I=5; BI=zeros(I,1);
for i = 1:I
b = fzero(@(b)(b*tan(b)-H),pi*i);
BI(i,1) = b;
end
unique(BI)
diff(BI)
I don't really know what the last equation is supposed to be, but to evaluate in the loop over k, one presumes you're looking for BI(k) everywhere you have BI and the .\ operators are really supposed to denote division on an element-by-element basis.
Write the equation out longhand so it can be deciphered if you need more help...
2 comentarios
dpb
el 7 de Mzo. de 2023
I showed the way to write BI(k) in the loop...oh! I ended up deleting it because it was too hard to try to decipher what was really intended, sorry.
for k = 1:length(X)
Theta(k) = ((((1/BI(k)).*(1-cos(BI(k))))/(....etc., ...
end
Too many parentheses for this old man's eyes to be able to count and the online code editor doesn't automagically match them so leave that to younger eyes than mine... <vbg>
But, there's still confusion about what you really want as there's no X in the equation anywhere; what's the point of it?
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!