Why do I have this error when I try to derivative a function with variable x?
1 次查看(过去 30 天)
显示 更早的评论
I dont know why i have this error. Please help me.
This is my code:
function [dX,s,x,o,dU,B] = fcn( nref,dnref,ddnref,e1,de1, u)
lamda1 = [15.6 10.6;10.6 10.4];
s = de1+ lamda1*e1;
g1 = 5;
g2 = 1;
g3 = 1;
n = nref-e1;
dn = dnref+lamda1*e1-s;
x = [e1';s'];
M = [g1+2*g2*cos(n(2)) g3+g2*cos(n(2));g3+g2*cos(n(2)) g3];
C = [-g2*sin(n(2))*dn(2) -g2*sin(n(2))*(dn(1)+dn(2));g2*sin(n(2))*dn(1) 0];
Y = -M^-1*C*s;
A = [-lamda1*e1+s;Y;dnref;ddnref];
b1 = zeros(2,2);
b2 = zeros(4,2);
B = [b1;M^-1;b2];
dX = A+B*u;
U = [x(1)^2;x(1)*x(2);x(2)^2;x(3)^2;x(3)^2*cos(n(2));x(3)*x(4);x(3)*x(4)*cos(n(2));x(4)^2];
o = diff(U,x)*dX;
dU = diff(U,x);
Coder error: Difference order N must be a positive integer scalar in the range 1 to intmax('coder.internal.indexInt') in 'o' function.
0 个评论
采纳的回答
Sulaymon Eshkabilov
2021-5-31
Hi,
here you are trying to compute numerical differentiation and thus, you need to use these commands:
o = (diff(U)./diff(x))*dX;
dU = diff(U)./diff(x);
Should you want to get symbolic differentiation, then you'd need introduce symbolic variables, e.g.:
syms U(x)
dU = diff(U(x), x)
ddU = diff(dU, x)
...
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!