Attempting to get fminsearch to work. Likely a silly mistake.

조회 수: 1 (최근 30일)
Gus Hopkins
Gus Hopkins 2019년 11월 22일
답변: Marco Riani 2019년 11월 23일
I am writing code to simulate a double pendulum, whose two natural frequencies (wn) should be 2 and 5hz. I would like to optimize L1 and L2 (arm lengths) with fminsearch in order to bring (wn) to 2 and 5 hz.
My difficulty seems to lie in creating the cost function which is being used with fminsearch. What I have written is my best guess, which currently yields an error.
In short:
I am attempting to determine L1 and L2 such that wn(1) and wn(2) of the system are 2, and 5 hz respectively, and am having trouble setting up the function that interfaces with fminsearch itself.
Any help would be greatly appreciated. Thank you.
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 11월 22일
Why are you passing m1 and m2 into double pendulum cost function when that function does not accept them as arguments and does not use them?
Why bother to search at all? You know that for unbound searches the minimum of (x1-a)^2+(x2-b)^2 can only be when x1=a and x2=b so there is no point trying other values.

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

답변 (1개)

Marco Riani
Marco Riani 2019년 11월 23일
Dear Gus,
The MATLAB sintax to make fminsearch work is
L1 = 0.0337; % Length of arm 1 (Rough guess)
L2 = 0.0166; % Length of arm 2 (Rough guess)
Double_Pendulum_Cost = @(wn) ((wn(1)-12.57)^2+(wn(2)-31.42)^2);
sopt = fminsearch(Double_Pendulum_Cost,[L1 L2]); % Minimize L1 and L2
Of course, as Walter was suggesting: "why bother to search at all?". in this case sopt is
12.5700 31.4200
irrispective of the values of L1 and L2
Hope it helps
Marco

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by