フィルターのクリア

the program is plotted once, then showing error, is something error in program

1 回表示 (過去 30 日間)
SAHIL SAHOO
SAHIL SAHOO 2022 年 7 月 21 日
回答済み: KSSV 2022 年 7 月 21 日
format long
a = 0;
b = 4;
h = 0.1;
k = 0.033;
L = 0.5;
s = 0.1;
tc = 70E-9;
n = (b-a)/h ;
t = a + (0:n)*h;
y(1) = 0;
func1 = @(y) ((-(s^2)*k/tc)*sin(y - pi/2) + L*(s^2)/(2*tc)*sin(y + pi/2)/sqrt(1 + cos(y + pi/2)));
for i = 1:n
k1 = func1(y(i));
k2 = func1 (y(i)+(k1/2)*h);
k3 = func1 (y(i)+(k2/2)*h);
k4 = func1(y(i)+(k3*h));
y(i+1) = y(i) + (h/6)*(k1+(2*(k2+k3))+k4);
end
plot(t,y)
==================================
output:- Error using plot
Vectors must be the same length.
  2 件のコメント
KSSV
KSSV 2022 年 7 月 21 日
It is working fine...clear you variables once and run the code.
a = 0;
b = 4;
h = 0.1;
k = 0.033;
L = 0.5;
s = 0.1;
tc = 70E-9;
n = (b-a)/h ;
t = a + (0:n)*h;
y(1) = 0;
func1 = @(y) ((-(s^2)*k/tc)*sin(y - pi/2) + L*(s^2)/(2*tc)*sin(y + pi/2)/sqrt(1 + cos(y + pi/2)));
for i = 1:n
k1 = func1(y(i));
k2 = func1 (y(i)+(k1/2)*h);
k3 = func1 (y(i)+(k2/2)*h);
k4 = func1(y(i)+(k3*h));
y(i+1) = y(i) + (h/6)*(k1+(2*(k2+k3))+k4);
end
whos t y
Name Size Bytes Class Attributes t 1x41 328 double y 1x41 328 double
plot(t,y)
SAHIL SAHOO
SAHIL SAHOO 2022 年 7 月 21 日
why I'm geting y 1 * 101 and you got 1* 41

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

採用された回答

KSSV
KSSV 2022 年 7 月 21 日
You initialize the value of y before for loop.
y = zeros(1,n) ;
y(1) = 0;
func1 = @(y) ((-(s^2)*k/tc)*sin(y - pi/2) + L*(s^2)/(2*tc)*sin(y + pi/2)/sqrt(1 + cos(y + pi/2)));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by