Clear Filters
Clear Filters

Error while using linmod for linearization of aircraft model

4 views (last 30 days)
I try to linearize the trimmed aircraft model using command given below-
[Alin,Blin,Clin,Dlin] = linmod('Trim_model',xtrim,utrim,ytrim)
, where xtrim,utrim,ytrim are the trimmed values in columm matrix and 'Trim_model' is the simulink model.
This is the error I am geeting-
In Trim_model (line 133)
Error using dlinmod
Domain error. To compute complex results from real x, use
'sqrt(complex(x))'.
Error in sqrt.m (line 13)
coder.internal.error('Coder:toolbox:ElFunDomainError',mfilename);
Error in 'Trim_model/J31_Trimming/Jetstream31
Forces & Moments1/Powerplants and
Slipstream/Powerplant Model/Powerplant - port (forces and
moments about spinner) (in body axes)/Propeller - left
(forces and moments about spinner) (in body
axes)/propeller derivatives' (line 12)
Error in linmod
Error in J31_avms_Trim (line 133)
[Alin,Blin,Clin,Dlin] = linmod('Trim_model',xtrim,utrim,ytrim)
- Show
Thanks!

Answers (1)

Simar
Simar on 14 May 2024
Edited: Simar on 15 May 2024
Hi Priyank,
I understand that you are encountering an error during linearization of aircraft model using “linmod” function. Error message being encountered indicates that there is a domain error occurring within model, specifically related to use of the sqrt function. This typically happens when sqrt function is called with a negative argument, which is not allowed for real numbers since square root of negative number is complex.
The error message points to a specific block in your model ('Propeller - left (forces and moments about spinner) (in body axes)/propeller derivatives') where this issue is occurring. The model is trying to compute the square root of a negative value, which leads to the domain error.
Here are some steps to resolve this issue:
1. Check the Model for Negative Inputs to sqrt:
Inspect block mentioned in the error message for computations involving square root function. Ensure inputs to sqrt can never be negative. Add checks around the sqrt function to handle potential negative inputs.
2. Use complex with sqrt if Necessary
If model is expected to work with complex numbers, follow suggestion in error message and use sqrt(complex(x)) instead of sqrt(x). This will allow square root function to accept negative inputs by treating them as complex numbers. However, this is only appropriate if dealing with complex numbers makes sense in the context of the model.
3. Review the Trim Conditions (xtrim, utrim, ytrim)
Ensure trimmed state(xtrim), input (utrim), and output (ytrim) vectors provided to linmod function are correct and physically meaningful. Incorrect trim conditions might result in the model being evaluated at an unrealistic point, leading to negative values where they are not expected.
4. Debugging the Model
Run model in Simulink using same trim conditions to see if the error can be reproduced outside of the linearization process. This might provide more insight into where and why the negative value is being generated.
Consider using "Step" feature of MATLAB if have custom scripts or functions that are part of the model computation, to identify exactly where the negative values are coming from.
5. Alternative Linearization Tools
Consider using the linearize function instead from Control System Toolbox, as it provides more robust and flexible options for linearizing Simulink models. Code would be like:
io = linio('Trim_model',...); % Define linearization inputs and outputs
sys = linearize('Trim_model',io,xtrim,utrim);
[Alin,Blin,Clin,Dlin] = ssdata(sys);
Resolving this issue will require a detailed review and redesign of part of Simulink model that leads to the square root of a negative number. Ensure that all physical and mathematical assumptions in your model are valid and that any operations that could result in complex numbers are intentionally designed to handle or avoid such cases.
Please refer to the following documentation-
Hope it helps!
Best Regards,
Simar

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!