Fixed-Tilt Solar Panel Optimization

June 2, 2026 · View on GitHub

Solar Panel Energy Optimization

Use MATLAB and optimization tools to find the best tilt angle and aspect ratio for maximum solar energy production.

Meet the Team

Tito Romero
Tito Romero
CSULA Electrical Engineering

Exploring MATLAB & MathWorks tools like optimization.
Excited to learn and solve real problems. My goal is to understand the connections between engineering and coding. MathWorks is helping bridge that gap and guide future engineers.
Tito Romero
Kyle Shibao
UC Berkeley Electrical Engineering

Love tinkering with circuits. New to MATLAB.
I'm grateful to be part of this program and learn how to use MATLAB and the suite of software it provides to solve problems.

Although our team originally had four members, two left early on and contributed little to the project, leaving the remaining two of us to take on all the work. It was challenging, but we pushed through and completed the entire project ourselves.

Acknowledgments

Throughout this project, we used AI language models as a writing and organizational aid. They helped us edit our explanations, structure the documentation, and provided general pointers on MATLAB, Simulink, and optimization concepts. However, we built the models, ran the simulations, analyzed the data, and verified all the final results ourselves.

Motivation

Solar power is one of the cheapest and fastest-growing energy sources in the world, offering a clean and sustainable alternative to fossil fuels. However, the efficiency of solar panels is highly dependent on their orientation relative to the sun. Solar panels are most efficient when they are completely perpendicular to the sun. Fixed-position panels often miss out on optimal sunlight throughout the day, leading to energy losses. Increase in energy production leads to a higher return on investment, which makes solar panels more economical, leading to higher adoption and lower carbon emissions. Enhancing the energy efficiency of solar panels reduces the need for additional panels and land, thereby lessening human environmental impact and helping to combat climate change.


Fixed-Tilt Solar Panel Optimization

Project Description

The goal of this project is to obtain the maximum energy production, balancing the shape (aspect ratio) as well as incidence angle to maximize energy return. We are limited to a rectangular surface with a surface area of 2 square meters. The only two parameters that may be adjusted are

  • Tilt Angle (θ\theta) which is the angle between the panel and the ground, and can only be from 0 degrees to 90 degrees
  • Aspect Ratio (rr) which is the ratio of the panel's width and length, which is constrained from 0.5 to 4.0

Our objective was to use MATLAB to find the values of θ\theta and rr to maximize the energy generation under the above constraints.

Results

This project used MATLAB to find the best tilt angle and shape (aspect ratio) for a solar panel, in order to get the most energy from sunlight. The program tested many combinations using optimization tools to find which setup gives the highest energy output, while keeping the panel area fixed at 2 square meters.

The results show that the most energy is produced when:

  • Tilt Angle is around 37.50 degrees
  • Aspect Ratio is about 1
  • Maximum Energy Output is 1965.93 units

Below are two 3D graphs generated from the code that help visualize these results:

Energy Surface Graph 1 Energy Surface Graph 2
In the plots, a big star or point marks this best spot. That’s the place where both the angle and shape of the panel are just right to collect the most sunlight under the given model.

Each graph shows how the energy output changes depending on the tilt angle (on one axis) and the aspect ratio (on the other). The peak of the surface — where the graph reaches its highest point — shows the best combination that gives the most energy.

Tilt Angle (°)Aspect RatioEnergy Output (units)Notes
201.01294.10Sunlight too low
301.01732.05Good efficiency, lower sun
37.5 (optimal)1.0 (optimal)1965.93✅ Best energy output
451.01767.77Past optimal, sun angle drops
602.01087.91Bad shape and high tilt

This table shows how changing the tilt angle and the shape of the solar panel affects how much energy it can produce. The best results came from a tilt of 37.5° and a regular shape (aspect ratio = 1.0). Moving away from these values — either by tilting too much or choosing an odd shape — leads to lower energy output. This shows why it’s important to optimize both the angle and shape when designing solar panels.

Background Material

