A problem with differentiating

I want to differentiate detk to f.But after I run it,my matrix c is empty. Can anyone tell me what is wrong? Thanks!
f = 0.001;
x = 1:f:5;
w = 2*pi*x;
k = [cos(w), 0; 0, cos(w) ];
detk = k(1,1)*k(2,2)-k(2,1)*k(1,2);
c = diff(detk)/f;
plot(x,detk,x,[0 c],'r:')

回答 (1 件)

per isakson
per isakson 2014 年 5 月 10 日
編集済み: per isakson 2014 年 5 月 10 日

0 投票

detk is evaluated to a scalar and thus c will be empty.
I find it easier to debug functions than scripts. Thus, I created a function, cssm. Next I set a break point at the line, w = 2*pi*x;, and stepped through the remaining lines. The values of the variables may be inspected in many ways. I kept an eye on the Workspace window while stepping.
function cssm
f = 0.001;
x = 1:f:5;
w = 2*pi*x;
k = [cos(w), 0; 0, cos(w) ];
detk = k(1,1)*k(2,2)-k(2,1)*k(1,2);
c = diff(detk)/f;
plot( x,detk, x,[0 c], 'r:' )
end
Here are some links on debugging in Matlab

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

質問済み:

2014 年 5 月 10 日

編集済み:

2014 年 5 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by