`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.
using matlab, and fibonacci. i have included the picture of the function fofx i believe problem...
I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a program that uses a for loop to calculate a Fibonacci sequence (NOT RECURSIVE!!!) up to a given position, starting with position 0. This function defines a Fibonacci sequence: If the number is 0, the function returns a 0 If the number is 1, the function returns a 1 If the number is higher than 1, it returns the sum of the previous two numbers...
4. One interesting property of a Fibonacci sequence is that the ratio of the values of adjacent members of the sequence approaches a number called "the golden ratio". Create a program that accepts the first two numbers of a Fibonacci sequence as user input and then calculates additional values in the sequence until the ratio of adjacent values converges to within 0.001 You can do this in a while loop by comparing the ratio of element k to element k...
(a) (4 points) Fill in the blanks in the following MATLAB function M file trap so that it implements the composilu trapezidul rulo, using a soquence of w -1,2, 4, 8, 16,... trapezoids, to approximatel d . This M file uses the MATLAB built-in function trapz. If 401) and y=() f(!)..... fr. 1)). 3= ($1, then the execution of z = trapz(x, y) approximates using the composite trapezoidal rule (with trapezoids). (Note that the entries of are labeled starting at...
I included a picture of what the union of set Un
represents
Problem C. Define a function f:R CX by the formula f(x) = cos(272) + i sin(2x). (a) Verify that f is a homomorphism from (R, +) to (CX,.). (b) Find im(f) and ker(f). (c) Check that f(Q) = {f(x): 2 € Q} coincides with the group UN-, UN ů {ze C]z* = 1} n = 1
Question #1 (15 Marks) a) (8 Marks) Answer the following questions with True or False. 1) 2) 3) Every basic solution in the assignment problem is necessarily degenerate. The assignment problem cannot be solved using the transportation technique. If the gradient vector of a function at a given point is zero, the point can only be a maximum or minimum. If a single-variable function has two local minima, it must have at least one local 4) maximum 5) The Golden...
MATLAB Problem
HW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the following math function 3 o-0.47x The input to the function is x and the output is y. Write the function such that x can be an array (use element-by-element operations) (15 pts) Use the function in (a) the command window to calculate y(-2) and y(5) (b) a script file HW7P2.m to determine y(x) for 0.001 Sx S 10 with 1000 points. Hint: Use the...
matlab only
Question 5: a.) Write an m-file using conditional statements to evaluate the following function, assuming that the scalar variable x has a value. The function is for x <-1 - 3e y=2+cos(m) for-1 x<5 y 10-5)+1 for r 2 5 Use your file to evaluate y for x5, x-3, and x-15, and Use keyboard entry for values of x. b.) Use a for loop in the above file to plot the above function over the interval -2x <10....
Please I need help with MATLAB .. PLease help me . Thankyou Write Matlab code to plot a 2D sinc function over a 2D cartesian grid where x ranges from 100 to 355 and y ranges from 0 to 255 and the sinc is centered at somewhere not midway in the grid. First plot the grid, and then plot the function on the grid (both as grayscale and as a surface plot). Comment the code well, generate the figures and...
please solve then upload matlab code
Thanks
1. The function f(z, y) (a-x)2 + b(y-12)2 is called Rosenbrock's banana function. It is often used as a benchmarking test for optimization algorithms becatse it is easy to find the minimum by hand but often very difficult to find numerically. Throughout the problem, we will use the values a = 2 and b 10. You can plot this function using the following code: x3:0.1:3; y = -10:0.2:10; Cx,Ymeshgrid(x,y); Z(2-X).2 10* (Y-X. 2)....
In matlab, I keep getting the same issue for this problem can
someone help?
"myrowproduct.m" >> Filename myrowproduct (A,x) Undefined function or variable 'Filename' Did you mean: mfilename : myrowproduct (A, x) Undefined function or variable 'myrowproduct' function y = myrowproduct(A,x); function y my rowp roduct (A, x); Error: Function definition not supported in this context. Create functions in code file. (, 2,,)T 4. The product y Ax of an m x n matrix A times a vector x= can...