Solar panels work best when they face the sun directly. The amount of energy they generate depends on how tilted they are and what shape they take. In this project, we modeled a solar panel with a fixed area (2 square meters) and tried to find the best tilt angle and shape to get the most energy.

We used a simplified energy formula that depends on two things:

  • Tilt angle (θ) — how much the panel is angled upward. If it’s tilted too little or too much, it won’t catch enough sunlight.
  • Aspect ratio (r) — the shape of the panel (length divided by width). If the shape is too stretched, it becomes less efficient.

The energy function is based on these ideas:

  • Sunlight is strongest when the panel is angled toward the sun
  • Efficiency drops if the shape is too far from square
  • Both of these effects are modeled using cosine and exponential functions

📐 Energy Function

The energy output is calculated using the formula:

E(θ,r)=2cos(θ30)(1000cos(θ45))e0.1(r1)2E(θ, r) = 2 \cdot \cos(θ - 30^\circ) \cdot \left(1000 \cdot \cos(θ - 45^\circ)\right) \cdot e^{-0.1(r - 1)^2}

Where:

  • The 2 is the fixed panel area (in square meters)
  • cos(θ - 30°) models panel efficiency
  • 1000 ⋅ cos(θ - 45°) models sunlight intensity depending on tilt
  • exp(-0.1(r - 1)^2) adds a penalty for stretched panel shapes

We used MATLAB’s optimization toolbox to solve the problem. The tool tested many combinations of tilt and shape until it found the one that produced the most energy. We also used a 3D surface plot to visualize the energy output across different tilt angles and shapes.

This project helped us practice:

  • Setting up a real-world problem as a math function
  • Using optimproblem and fcn2optimexpr in MATLAB
  • Visualizing results with surf and plot3

Accessing our Fixed Tilt Model

To access the fixed tilt model from GitHub, clone the repository to your local machine using git clone. Then, navigate to the src/fixed tilt/ directory and run the live script by opening and executing SolarPanelOptimization.mlx with MATLAB.

Limitations of our Model

A key limitation of our model is its static design. It calculates energy output for a single point in time, rather than for a realistic duration like a full day. The model is based on the assumption that the sun is fixed at a 45° angle above the horizon. This condition is represented by the sunlight intensity function, sunIntensity(θ)=1000cos(θ45)\text{sunIntensity}(\theta)=1000\cdot\cos(\theta−45^\circ), which means the maximum amount of sunlight is captured only when the panel's tilt angle, θ, is also 45°. At this angle, the panel's surface is perfectly perpendicular to the sun's rays.

As a result, our findings for the optimal tilt angle and aspect ratio are only valid for that specific moment. In practice, the sun’s position in the sky is not fixed; it changes continuously throughout the day and varies significantly with the seasons.

While our current model is useful for analyzing a specific case, its results don't show the best setup for maximizing energy collection over a whole day or year. This is where we can make upgrades to our simple fixed-angle solar panel. Instead of using one fixed angle for a given estimate of the sun angle, a tracker's software would continuously calculate the sun's real-time position. It would then adjust the panel's tilt and orientation to always remain perpendicular to the sun's rays, maximizing sunlight capture from sunrise to sunset.


Two-Axis Variable Tilt Solar Panel Optimization

To address the limitations of the fixed-angle solar panel system, we designed a dynamic two-axis solar tracker and simulated using MATLAB, Simulink, and Simscape. We started with the "Using the Worm and Gear Constraint Block"1 example from the MathWorks website. We modified this example Simulink model to be able to track the sun over the course of a day.

The core of the design is a two-axis, closed-loop control system. Each axis has its own PID controller to manage the panel's orientation. This system controls both the yaw (azimuth) and pitch (elevation) axes to precisely follow the sun's trajectory throughout the day.

Simulink Model

We first find where the yaw and pitch angles should be by using a Solar Position Algorithm (SPA) to calculate the sun's real-time coordinates for a specific geographic location, and a specific time. We found a SPA algorithm written in MATLAB from the MATLAB File Exchange website2, and after modifying the code to make it compatible to be used within our Simulink program, we set the geographic location to Los Angeles, CA since we both reside there. For the date, we chose July 25, 2025 since this is the due date for our project. For the time, we chose to model from 8:00 AM - 8:00 PM (PDT), since this is slightly after sunrise right until sunset. The design is highly adaptable; the solar tracking algorithm can be configured for any geographic location by changing the latitude and longitude coordinates, and for any point in time, including future dates.

