Question

2. Write a MATLAB code that uses the Golden Section Search Method to find the minimum of f(x) = r-r , starting with the interval [0, 2]. Iterate until the width of the interval is less than 0.1

0 0
Add a comment Improve this question Transcribed image text
Answer #1

clear all
clc
syms x
p=linspace(0,2,400);
f(x) = x^2-x;
plot(p,f(p));%hold on
phi=(1+sqrt(5))/2
a=0;
b=2;
d=b-(b-a)/phi;
    c=a+(b-a)/phi;
k=abs(c-d);

for i=1:15
    if f(c)>f(d)
     b=d;
    end
    if f(d)>f(c)
     a=c;
    end
    d=b-(b-a)/phi;
    c=a+(b-a)/phi;

end


v=[f(a) f(b) f(c) f(d)];
min(v)

A MATLAB R2018a HOME PLOTS EDITOR PUBLISH VEW rch Documentation rajen ▼ Find Files -Compare ▼ GoTo▼ Comment 9e.r Breakpoints Run Run and Advance Run and New Open Save Print Find Advance Time aC:Program FilesMATLABR201abinwin64 Editor-work&m clear al1 ขึ้-p-linspace (0,2,400); 5- f(x)-x^ 2-х; 6- plot (p,f (p));%hold on 7-phi (1+sqrt (5))/2 8- a=0; -b-2: 10-d-b-(b-a)/phi: c-a+ (b-a)/phi: 12k-abs (c-d); 13 14 15-Efor i-1:15 16- if t(c)>t (d) b-d: end if t(d) > (c) 18- 20 21- 22- 23- 24 25-Lend 26 27 28v-[f (a) f(b) f (c) f(d): 29-min(v) a-c: end d-b-(b-a)/phi: c-a+ (b-a)/phi: scnpt Ln 9 Col5

OUTPUT

Add a comment
Know the answer?
Add Answer to:
2. Write a MATLAB code that uses the Golden Section Search Method to find the minimum...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT