フィルターのクリア

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.

採用された回答

Sulaymon Eshkabilov
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)
...
  1 件のコメント
chuyen hoangcao
chuyen hoangcao 2021 年 6 月 1 日
編集済み: chuyen hoangcao 2021 年 6 月 1 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDeployment, Integration, and Supported Hardware についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by