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

1 Ansicht (letzte 30 Tage)
Gus Hopkins
Gus Hopkins am 22 Nov. 2019
Beantwortet: Marco Riani am 23 Nov. 2019
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 Kommentar
Walter Roberson
Walter Roberson am 22 Nov. 2019
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Marco Riani
Marco Riani am 23 Nov. 2019
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

Kategorien

Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by