Results for
When solving Cody problems, sometimes your solution takes too long — especially if you’re recomputing large arrays or iterative sequences every time your function is called.
The Cody work area resets between separate runs of your code, but within one Cody test suite, your function may be called multiple times in a single session.
This is where persistent variables come in handy.
A persistent variable keeps its value between function calls, but only while MATLAB is still running your function suite.
This means:
- You can cache results to avoid recomputation.
- You can accumulate data across multiple calls.
- But it resets when Cody or MATLAB restarts.
Suppose you’re asked to find the n-th Fibonacci number efficiently — Cody may time out if you use recursion naively. Here’s how to use persistent to store computed values:
function f = fibPersistent(n)
import java.math.BigInteger
persistent F
if isempty(F)
F=[BigInteger('0'),BigInteger('1')];
for k=3:10000
F(k)=F(k-1).add(F(k-2));
end
end
% Extend the stored sequence only if needed
while length(F) <= n
F(end+1)=F(end).add(F(end-1));
end
f = char(F(n+1).toString); % since F(1) is really F(0)
end
%calling function 100 times
K=arrayfun(@(x)fibPersistent(x),randi(10000,1,100),'UniformOutput',false);
K(100)
The fzero function can handle extremely messy equations — even those mixing exponentials, trigonometric, and logarithmic terms — provided the function is continuous near the root and you give a reasonable starting point or interval.
It’s ideal for cases like:
- Solving energy balance equations
- Finding intersection points of nonlinear models
- Determining parameters from experimental data
Example: Solving for Equilibrium Temperature in a Heat Radiation-Conduction Model
Suppose a spacecraft component exchanges heat via conduction and radiation with its environment. At steady state, the power generated internally equals the heat lost:
Given constants:
= 25 W- k = 0.5 W/K
- ϵ = 0.8
- σ = 5.67e−8 W/m²K⁴
- A = 0.1 m²
= 250 K
Find the steady-state temperature, T.
% Given constants
Qgen = 25;
k = 0.5;
eps = 0.8;
sigma = 5.67e-8;
A = 0.1;
Tinf = 250;
% Define the energy balance equation (set equal to zero)
f = @(T) Qgen - (k*(T - Tinf) + eps*sigma*A*(T.^4 - Tinf^4));
% Plot for a sense of where the root lies before implementing
fplot(f, [250 300]); grid on
xlabel('Temperature (K)'); ylabel('f(T)')
title('Energy Balance: Root corresponds to steady-state temperature')
% Use fzero with an interval that brackets the root
T_eq = fzero(f, [250 300]);
fprintf('Steady-state temperature: %.2f K\n', T_eq);
Don’t miss out on two incredible keynotes that will shape the future of engineering and innovation:
1️⃣What’s New in MATLAB and Simulink in 2025
Get an inside look at the latest features designed to supercharge your workflows:
- A redesigned MATLAB desktop with customizable sidebars, light/dark themes, and new panels for coding tasks
- MATLAB Copilot – your AI-powered assistant for learning, idea generation, and productivity
- Simulink upgrades, including an enhanced quick insert tool, auto-straightening signal lines, and new methods for Python integration
- New options to deploy AI models on Qualcomm and Infineon hardware
2️⃣Accelerating Software-Defined Vehicles with Model-Based Design
See how MathWorks + NXP are transforming embedded system development for next-gen vehicles:
- Vehicle electrification example powered by MATLAB, Simulink, and NXP tools
- End-to-end workflow: modeling → validation → code generation → hardware deployment → real-time cloud monitoring
📅 When: November 13
💡Why Join? Stay ahead with cutting-edge tools, workflows, and insights from industry leaders.

