Skip to content

New main: assigment 3#5

Open
kurtaga wants to merge 8 commits intonew-mainfrom
dn03
Open

New main: assigment 3#5
kurtaga wants to merge 8 commits intonew-mainfrom
dn03

Conversation

@kurtaga
Copy link
Copy Markdown
Owner

@kurtaga kurtaga commented Aug 28, 2025

No description provided.

@kurtaga
Copy link
Copy Markdown
Owner Author

kurtaga commented Aug 28, 2025

@mrcinv rebased dn03 tudi na new-main. Sedaj ok?

Copy link
Copy Markdown
Collaborator

@mrcinv mrcinv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kurtaga Naloga je rešena zadovoljivo. Izbira algoritmov ne omogoča dovolj velike natančnosti. Prav tako ni nobene ocene za napako, tako da ne vemo, kako natančen je v resnici vaš rezultat.

Because no simple parametric form is available, we approximate this curve numerically by integrating the associated ODE and then use the trajectory to estimate its length.

# Integrating with Explicit Euler
We integrate the ODE using the explicit Euler method. Given a current point $u_k$ on the curve and step size $h$, the next point is computed as
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kurtaga Explicit Euler method is order 1 and it needs orders of magnitude more calculations than higher order methods to achieve sufficient accuracy. The method used should be at least of order 4.

```

# Curve Length
The algorithm produces a trajectory that traces the implicit intersection curve. The total arc length is approximated by summing distances between consecutive points.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kurtaga Given that you normalized the cross product, the parameter from the ODE will be the natural parameter on the curve. So there is no need to perform an additional sum.

@@ -0,0 +1,31 @@

# ODE right-hand side
function rhs(u, ∇F1, ∇F2)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a docstring!



# explicit Euler step
function explicit_euler_step(u, h, ∇F1, ∇F2)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a generic method for euler step that takes one function and not the gradients. Generic methods are easier to test and design. There is less room for bugs.

Suggested change
function explicit_euler_step(u, h, ∇F1, ∇F2)
function explicit_euler_step(u, h, rhs)

Add a docstring.

end

# integrate
function integrate_explicit_euler(u0, h, ∇F1, ∇F2; max_steps=250000, min_steps=100)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a docstring!

for k in 1:max_steps
u = explicit_euler_step(u, h, ∇F1, ∇F2)
push!(traj, u)
if k > min_steps && norm3(u - u0) < tol
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are effectively calculating period of the solution. Checking for the period this way is limited by the step size. So the accuracy is limited to the step size. To get higher accuracy, you should formulate the problem as a nonlinear equation ($y(t_0) = y(t_0 + p)$) and use methods to solve nonlinear equations (Newton, bisection, etc.)

for k in 1:max_steps
u = explicit_euler_step(u, h, ∇F1, ∇F2)
push!(traj, u)
if k > min_steps && norm3(u - u0) < tol
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the method integrate_explicit_euler generic, you can pass the stop condition as an argument.

function integrate_explicit_euler(u0, h, ∇F1, ∇F2; stop_condition=(u, t)->false, max_steps=250000, min_steps=100)
   ...
  if stop_condition(u, t)
      break
  end
  ...
end

and then the stop condition can be passed as an argument

integrate_explicit_euler(u0, h, ∇F1, ∇F2; stop_condition=(u, t)->abs(t)>1 && norm3(u -u0) < tol)

end

@testset "Integration" begin
# For this toy case, tangent always points +z, so trajectory is a straight line
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be easier to test generic method for integration, as you can pass arguments with known solutions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants