By: Makie Blog
Re-posted from: https://blog.makie.org/blogposts/bonito
Finally announcing Bonito.jl, the flashy Julia web framework
By: Makie Blog
Re-posted from: https://blog.makie.org/blogposts/bonito
Finally announcing Bonito.jl, the flashy Julia web framework
By: n JuliaLang - The Julia programming language n
Re-posted from: https://julialang.org/blog/2025/10/this-month-in-julia-world/index.html
Community Newsletter for September 2025
Re-posted from: https://blog.glcs.io/matlab-vs-julia-renewable-energy
This post was written by Steven Whitaker.
At GLCS, we’re proud to have delivered innovative projects across top industries, including renewable energy, aerospace, and biomedical engineering.Our comprehensive Modeling and Simulation Servicesempower clients to elevate their designs,whether rewriting models in Juliafor greater efficiency or unlocking cutting-edge featuresto solve complex problems.With deep expertise spanning several engineering and scientific domains,including computational fluid dynamics,thermodynamics,controls,biomedical engineering,and chemistry,we are your trusted partner in pushing modeling boundariesand achieving breakthrough results.
In this post,we’ll focus on systems modelingfor renewable energy.
Renewable energy systems,from wind farms to wave power,require precise modeling and simulation.Selecting the optimal computational tools is crucial;it can significantly acceleratedevelopment, reduce costs, and drive the transitionto a sustainable future.
Both MATLAB and Julia are widely used in engineering,particularly for solving differential equations.This post compares how each handlesa renewable energy modeling scenario,the steady axisymmetric turbulent wakebehind a wind turbine,ultimately showing why Julia has the edge.Maximize efficiency and energy outputwith cutting-edge technologiesdesigned for tomorrows energy.
When air flows past a wind turbine,a wake forms downstream.The wake velocity deficit impacts turbine spacing,efficiency,and power output.
A simplified steady axisymmetric turbulent wake equation is:
\[\frac{\partial U}{\partial x} = \nu_t \cdot \left( \frac{\partial^2 U}{\partial r^2} + \frac{1}{r} \frac{\partial U}{\partial r} \right)\]
where:
This is a reduced form of the momentum equation,capturing diffusion of momentumdue to turbulence.
Let’s see how to convert the math into codeand solve this PDE.
MATLAB:
function dUdx = wake_eq(x, U, p) % Radial step size dr = p.r(2) - p.r(1); % First derivative (central difference) dUdr = (U(3:end) - U(1:end-2)) / (2 * dr); % Second derivative (central difference) d2Udr2 = (U(3:end) - 2 * U(2:end-1) + U(1:end-2)) / dr^2; dUdx = zeros(size(U)); dUdx(2:end-1) = p.nu_t * (d2Udr2 + dUdr ./ p.r(2:end-1));endU0 = initial_profile();xspan = [0 100];p.nu_t = 0.05;p.r = linspace(0, 1, numel(U0));prob = ode;prob.ODEFcn = @dUdx;prob.InitialTime = xspan(1);prob.InitialValue = U0;prob.Parameters = p;prob.Solver = "ode45";sol = solve(prob, xspan(1), xspan(2));
Julia:
using DifferentialEquations@kwdef mutable struct WakeParams{T} _t::Float64 const r::Tendfunction wake_eq!(dU, U, p, x) # Radial step size dr = p.r[2] - p.r[1] # First derivative (central difference) dUdr = (U[3:end] .- U[1:end-2]) ./ (2 * dr) # Second derivative (central difference) d2Udr2 = (U[3:end] .- 2 .* U[2:end-1] .+ U[1:end-2]) ./ dr^2 dU[1] = dU[end] = 0 dU[2:end-1] .= p._t .* (d2Udr2 .+ dUdr ./ p.r[2:end-1])endU0 = initial_profile()xspan = (0.0, 100.0)p = WakeParams(; _t = 0.05, r = range(0.0, 1.0, length(U0)))prob = ODEProblem(wake_eq!, U0, xspan, p)solver = Tsit5()sol = solve(prob, solver)
(Note that, in practice,the boundary conditionsfor \( r = 0 \) and \( r = 1 \)would need to be handled with more care.)
As you can see,the syntax for Julia and MATLABis quite similar.However,there are some key differencesbetween the two approaches:
.=, .*, etc.) is explicit and fast.Now let’s add a gust at \( x = 50 \)that will change \( \nu_t \)for \( x \ge 50 \).
MATLAB:
function v = events_func(x, U, p, gust_position) % Event occurs when `x == gust_position`. v = x - gust_position;endfunction [stop, U, p] = callbacks_func(x, U, ie, p) stop = false; % Check if the event occurred. if ismember(1, ie) p.nu_t = 0.08; endendgust_position = 50;event = odeEvent;event.EventFcn = @(x, U, p) events_func(x, U, p, gust_position);event.Response = "callback";event.CallbackFcn = @callbacks_func;prob.EventDefinition = event;sol = solve(prob);
Julia:
function gust_affect!(integrator) integrator.p._t = 0.08endgust_position = 50.0;callback = PresetTimeCallback([gust_position], gust_affect!)sol = solve(prob, solver; callback)
When it comes to events and callbacks,Julia’s approach is better:
CallbackSet,no need to try to cram multiple eventsinto a single functionlike you have to do in MATLAB.In addition to the differencesin solving differential equations,here are some other key differencesbetween Julia and MATLAB:
In this post,we saw how Julia and MATLAB comparefor defining and solvingsteady axisymmetric turbulent wake.Both languages can model renewable energy systems effectively.However, Julia offers:
Ready to revolutionize your renewable energy simulations? Transition your MATLAB models to Juliaand experience unparalleled speed, flexibility, and long-term maintainability.Reach out today and let’s accelerateyour green energy innovations together!
Worried about the technical hurdles and costsof switching from MATLAB to Julia?Discover our cutting-edgeJulia-MATLAB Integration.We develop high-performance Julia modelsthat seamlessly connect withyour existing MATLAB codebase,minimizing risks while maximizingyour return on investment.Transition smarter, faster, and more cost-effectivelywith our expert solutions!
MATLAB is a registered trademarkof The MathWorks, Inc.
]]>