Undefined function sgn(z)

6 ビュー (過去 30 日間)
Advait Sinha
Advait Sinha 2019 年 6 月 19 日
回答済み: Abhishek Kumar 2019 年 6 月 26 日
close all;
dt = 0.01;%time step
k=1;
m=1;%initial parameters
u1 =1;
u2 =2;
z = u2-u1;
c = sgn(z);
h = c*z;
v=1;
a=1;
tend=10;
t=0;
i=1
while t < tend-2*dt
vh=v(i)-dt*k*h(i)/ (2*m);
h(i+1)= z(i)+ dt*vh;
a(i+1)= -k*h(i+1)/2;
v(i+1)= vh + dt*a(i+1)/2;
i = i+1;
t = t + dt
end
plot(linspace(0,tend,tend/dt),z);
  1 件のコメント
Stephen23
Stephen23 2019 年 6 月 19 日
編集済み: Stephen23 2019 年 6 月 19 日
Did you actually intend to use sign ?

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

回答 (1 件)

Abhishek Kumar
Abhishek Kumar 2019 年 6 月 26 日
Hi Advait
There is no function called 'sgn' in matlab. It seems that you wanted to use 'sign' to get the sign of the variable and then make it positive.
you can use to command window to find whether a function exists or not, and if it exists what it does. eg.
>> help sign

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by