Syms function optimization. How to solve function (NLE) for minimum value?

조회 수: 3 (최근 30일)
Akshayy Garg
Akshayy Garg 2018년 1월 23일
댓글: Walter Roberson 2018년 1월 23일
I have derived the equation following syms of variable D s n n_pass as the following function (fun).
fun=100000*(250000000/(549*n*pi*(2*s + 1/1000)) - 2000*n_pass + (625000000*s)/(157*n*(D^2 - 5312662293228351/147573952589676412928)))^2 + 100000*(48000000000/(7*n_pass) - 1000000000000*n*s*((157*D^2)/100 - 834087980036851107/14757395258967641292800))^2 + 7850*D^2*n*n_pass*(2*s + 1/1000) + (102400*n*(2*s + 1/1000))/(627*n_pass*pi)
I have to minize the following function. How to do it using MATLAB optimization functions. Please help?
  댓글 수: 5
Akshayy Garg
Akshayy Garg 2018년 1월 23일
I know that. But I alraedy have the equation with the syms variable in U as follows: U =
100000*(250000000/(549*n*pi*(2*s + 1/1000)) - 2000*n_pass + (625000000*s)/(157*n*(D^2 - 5312662293228351/147573952589676412928)))^2 + 100000*(48000000000/(7*n_pass) - 1000000000000*n*s*((157*D^2)/100 - 834087980036851107/14757395258967641292800))^2 + 7850*D^2*n*n_pass*(2*s + 1/1000) + (102400*n*(2*s + 1/1000))/(627*n_pass*pi) I want to replace D,s,n,n_pass in the equation to x(1),x(2),x(3), x(4) directly. How to do that?
Walter Roberson
Walter Roberson 2018년 1월 23일
subs(U, [D, s, n, n_pass], x(1:4))

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

답변 (1개)

Torsten
Torsten 2018년 1월 23일
fun=@(D,s,n,n_pass) 1000*....;
x0=[1 1 1 1];
[x,fval,exitflag,output] = fminunc(@(x)fun(x(1),x(2),x(3),x(4)),x0)
Best wishes
Torsten.
  댓글 수: 2
Akshayy Garg
Akshayy Garg 2018년 1월 23일
편집: Akshayy Garg 2018년 1월 23일
I got my earlier function stored in var U.I tried this way: U=1000*....; % I cannot write this directly in fun because I get the values from other equations also. This is the final objective function fun=@(D,s,n,n_pass)U x0=[10e-3 1e-3 5e3 20] [x,fval,exitflag,output]=fminunc(@(x)fun(x(1),x(2),x(3),x(4)),x0)
Did not work?
Regards Akshayy
Torsten
Torsten 2018년 1월 23일
Why don't you use the code from above ?
fun=@(D,s,n,n_pas) U won't work, and you forgot the "x0" in your call to "fminunc".
Just do the following:
1) Remove all "syms" declarations in your code.
2) Copy the code from above and insert your fun-definition in the line fun=@(D,s,n,n_pass) 1000*...
3) Run the script.
Best wishes
Torsten.

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by