After we found where the yaw and pitch angles should be, we found where the yaw and pitch angles actually are. To do this, we used a Transform Sensor to obtain the Euler Angles of the solar panel. After we obtained the actual yaw and pitch, we fed it into our PID control system. Each controller continuously compares the target angle with the panel's actual measured angle and commands a DC motor to adjust the panel's orientation, thereby minimizing the error and ensuring the panel faces the sun directly. By using a control loop, we ensure that the panel continuously aligns itself with the sun’s position, maximizing solar energy capture throughout the entire day, unlike our previous model.

As you can see below, the actual yaw and pitch angles continuously adjust to align with the target angles because of our control loop. Note: Each second of simulation time (on the x-axis) span one real-life minute, so the graphs span 0–720 minutes (12 hours). The y-axis represents the angle in radians.

Yaw Scope Pitch Scope

Animation of Simulation

You can access a 24-second sped up Simulink animation video of the solar panels moving and tracking the sun by clicking here. You can also access the animation by viewing the file SolarPanelSimulation.mp4, or by running the Simulink model yourself. I highly recommend you take 24 seconds to watch the video or watch the animation by running the model.

Accessing our Variable Tilt Model

To access the variable tilt model from GitHub, clone the repository to your local machine using git clone. Then, navigate to the src/variable tilt/ directory and run the simulink model by opening and executing WormAndGearConstraint.slx with MATLAB. Make sure that the other files and folders: WormAndGearConstraintSupport/ and WormAndGearConstraintLibrary.slx are in the same directory. Run the model, access the scopes, and watch the animation play.

Warning: The model may take awhile (~5 minutes) to compile and finish


Impact

This project shows how we can use simple math and coding to make better decisions when designing solar panels. Instead of guessing what angle or shape works best, we used a model to test many options and find the one that gives the most energy.

Even though the setup is simplified, the approach can be applied to real-world problems. Engineers, researchers, or anyone working with solar energy can use this kind of optimization to:

  • Improve solar panel design for different locations
  • Adjust panels to match seasonal sunlight changes and changes based on time
  • Maximize energy for a limited space (like rooftops, portable devices, or solar farms)

By using tools like MATLAB, we were able to turn a real question — “What tilt and shape gives the most power?” — into something we could solve with code. This helps build skills that are useful in renewable energy, electrical engineering, and beyond.

Expertise Gained

Before this project, Kyle knew nothing about MATLAB, Simulink, Simscape, or control systems. Tito knew introductory MATLAB from his college course but did not know how to use its optimization features. Throughout this project, the two of us had to learn how to use MATLAB, Simulink, Simscape, and control systems tools to design an optimization algorithm.

We used many public resources to learn about different features in MATLAB. Some of the resources we used are the following:

  • Getting Started With Simulink For Controls3 – Taught how control systems work and introduced the basics of using the PID Controller.
  • MATLAB Onramp Course4 – Gave us the basics of using MATLAB.
  • Optimization Onramp Course5 – Taught us how to use optimproblem and fcn2optimexpr in MATLAB.
  • Simulink Onramp6 – Taught us how to use Simulink to build, simulate, and visualize dynamic systems using block diagrams.
  • Simscape Onramp7 – Taught us how to model physical systems using Simscape blocks.

References

Footnotes

  1. Using the Worm and Gear Constraint Block - Solar Tracker (MathWorks)

  2. Sun Position Algorithm (MATLAB File Exchange)

  3. Getting Started With Simulink for Controls – MathWorks YouTube Video

  4. MATLAB Onramp Course (MathWorks Academy)

  5. Optimization Onramp Course (MathWorks Academy)

  6. Simulink Onramp Course (MathWorks Academy)

  7. Simscape Onramp Course (MathWorks Academy)