why do i receive this error

조회 수: 4 (최근 30일)
Mohammad Adeeb
Mohammad Adeeb 2021년 3월 21일
댓글: Sergey Kasyanov 2021년 3월 22일
x=0.1;
x= 0:0.1:1;
yic =[1 -2] ' ;
for i=1:(length(x)-1)
K11 = fn (x, yic);
K21 = fn (x , yic);
K12 = fn ((x + h) , (yic + (h*K11)) , (yic + (h*K21)));
K22 = fn ((x + h),(yic + h*K11) , (yic + h*K21));
y1 = ( yic + 0.5*h*(K11 + K12 ));
y2 = ( yic + 0.5*h*(K12 + K22));
end
function f = fn( x , yic )
dy = yic(2);
dy2 = 2*yic(1)-yic(2);
end
when i run the code this error appear :
''
Output argument "f" (and maybe others) not assigned during call to "HW2>fn".
Error in HW2 (line 22)
K11 = fn (x, yic);
''

답변 (1개)

Sergey Kasyanov
Sergey Kasyanov 2021년 3월 21일
Hello!
You don't define f in fn function.
Are you want to return f = [fy, fy2]? In that case:
function f = fn( x , yic )
dy = yic(2);
dy2 = 2*yic(1)-yic(2);
f = [dy, dy2];
end
Also you have an error in another lines. Maybe you should to correct it in that way:
K12 = fn ((x + h) , [(yic + (h*K11)) , (yic + (h*K21))] );
K22 = fn ((x + h), [(yic + h*K11) , (yic + h*K21)] );
  댓글 수: 11
Walter Roberson
Walter Roberson 2021년 3월 21일
Writing it that way is just a more compact way of writing it.
Sergey Kasyanov
Sergey Kasyanov 2021년 3월 22일
It is more readable.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by