why 'for' doesnt affect inner function?

조회 수: 5 (최근 30일)
Witold Sure
Witold Sure 2018년 6월 23일
댓글: Witold Sure 2018년 6월 23일
hello Guys! im trying to have variable 'i' included in outside function called @witodefinicje. I wanna run ode for different 'i' inside @. The problem is that inside @ it stays the same. I have no clue whats wrong, please help
for i=0:50:200
j=j+1;
t = 0:0.01:20;
X0 = zeros(12,1);
X0(10,1) = -pi/2;
X0(11,1) = pi/2;
[t X] = ode45(@witodefinicje, t, X0);
A(j,1)=max(X(600:1800,8));
A(j,2)=i;
end
  댓글 수: 2
Jan
Jan 2018년 6월 23일
Today I've formatted the code for you. Please do this by your own in following questions. Thanks. See the "{} Code" button.
What is "an outside function"? What does "inside @" mean? What stay the same?
Witold Sure
Witold Sure 2018년 6월 23일
thank you, Jan. An outside function is a function included in other file then one you see. Inside @witodefinicje, parameter 'i' does not change, even though 'for' should work. Or am I wrong?

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

채택된 답변

Jan
Jan 2018년 6월 23일
편집: Jan 2018년 6월 23일
A bold guess:
X0 = zeros(12,1);
X0(10,1) = -pi/2;
X0(11,1) = pi/2;
t = 0:0.01:20;
for i = 0:50:200
[t, X] = ode45(@(t,x) witodefinicje(t, x, i), t, X0);
j = j + 1;
A(j,1) = max(X(600:1800, 8));
A(j,2) = i;
end
And in the function to be integrated:
function witodefinicje(t, x, i)
...
  댓글 수: 1
Witold Sure
Witold Sure 2018년 6월 23일
I suspected I've got to regard to fuction parameters, however I didn't know how to code it, due to too little experience. Thanks Jan, you're the man!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by