How can I limit decimal places in octave

Problem description

I was doing a mathematical calculation using ‘fsolve’ function, there were 2 non-linear equation with 2 variables to be solved, and i need to input 2 variables to define the equation. so it’s kinda tricky to state the initial guess and tolerance of errors. Unfortunately i’m not that good at math, so i was hoping to decrease the precision of answers to make sure it converges. The function look like this:

## input a and b as constants
...

function y=f(x)
  y(1) = f_1(x(1), x(2)) + a
  y(2) = f_2(x(1), x(2)) + b
endfunction
## trying to solve using fsolve function
[x,fval,info] = fsolve(@f,[0;0],optmiset("TolX", 0.01));

I found out if i manually input a and b as 2 place decimals it would converge and output result as it should, but when other parts of the code give inputs of a and b as “1.60000” (as a ‘short’ type data), it would collapse and output weird results.
I am able to know it’s something to do with data types and precision of calculation, but i failed to limit the decimal places :frowning: Looking forward to any advice here.

My system

  • OS: Windows 11 21H2
  • Octave version: Version 6.4.0
  • Installation method: Downloaded and installed “octave-6.1.0-w64-installer.exe” from Download

Can you show the other part of the code which sets a and b as short ?

If possible please provide values of a and b for which the code collapses and another set of values for which the result converges.

What happens when when you add a very small number (say, 1e-5) to values of a and b for which the value converged ?