Reputation: 669
I have equations which I would like to test with many different values and find the one solution for those equations. So the idea is to find T_out, and all the other values are known. For this I want to test values from 45 to 30 in 0.001 steps.
T_out =326.5
for (i in seq(45, 30, by = -0.001)){
T_out=T_out-i;
Q_in=0.16*0.8*(316-300.4-T_out-300.4) / (log(316-300.4 / T_out-300.4));
Q_out=0.00762*1512*(316-T_out);
if (Q_in-Q_out==0){
break
end}
T_out_new=T_out-i;
}
But nothing happens. Do you know what is the mistake?
Upvotes: 0
Views: 69
Reputation: 388982
These are vectorised function and you should need for
loop for this.
T_out = 326.5
vals = seq(45, 30, by = -0.001)
T_val = T_out - vals
Q_in = 0.16*0.8*(316-300.4-T_val-300.4) / (log(316-300.4 / T_val-300.4))
Q_out = 0.00762*1512*(316-T_val)
vals[which((Q_in - Q_out) == 0)]
However, none of the numbers satisfy the condition and it returns numeric(0)
. Maybe you need to adjust some values ?
Upvotes: 1