I cannot remove 0 elements of a symbolic array

4 ビュー (過去 30 日間)
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2022 年 2 月 1 日
Hello friends!
Consider the following commands
syms x sigma(x)
par=sym('par%d', [1 2],'positive');
sigma(x)=par(1)+par(2)*x;
D_sigma=[sigma diff(sigma) diff(sigma,2) diff(sigma,3)];
D_sigma
nonzeros(D_sigma)
D_sigma(x) =
[par1 + par2*x, par2, 0, 0]
ans(x) =
[par1 + par2*x, par2, 0, 0]
I really have no idea why this does not work!!!!!!!
Any help!
Thanks in advance!
Babak

採用された回答

Walter Roberson
Walter Roberson 2022 年 2 月 1 日
syms x sigma(x)
par=sym('par%d', [1 2],'positive');
sigma(x)=par(1)+par(2)*x;
D_sigma=[sigma diff(sigma) diff(sigma,2) diff(sigma,3)];
D_sigma
D_sigma(x) = 
DSX = D_sigma(x);
nonzeros(DSX)
ans = 
The reason you had a problem is that your D_sigma is a symbolic function, not a vector.
  3 件のコメント
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2022 年 2 月 1 日
Thanks Walter for your kins explanation!
Although I am a mathematician I found coding a bit annoying but will improve over time!

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by