Learning Center Watch the latest QUADOA® Optical CAD Videos YouTube channel

Math Expressions for Optimization in QUADOA® Optical CAD

Published by Quadoa Optical Systems GmbH · Last updated · Applies to QUADOA® Optical CAD v26.10 · Reading time: 3 minutes · Video: 3:25 min

When no predefined goal fits, QUADOA® Optical CAD lets you build your own optimization target from other targets and variables with a math expression. Each goal or variable you want to use gets a Target ID; the math expression then combines them, for example as a distance, difference or trigonometric function. For even more flexibility, Python targets are available.

Key points

  • Add a Math Expression target with a right-click on the ray trace (for example under Add Aberration Goals).
  • Give every goal or variable you want to use a unique Target ID.
  • Write the expression with these IDs, e.g. position2 - position1 or sin(radius1) * cos(radius2).
  • An expression can only refer to targets above it, since targets are computed top to bottom.
  • In a duplicated ray trace, an ID refers to the target in the same ray trace.
  • For anything beyond math expressions, use a Python target.

Terms used in this article

Target ID
A unique name of a goal, constraint or variable, used to refer to it in math expressions or Python targets.
Math Expression Target
An optimization goal computed from other targets with a formula.
Python Target
An optimization goal defined by a Python class, for full flexibility.

How to add a math expression target

  1. In the System Setup Editor, open the merit function under Optimization.
  2. Right-click the Ray Trace, open a goal group such as Add Aberration Goals, and choose Math Expression at the bottom.
  3. The target appears in the list of trace goals. Enter the formula in its Math Expression field.

How to use goals and variables in the expression

  1. Give every goal or variable you want to use a unique ID, for example radius1, radius2, position1 and position2.
  2. Use these IDs in the expression. Examples from the video:
    • position2 - position1: the distance between two positions
    • radius2 - radius1: the difference of two radii
    • sin(radius1) * cos(radius2): any other combination

The current value of the expression is shown next to it, so you can check the formula immediately. Because all targets are computed from top to bottom, an expression can only use targets in rows above it. If no math expression or Python target uses an ID, it is simply ignored.

How are IDs resolved in several ray traces?

When you duplicate a ray trace (right-click → Duplicate), its goals and their IDs are copied too. The rules:

  • Variables with an ID can be used in the math expressions of every ray trace.
  • A goal ID always refers to the goal in the same ray trace. In the second ray trace, position1 means the position goal of the second ray trace, not of the first.

This makes it easy to evaluate the same expression for several sequences or configurations. To optimize different parts of a system independently, see multiple merit functions.

Which operators and functions are available?

The same as in the multi-config lookup table: numbers and pi, + - * / ^, brackets, abs, exp, log, log10, log2, sqrt, root, sgn, min, max, trigonometric and hyperbolic functions, rad2deg and deg2rad, logic and comparison operators, and conditions such as if((x<2), 1, sin(y)).

For targets that need their own ray tracing or logic, a Python Target can trace single rays and read other targets and variables by their IDs.

Video tutorial: math expressions in the merit function

This 3-minute video adds math expression targets and shows how IDs are resolved in duplicated ray traces.

Video length: 3:25 min · Also on YouTube: Math Expression Targets in the Merit Function of QUADOA® Optical CAD

Frequently asked questions

Add a Math Expression target to the ray trace of the merit function, give the goals and variables you need a Target ID, and combine them in the expression.

Yes. Give the variable an ID; variables with IDs can be used in the math expressions of every ray trace.

A goal ID always refers to the goal in the same ray trace. Variables can be used across all ray traces.

It may refer to an unknown ID or to a target below it. Targets are computed from top to bottom, so an expression can only use targets in rows above it.