Julia equivalent for python scipy.optimize.fsolve

Yes, sure, there are great packages in Julia for symbolic manipulation, but the context here is, e.g., when you’re teaching engineering students to solve an electrical circuit in the simplest possible way. I want to completely replace MATLAB in this case by Julia, without introdicung complexities the students don’t care about. They want to answer the simple question of just give me the currents in the circuit.

Just use vectors/matrices then — more compact, less error-prone. I imagine most EE students should be able to handle elementary linear algebra.

If you want a CAS without using packages, then that’s not possible in Julia.

4 Likes

I mean, did you even test it yourself? I ran your code, I checked G(x), it was zero with the result from the routine and non-zero with what you provided. Are you really so sure that you didn’t make a typo that you don’t have to check it yourself, even when both the computer and a human says that the solution you got is in fact correct?

Above we can find 4 different proposals with which we obtain the expected results. And I don’t realize what that difference is!
links:
20
8
14
17

It was already said:

2 Likes

You are absolutely right. I would be wrong 'the index gave unsuccessful result.
Here it is already corrected and we obtain the expected results.

G(x) = [3x[1] + 5x[2] + 2x[3] - 12, 2x[1] + 5x[2] - 4x[3] - 9, 4x[1] - x[2] + 5x[3] + 3]
22:09:46->>G (generic function with 1 method)
Julia>J = ForwardDiff.jacobian(G, [0,0,0])
22:09:47->>3×3 Array{Int64,2}:
 3   5   2
 2   5  -4
 4  -1   5
Julia>x = -J \ G([0,0,0])
22:09:49->>3-element Array{Float64,1}:
 -0.8918918918918918
  2.675675675675676
  0.6486486486486486
Rational.( -J) \ Rational.(G([0,0,0]))
22:18:58->>3-element Array{Rational{Int64},1}:
 -33//37
  99//37
  24//37

Thank you very much for allowing me happy dreams!

Note that @shashi added a solve_for function last week. Still not documented though.

1 Like

Oh, that’s awesome news! Is that also able to handle more complex non-linear equations?

Very very soon.

2 Likes

Which kind of underlies the point: don’t use the general form in code if it can be avoided, it is very error-prone. Use linear algebra notation, especially for linear problems.

1 Like