Starting Julia with a few tasks

I need to do two tasks in Julia but I am so new that I can barely open Julia. I am using Julia in the numerical analysis course on my collage so I was hoping that I can get some help here. Here are the tasks:

I am certain that you can get some help, but this post is much closer to asking someone to do your homework for you.

You are much more likely to get the help you need if you show that you’ve put in some work and show where you’re stuck. Have a look at this post.

What have you tried? What are you encountering that’s different than you expect?


How about telling us some basic Information

  • What computer are you using? PC or Mac
  • What Operating System are you using? Windows, Macos or Linux
  • Where is Julia located? On PC or in a different web site
  • What version of Julia are you using?

function f(u)
x, y, z, λ = u[1], u[2], u[3], u[4]
return [(x^2)/25 + (y^2)/16 + (z^2)/9 - 1,z - 3 - (λz)/9,y - 4 - (λy)/16,x - 5 - (λ*x)/25] #input vector u

function find_jacobian_matrix(f, x, epsilon)
n = length(x) # stores the length of input vector (4)
J = zeros(n, n) # create the nn matrix
for j in 1:n # iterate over each column (4 times)
ei = zeros(n) # create a vector of zeroes
ei[j] = 1 # set the ei vector to 1
J[:, j] = (f(x + epsilon
ei) - f(x)) / epsilon #assign the partial derivative of equations to jth column using the formula
return J

initial guess

x0 = [1.0, 1.0, 1.0, 1.0]

set the inital value for epsilon

epsilon = 1e-6

call the function

J = find_jacobian_matrix(f, x0, epsilon)
so this is my code for now I managed to do the Jacobian matrix but for some reason I am struggling with Newton’s method to find the root of the system. I am getting an error norm not defined.This is my newton method:

function newton(F, J, u0, tol=1e-8, maxiter=100)
u = copy(u0)
for i = 1:maxiter
du = - J \ F(u)
u += du
if norm(du) < tol
return u
error(“newton: maximum number of iterations exceeded”)

1 Like

Make sure to format your code with triple backticks ``` to make it legible.

norm is defined in the LinearAlgebra standard library, so you need using LinearAlgebra before you call it.

julia> norm(rand(5))
ERROR: UndefVarError: norm not defined
 [1] top-level scope
   @ REPL[1]:1      

julia> using LinearAlgebra; norm(rand(5))

Got it it works now thank you