how to solve 'Diffrence order N must be positive ..." error
显示 更早的评论
Hello, I'm trying some simulation about dynamics of gimbal using simulink. the input is ramp signal and there are several matlab function in the subsystem of the simulation. when i run the program, error was showing and it said "Difference order N must be positive integer scalar in the range 1 to intmax('coder.internal.indexInt')". I dont understand the meaning of N in that sentence. please help me.
6 个评论
Walter Roberson
2018-7-18
Do any of the matlab functions call diff() ?
Is it possible they might be calling diff() expecting it to be the symbolic diff routine?
Qalisha Putri
2018-7-18
Jan
2018-7-18
Please post the relevant part of the code.
Walter Roberson
2018-7-18
If you are using sym() or syms anywhere in the code, then it can only be used with acceleration turned completely off (though maybe it could be forced to work with the first level of acceleration, I am not certain.)
There are two important functions named diff() . diff() applied to a symbolic expression is the calculus differentiation operator. This diff() is part of the Symbolic Toolbox, but nothing in the Symbolic Toolbox can be compiled.
diff() applied to a numeric array is a numeric difference operator. For example, for a numeric row vector X, diff(X) is X(2:end)-X(1:end-1) . There is no problem compiling the numeric diff()
Rhys Davies
2019-4-25
Did you get this to work? I have the exact same problem
Walter Roberson
2019-4-25
Simulink is only really happy with things it can compile, but nothing in the symbolic toolbox can be compiled. If you need to take a symbolic differentiation, you should, if possible, work it out symbolically at the MATLAB level, and use matlabFunction() to convert the symbolic version into a formula that can be evaluated numerically, which you would then copy into the MATLAB Function Block.
There are two different diff() functions.
When the first parameter is numeric, the diff that is called is the numeric difference routine, such as diff(x) meaning the same as x(2:end,:) - x(1:end-1,:) . For numeric diff(), if there is a second parameter, it must be empty or the difference order -- roughly speaking, the number of times that the above is applied to get successive differences. The difference order must be a positive integer. If there is a third parameter, it must be the dimension to operate along instead of the first non-scalar dimension.
When the first parameter is symbolic, the diff that is called is the symbolic calculus differentiation routine, such as diff(sin(x)+x^2,x) -> cos(x)+2*x . The second parameter is normally a variable to differentiate on, but can also be a positive integer indicating the number of times to differentiate with respect to the default variable.
When you get the error message about difference order must be positive, then typically it is because you tried to call the symbolic differentiation in a context where the first parameter is not symbolic, or in a context (such as Simulink MATLAB Function Block) where the symbolic diff() routine is not on the path.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Code Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!