Values generated by the loop Seem Wrong

Could someone look over this code which is a loop which is suspose to calculate values for VFull and h1. Then use these new values in the next iteration to do the same calculations. When at the same time outputting Power, NewVolume and h1. The values calculated seem very wrong, especially the futher you go down the loop.
%Importing Data
Time = importdata('time.txt');
%Importing Data
Height = importdata('height.txt');
%constants
d = 7.2;
al = 11500;
cd = 0.8;
ct = 0.5;
g = 9.807;
p = 1029;
%Area Of turbine = pi*r^2
A = 40.715;
%Variables that need to change after every loop
h1 = 14.05; %h1 should be replaced with h1New after every 1 loop
h2 = Height(7988:19295,:); %this data is from a data excel sheet
VFull = 161575; %VFull shoule be replaced by NewVolume after every 1 loop
for c=1:11307
%Discharge
discharge(c) = cd*A*(sqrt(2*g*((abs(h1-h2(c)))))) ;
V = discharge(c)/A;
%Power
Power(c) = (1/2)*ct*p*A*V^3;
%New Volume Calculation
NewVolume(c) = VFull - discharge(c);
VFull=NewVolume(c);
%New h1
h1New(c) = ((VFull - discharge(c))/al);
h1=h1New(c);
end

4 comentarios

Star Strider
Star Strider el 12 de Dic. de 2019
What makes then ‘wrong’? What should the values be?
Constantinos Yiannakis
Constantinos Yiannakis el 12 de Dic. de 2019
The values are suspose to represent how h1 changes with a given Height value but the values generated are mostly negative which doesnt seem to be correct. So was wondering if there was anything wrong with my coding or if its just a mistake with the Height value range ive used.
You forgot to attach either Height, or the worksheet:
h2 = Height(7988:19295,:); %this data is from a data excel sheet
so we can't run your code. Until then, nothing is obviously wrong. And, in spite of Star directly asking you, you have not said what "doesn't seem to be correct" means or what the correct values should be. If I'm just looking at a list of 11,307 numbers, how on earth am I supposed to know if they're correct or not?
Constantinos Yiannakis
Constantinos Yiannakis el 12 de Dic. de 2019
Sorry for that, i have now attached the worksheets and input code. Neither do i know if the values are correct, i was just asking if the code was correct ?

Iniciar sesión para comentar.

 Respuesta aceptada

Ridwan Alam
Ridwan Alam el 12 de Dic. de 2019
I believe you are mistakenly updating VFull in each iteration.
h1 = 14.05; %h1 should be replaced with h1New after every 1 loop
h2 = Height(7988:19295,:); %this data is from a data excel sheet
VFull = 161575; %VFull shoule be replaced by NewVolume after every 1 loop
for c=1:11307
%Discharge
discharge(c) = cd*A*(sqrt(2*g*((abs(h1-h2(c)))))) ;
V = discharge(c)/A;
%Power
Power(c) = (1/2)*ct*p*A*V^3;
%New Volume Calculation
NewVolume(c) = VFull - discharge(c);
%VFull=NewVolume(c);
%New h1
h1New(c) = ((VFull - discharge(c))/al);
h1=h1New(c);
end
figure;plot(h1New)
untitled.jpg
Hope it helps!

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 12 de Dic. de 2019

Respondida:

el 12 de Dic. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by