Borrar filtros
Borrar filtros

Why do I have this error when I try to derivative a function with variable x?

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 31 de Mayo de 2021
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)
...
  1 comentario
chuyen hoangcao
chuyen hoangcao el 1 de Jun. de 2021
Editada: chuyen hoangcao el 1 de Jun. de 2021
Wow, thank you so much for helping me answer the question. The numerical differentiation is not wrong, but in matlab function block it does not support for symbolic differentiation with syms U(x). Maybe I will use the numerical differentiation.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Deployment, Integration, and Supported Hardware en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by