For some reason my script runs really really slow on GNU octave. Did that ever happen to you?
It has. Writing data processing code in Octave was a big part of my last job; I ended up using the profiler a lot to optimize things.
>> profile on; your_program; profile off
>> profshow
>> profexplore
>> profile clear
I put some tic and toc statements in the first program you posted and found that the following loop takes most of the time (1.1 seconds on my PC):
for i = 1:SizeofSVL
for j = 1:SizeofSVL
...
end
end
MATLAB has a Just In Time (JIT) compiler that probably optimizes your inner loop here. Octave does not have this feature yet.
https://en.wikipedia.org/wiki/Just-in-time_compilationThere is a more efficient way to write the two-resistor ratio finder. For each resistor value in your list, treat it as the lower resistor. Multiply this lower resistor value by the desired ratio to get the "optimal" upper resistor value. Find the real resistor value in your list that is closest to the "optimal" value and compute its actual ratio relative to the lower resistor.
When I wrote ratio.m, I also repeated this process, treating each resistor value as an upper resistor, dividing by the desired ratio, and finding the closest lower resistor. I don't know if you need to do this or not. I did it because my list of resistor values included all the x1, x10, x100, x1000, x10,000, x100,000, x1,000,000 multiplied resistor values.
I also limited the search range based on the ratio. For example, I didn't test 523k or larger as the lower resistor with a desired ratio of 19, because the largest possible resistor was 9.88M, and 9.88M / 19 is 520k. Similarly, I didn't test 18.9 ohm or smaller as an upper resistor for desired ratio = 19, because 1 ohm is the lowest value in my list.
The attached ratio.m below has comments, runs as a function, and checks user input, as it should have done earlier. I'm too lazy to put a nice header comment on it right now...