It’s exciting to dive into a new dataset full of unfamiliar variables but it can also be overwhelming if you’re not sure where to start. Recently, I discovered some new interactive features in MATLAB live scripts that make it much easier to get an overview of your data. With just a few clicks, you can display sparklines and summary statistics using table variables, sort and filter variables, and even have MATLAB generate the corresponding code for reproducibility.
The Graphics and App Building blog published an article that walks through these features showing how to explore, clean, and analyze data—all without writing any code.
If you’re interested in streamlining your exploratory data analysis or want to see what’s new in live scripts, you might find it helpful:
If you’ve tried these features or have your own tips for quick data exploration in MATLAB, I’d love to hear your thoughts!
Submit your questions about this work in the comment section below.
In the FAQs, I saw the procedure to download the "mobile background", is the the same thing as an award? If yes, good, else how can we get an award and what are the available ones?
iaabdulhameed@knu.ac.kr
Glad to have watched the session, especially the part when the speaker, Arthur gave an answer to my question on "speech recognition use case" in Avionics.
I set my 3D matrix up with the players in the 3rd dimension. I set up the matrix with: 1) player does not hold the card (-1), player holds the card (1), and unknown holding the card (0). I moved through the turns (-1 and 1) that are fixed first. Then cycled through the conditional turns (0) while checking the cards of each player using the hints provided until it was solved. The key for me in solving several of the tests (11, 17, and 19) was looking at the 1's and 0's being held by each player.
sum(cardState==1,3);%any zeros in this 2D matrix indicate possible cards in the solution
sum(cardState==0,3)>0;%the ones in this 2D matrix indicate the only unknown positions
sum(cardState==1,3)|sum(cardState==0,3)>0;%oring the two together could provide valuable information
Some MATLAB Cody problems prohibit loops (for, while) or conditionals (if, switch, while), forcing creative solutions.
One elegant trick is to use nested functions and recursion to achieve the same logic — while staying within the rules.
Example: Recursive Summation Without Loops or Conditionals
Suppose loops and conditionals are banned, but you need to compute the sum of numbers from 1 to n. This is a simple example and obvisously n*(n+1)/2 would be preferred.
function s = sumRecursive(n)
zero=@(x)0;
s = helper(n); % call nested recursive function
function out = helper(k)
L={zero,@helper};
out = k+L{(k>0)+1}(k-1);
end
end
sumRecursive(10)
- The helper function calls itself until the base case is reached.
- Logical indexing into a cell array (k>0) act as an 'if' replacement.
- MATLAB allows nested functions to share variables and functions (zero), so you can keep state across calls.
Tips:
- Replace 'if' with logical indexing into a cell array.
- Replace for/while with recursion.
- Nested functions are local and can access outer variables, avoiding global state.
What a fantastic start to Cody Contest 2025! In just 2 days, over 300 players joined the fun, and we already have our first contest group finishers. A big shoutout to the first finisher from each team:
- Team Creative Coders: @Mehdi Dehghan
- Team Cool Coders: @Pawel
- Team Relentless Coders: @David Hill
- 🏆 First finisher overall: Mehdi Dehghan
Other group finishers: @Bin Jiang (Relentless), @Mazhar (Creative), @Vasilis Bellos (Creative), @Stefan Abendroth (Creative), @Armando Longobardi (Cool), @Cephas (Cool)
Kudos to all group finishers! 🎉
Reminder to finishers: The goal of Cody Contest is learning together. Share hints (not full solutions) to help your teammates complete the problem group. The winning team will be the one with the most group finishers — teamwork matters!
To all players: Don’t be shy about asking for help! When you do, show your work — include your code, error messages, and any details needed for others to reproduce your results.
Keep solving, keep sharing, and most importantly — have fun!
Many MATLAB Cody problems involve recognizing integer sequences.
If a sequence looks familiar but you can’t quite place it, the On-Line Encyclopedia of Integer Sequences (OEIS) can be your best friend.
OEIS will often identify the sequence, provide a formula, recurrence relation, or even direct MATLAB-compatible pseudocode.
Example: Recognizing a Cody Sequence
Suppose you encounter this sequence in a Cody problem:
1, 1, 2, 3, 5, 8, 13, 21, ...
Entering it on OEIS yields A000045 – The Fibonacci Numbers, defined by:
F(n) = F(n-1) + F(n-2), with F(1)=1, F(2)=1
You can then directly implement it in MATLAB:
function F = fibSeq(n)
F = zeros(1,n);
F(1:2) = 1;
for k = 3:n
F(k) = F(k-1) + F(k-2);
end
end
fibSeq(15)
When solving MATLAB Cody problems involving very large integers (e.g., factorials, Fibonacci numbers, or modular arithmetic), you might exceed MATLAB’s built-in numeric limits.
To overcome this, you can use Java’s java.math.BigInteger directly within MATLAB — it’s fast, exact, and often accepted by Cody if you convert the final result to a numeric or string form.
Below is an example of using it to find large factorials.
function s = bigFactorial(n)
import java.math.BigInteger
f = BigInteger('1');
for k = 2:n
f = f.multiply(BigInteger(num2str(k)));
end
s = char(f.toString); % Return as string to avoid overflow
end
bigFactorial(100)
Title: Looking for Internship Guidance as a Beginner MATLAB/Simulink Learner
Hello everyone,
I’m a Computer Science undergraduate currently building a strong foundation in MATLAB and Simulink. I’m still at a beginner level, but I’m actively learning every day and can work confidently once I understand the concepts. Right now I’m focusing on MATLAB modeling, physics simulation, and basic control systems so that I can contribute effectively to my current project.
I’m part of an Autonomous Underwater Vehicle (AUV) team preparing for the Singapore AUV Challenge (SAUVC). My role is in physics simulation, controls, and navigation, and MATLAB/Simulink plays a major role in that pipeline. I enjoy physics and mathematics deeply, which makes learning modeling and simulation very exciting for me.
On the coding side, I practice competitive programming regularly—
• Codeforces rating: ~1200
• LeetCode rating: ~1500
So I'm comfortable with logic-building and problem solving. What I’m looking for:
I want to know how a beginner like me can start applying for internships related to MATLAB, Simulink, modeling, simulation, or any engineering team where MATLAB is widely used (including companies outside MathWorks).
I would really appreciate advice from the community on:
- What skills should I strengthen first?
- Which MATLAB/Simulink toolboxes are most important for beginners aiming toward simulation/control roles?
- What small projects or portfolio examples should I build to improve my profile?
- What is the best roadmap to eventually become a good candidate for internships in this area?
Any guidance, resources, or suggestions would be extremely helpful for me.
Thank you in advance to everyone who shares their experience!
The main round of Cody Contest 2025 kicks off today! Whether you’re a beginner or a seasoned solver, now’s your time to shine.
Here’s how to join the fun:
- Pick your team — choose one that matches your coding personality.
- Solve Cody problems — gain points and climb the leaderboard.
- Finish the Contest Problem Group — help your team win and unlock chances for weekly prizes by finishing the Cody Contest 2025 problem group.
- Share Tips & Tricks — post your insights to win a coveted MathWorks Yeti Bottle.
- Bonus Round — 2 players from each team will be invited to a fun live code-along event!
- Watch Party – join the big watch event to see how top players tackle Cody problems
Contest Timeline:
- Main Round: Nov 10 – Dec 7, 2025
- Bonus Round: Dec 8 – Dec 19, 2025
Big prizes await — MathWorks swag, Amazon gift cards, and shiny virtual badges!
We look forward to seeing you in the contest — learn, compete, and have fun!
Hi everyone!
I’m Kishen Mahadevan, Senior Product Manager at MathWorks, where I focus on controls and deep learning. I’m excited to be speaking at MATLAB EXPO this year!
In one of my sessions, I’ll share how AI-based reduced order models (ROMs) are transforming engineering workflows—using battery fast charging as an example—making it easier to reuse high-fidelity models for real-time control and deployment.
I’d love to have you join the conversation at the EXPO and right here in the community!
Feel free to drop any questions or thoughts ahead of the event.
Jack and Cleve had famously noted in the "A Preview of PC-MATLAB" in 1985: For those of you that have not experienced MATLAB, we would like to try to show you what everybody is excited about ... The best way to appreciate PC-MATLAB is, of course, to try it yourself.
Try out the end-to-end workflow of developing touchless applications with both MathWorks' tools and STM Dev Cloud from last year!
You can also register this year's EXPO. Join the Hands-On workshops to learn the latest features that make the design and deployment workflow even easier!
Parallel Computing Onramp is here! This free, one-hour self-paced course teaches the basics of running MATLAB code in parallel using multiple CPU cores, helping users speed up their code and write code that handles information efficiently.
Remember, Onramps are free for everyone - give the new course a try if you're curious. Let us know what you think of it by replying below.
A toaster that tells jokes
23%
Cinderalla's godmother for cleaning
23%
Humanoid cooks and washes dishes
32%
Oven door opens with wave of hand
4%
Mattress rocks you to sleep
13%
Mirror recommends healthy cosmetics
4%
69 votes
Hey Relentless Coders! 😎
Let’s get to know each other. Drop a quick intro below and meet your teammates! This is your chance to meet teammates, find coding buddies, and build connections that make the contest more fun and rewarding!
You can share:
- Your name or nickname
- Where you’re from
- Your favorite coding topic or language
- What you’re most excited about in the contest
Let’s make Team Relentless Coders an awesome community—jump in and say hi! 🚀
Welcome to the Cody Contest 2025 and the Relentless Coders team channel! 🎉
You never give up. When a problem gets tough, you dig in deeper. This is your space to connect with like-minded coders, share insights, and help your team win. To make sure everyone has a great experience, please keep these tips in mind:
- Follow the Community Guidelines: Take a moment to review our community standards. Posts that don’t follow these guidelines may be flagged by moderators or community members.
- Ask Questions About Cody Problems: When asking for help, show your work! Include your code, error messages, and any details needed to reproduce your results. This helps others provide useful, targeted answers.
- Share Tips & Tricks: Knowledge sharing is key to success. When posting tips or solutions, explain how and why your approach works so others can learn your problem-solving methods.
- Provide Feedback: We value your feedback! Use this channel to report issues or share creative ideas to make the contest even better.
Have fun and enjoy the challenge! We hope you’ll learn new MATLAB skills, make great connections, and win amazing prizes! 🚀
