Question
using matlab, and fibonacci. i have included the picture of the function fofx
1. Write a function file to estimate the local maximum or minimum or the function fofx (use the last assignment one for testi
function [y]=fofx(x) y=x^3+2x^2-111*x+108 end

i believe problem should say of, not or the function fofx

Matlab is a program to do coding on, Golden Sequence is just Fibonacci
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

clc%clears screen
clear all%clears history
close all%closes all files
format long
disp('For minimum');
golden(@fofx,-10,7,1e-5,'min')
disp('For maximum');
golden(@(x) -fofx(x),-10,7,1e-5,'max')
function golden(fofx,a,b,epsilon,s)
iter= 50; % maximum number of iterations
tau=double((sqrt(5)-1)/2); % golden proportion coefficient, around 0.618
k=0; % number of iterations
x1=a+(1-tau)*(b-a); % computing x values
x2=a+tau*(b-a);
f_x1=fofx(x1); % computing values in x points
f_x2=fofx(x2);
while ((abs(b-a)>epsilon) && (k<iter))
k=k+1;
if(f_x1<f_x2)
b=x2;
x2=x1;
x1=a+(1-tau)*(b-a);
  
f_x1=fofx(x1);
f_x2=fofx(x2);
  
else
a=x1;
x1=x2;
x2=a+tau*(b-a);
  
f_x1=fofx(x1);
f_x2=fofx(x2);
  
end
  
k=k+1;
end
% chooses minimum point
if(f_x1<f_x2)
if(strcmp(s,'max'))
f_x1=-f_x1;
end
sprintf('x_%s=%f', s,x1)

sprintf('f(x_%s)=%f ', s,f_x1)
else
if(strcmp(s,'max'))
f_x2=-f_x2;
end
sprintf('x_%s=%f', s,x2)
sprintf('f(x_%s)=%f ', s,f_x2)
end
end
function y=fofx(x)
y=(x.^3+2*x.^2-111*x+108);
end

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
using matlab, and fibonacci. i have included the picture of the function fofx i believe problem...
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