Skip to content

[model_edit] "Trigonometric Function" added by display name computes a CORDIC-approximated sine — silent output divergence #61

Description

@shafiul

Bug Report

[model_edit] "Trigonometric Function" added by display name computes a CORDIC-approximated sine — silent output divergence

Date: 2026-08-10
Severity: High
Reproducibility: Always

Summary

When model_edit adds a Trigonometric Function block (sine) requested by its Library Browser display name, the created block computes the sine with a CORDIC approximation instead of exactly, so its simulated output silently differs from sin(x). model_check reports the model healthy and no warning is shown.

Expected Behavior

The block added for "Trigonometric Function" (Operator = sin) computes the exact sine, matching sin(x) to solver tolerance — the same as the block dragged from Simulink → Math Operations → Trigonometric Function, which defaults to ApproximationMethod = None.

Actual Behavior

The created block has ApproximationMethod = CORDIC (an approximation); its output differs from sin(x) by up to ~6.3×10⁻⁴. No warning is shown and model_check reports the model healthy. Adding the same block by its type name or full library path produces the exact (None) block — so the difference is tied to which name is passed.

Reproduction Steps

Prerequisites: MATLAB R2026a with the Simulink Agentic Toolkit initialized.

  1. Create an empty model.
  2. Use model_edit to add a Ramp source, a Trigonometric Function block (Operator = sin), and an Outport; wire Ramp → Trigonometric Function → Outport.
  3. Run model_check — it reports the model healthy.
  4. Simulate over t ∈ [0, 3] at a 0.1 s step and log the output.
  5. Compare against sin on the same samples. Observe: output differs by ~6.3×10⁻⁴; the block's ApproximationMethod is CORDIC.

Minimal Reproduction

new_system('m'); save_system('m');
model_edit('m.slx','root','[{"op":"add_block","type":"Trigonometric Function","name":"T","ref":"t"}]','full');
load_system('m'); get_param('m/T','ApproximationMethod')     % -> CORDIC  (display name)

new_system('m2'); save_system('m2');
model_edit('m2.slx','root','[{"op":"add_block","type":"Trigonometry","name":"T","ref":"t"}]','full');
load_system('m2'); get_param('m2/T','ApproximationMethod')   % -> None    (type name; exact)

Environment

Detail Value
SATK Version 2026.08.05 (also present on prior releases)
MATLAB R2026a, maca64
MCP Tools model_read, model_edit, model_check

Additional Context

The output divergence shown directly. Build the block by the display name (m1) and, as a reference, the standard Math-Operations block (m2); run a ramp [0,3] through each and compare to the exact sine:

bdclose('all');
new_system('m1'); save_system('m1');
model_edit('m1.slx','root','[{"op":"add_block","type":"Trigonometric Function","name":"T","ref":"t"}]','full');
load_system('m1');
add_block('simulink/Sources/Ramp','m1/R','slope','1','start','0','InitialOutput','0');
add_block('simulink/Sinks/Out1','m1/Y'); add_line('m1','R/1','T/1'); add_line('m1','T/1','Y/1');

new_system('m2');
add_block('simulink/Sources/Ramp','m2/R','slope','1','start','0','InitialOutput','0');
add_block('simulink/Math Operations/Trigonometric Function','m2/T');
add_block('simulink/Sinks/Out1','m2/Y'); add_line('m2','R/1','T/1'); add_line('m2','T/1','Y/1');

for c = {'m1','m2'}
  m = c{1};
  set_param(m,'SolverType','Fixed-step','Solver','FixedStepDiscrete','FixedStep','0.1','StopTime','3','SaveOutput','on','SaveFormat','Array');
  so = sim(m); y = so.yout; t = (0:0.1:3)';
  fprintf('%-4s ApproximationMethod=%-6s  max|y-sin| = %.3e\n', m, get_param([m '/T'],'ApproximationMethod'), max(abs(y(1:numel(t))-sin(t))));
end

Observed:

m1   ApproximationMethod=CORDIC  max|y-sin| = 6.302e-04
m2   ApproximationMethod=None    max|y-sin| = 4.441e-16

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions