octavesymbolic-math

solvefunction to get value to calculate Octave


I've recently found the solve function, which I see a potential in. However, I fail to see the output as usable.

For instance,

syms x

solve(x*sin(20)==5000)

produces the output:

warning: passing floating-point values to sym is dangerous, see "help sym"
warning: called from
    double_to_sym_heuristic at line 50 column 7
    sym at line 379 column 13
    mtimes at line 54 column 5

ans = (sym)

  7106000
  ───────
   413⋅π

Interesting. Because the answer is correct. Only problem is that I want to use this "value" not the equation in itself.

>> 7106000/(413*pi)
ans = 5476.8

Is there a way to get the solve function to actually produce the value I'm after?

I fail to see how I can use this value in further calculations without getting "access" to the calculated value.

I cannot see any flags or any other thing that could help me convert this value from symbolic to numerical...?


Solution

  • I realised my mistake.

    I didn't set a variable to the equation.

    using the same problem as above:

    sol=solve(x*sin(20)==5000)
    

    still gives the output:

    warning: passing floating-point values to sym is dangerous, see "help sym"
    warning: called from
        double_to_sym_heuristic at line 50 column 7
        sym at line 379 column 13
        mtimes at line 54 column 5
    
    sol = (sym)
    
      7106000
      ───────
       413⋅π
    

    If I write sol it provides with the following output:

    >> sol
    sol = (sym)
    
      7106000
      ───────
       413⋅π
    

    However. If I write this

    >> double(sol)
    ans = 5476.8
    

    Which means that I can now set a variable to it and use it for further equations.

    Like this:

    >> z = double(sol)
    z = 5476.8
    

    Which means that z is now the value I wanted in the first place.

    >> z
    z = 5476.8