Matlab Consider the function fx 02sinx2 05cosx2 Write a sc

Matlab: Consider the function

f(x) = 0.2*sin(x^2) + 0.5*cos(x/2)

Write a script file that uses the bisection method to approximate a root of f. You want to find a root of f that is between 0 and 3.5. Do this by constructing a sequence of brackets, as described in the course notes.

1. Choose an appropriate starting bracket [a b]. One way to do this is to plot the function f(x). You can do this using the Matlab installation in the lab.

2. Make sure you call this initial bracket \"init_bracket\". It should be an array of length 2. (Use this name or the grading program will get confused.) Make sure your solution doesn\'t change init_bracket once you have defined it.

3. Compute 10 iterations of the bisection formula, to get the 10th bracket in the sequence.

4. Call this 10th bracket \"final_bracket\". Note that final_bracket will be a vector of length 2.

Solution

Hi, i want to aware you that MATLAB is paid software you cannot use it for personal usage.

On the other hand, SCILAB is a free alternative of the MATLAB.

Most of the Things that you can do with matlab also you can do with scilab.

you can downlaod scilab for free from ( http://www.scilab.org/download/latest )

So i post TWO SCRIPTS:

1. Matlab script fot the given Problem is:

#############################################################   MATLAB code start

% Bisection method
% change the value of init_bracket as per your neeed
% to change the function please change the expression of
% func_lower_value and func_upper_value in the beggining and in the If Else loops.
% to change number of iteration change the variable no_iter

init_bracket = [0 3.5];
no_iter = 10;

% func = 0.2*sin(x^2) + 0.5*cos(x/2);

        x1=init_bracket(1);
        x2=init_bracket(2);
        func_lower_value = 0.2*sin(x1^2) + 0.5*cos(x1/2) ;
        func_upper_value = 0.2*sin(x2^2) + 0.5*cos(x2/2) ;
        x_mean = (x1+x2)/2;
           

if (func_lower_value<func_upper_value)
    for i=1:1:no_iter
      

        func_lower_value = 0.2*sin(x1^2) + 0.5*cos(x1/2) ;
        func_upper_value = 0.2*sin(x2^2) + 0.5*cos(x2/2) ;
        func_mean_value = 0.2*sin(x_mean^2) + 0.5*cos(x_mean/2) ;
      
        if (func_mean_value<0)
            x1=x_mean;
            x2=x2;
            x_mean = (x1+x2)/2;
        end
      
        if (func_mean_value>0)
            x1=x1;
            x2=x_mean;
            x_mean = (x1+x2)/2;
        end
      
    end
end

if (func_lower_value>func_upper_value)
  
    for i=1:1:no_iter
      

        func_lower_value = 0.2*sin(x1^2) + 0.5*cos(x1/2) ;
        func_upper_value = 0.2*sin(x2^2) + 0.5*cos(x2/2) ;
        func_mean_value = 0.2*sin(x_mean^2) + 0.5*cos(x_mean/2) ;
      
        if (func_mean_value<0)
            x1=x1;
            x2=x_mean;
            x_mean = (x1+x2)/2;
        end
      
        if (func_mean_value>0)
            x1=x_mean;
            x2=x2;
            x_mean = (x1+x2)/2;
        end
      
    end
    final_bracket=[x1 x2];
    fprintf(\'\ final bracket is: [%f ,%f]\',final_bracket(1),final_bracket(2));
end

    fprintf(\'\ \ ^^^^^-----_____     Have a Nice Day     _____-----^^^^^\ \');
  


###################################################################    MATLAB Code end

2. SCILAB script for given problem

###################################################################    SCILAB Codestart

###################################################################    SCILAB Code end

Matlab: Consider the function f(x) = 0.2*sin(x^2) + 0.5*cos(x/2) Write a script file that uses the bisection method to approximate a root of f. You want to find
Matlab: Consider the function f(x) = 0.2*sin(x^2) + 0.5*cos(x/2) Write a script file that uses the bisection method to approximate a root of f. You want to find

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site