Question

Write Matlab function script that you developed in such that it will take a real number...

Write Matlab function script that you developed in such that it will take a real number p and a desired tolerance TOL as input and will return the cube-root and number of iterations as output. You need to use a while(1) or infinite loop. Use your function to determine the cube roots of : (a) 81

I am getting stuck on how i can use a while loop for this. Any help would be much appreciated.

Homework Answers

Answer #1

PLEASE GIVE THUMBS UP, THANKS

SAMPLE OUTPUT :

code:


%Returns cube root of a no p
function value=cubicRoot(p,TOL)
%Set start and end for binary search
startt = 0; endd = p;
while (true)
mid=(startt + endd)/2;
error = abs(p-(mid*mid*mid));
  
%If error is less than TOL then mid is
%our answer so return mid
if (error <= TOL)
value= mid;
break;
end
  
%If mid*mid*mid is greater than p set
% endd = mid
if ((mid*mid*mid) > p)
endd = mid;
  
% If mid*mid*mid is less than p set
% startt = mid
else
startt = mid;
end
end
end

Know the answer?
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
Similar Questions
Solve the following problem using the MATLAB environment Write a function [approx_root, num_its] = bisection(f,a,b,tol) that...
Solve the following problem using the MATLAB environment Write a function [approx_root, num_its] = bisection(f,a,b,tol) that implements the bisection method. You function should take as input 4 arguments with the last argument being optional, i.e, if the user does not provide the accuracy tol use a default of 1.0e-6 (use varargin to attain this). Your function should output the approximate root, approx_root and the number of iterations it took to attain the root, num_its. However, if the user calls the...
Write a script (must be titled “NumIntF”) in MATLAB that calculates the integration of function f(x)=cos(x)...
Write a script (must be titled “NumIntF”) in MATLAB that calculates the integration of function f(x)=cos(x) . exp(sin x), Using numerical integration method. When the user runs the script, he/she is prompted to input the lower and upper limits for numerical integration, both in radians, and your program outputs the integration result. You can use built-in trigonometric functions and the exponential function, but you are not allowed to use any built-in function to do the integration. You must use a...
Name the script args.sh. The script will take any number of command line arguments. The script...
Name the script args.sh. The script will take any number of command line arguments. The script will print (echo) each of the command line arguments on its own line, and will then print the total number of arguments entered. You should use the special shell variables. One special variable contains all the command line arguments. There is another one that contains the number of command one arguments entered. This script is most easily completed with a for loop, although the...
Write a function in Matlab that takes as input the number of iterations k, the size...
Write a function in Matlab that takes as input the number of iterations k, the size n, and a sparse matrix A. Have this function run the Power method for k iterations on an initial guess the vector of 1’s and output the dominant eigenvalue and its corresponding eigenvector. Use only basic programming. Write out or print out your function.
Write a MATLAB function and test bench script code to solve the above simple RL/RC circuits...
Write a MATLAB function and test bench script code to solve the above simple RL/RC circuits by following the instructions noted below. The input signal and impulse response generation should be done in the function. The test bench script should be used only to call the function and for signal plotting purposes. No plotting should be done inside the function itself. Name your function L2_C Instructions: Input voltage ,x(t), can be AC or DC. Consider a variable ‘w1’ which can...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
In the previous assessment, you used a static set of named variables to store the data...
In the previous assessment, you used a static set of named variables to store the data that was entered in a form to be output in a message. For this assessment, you will use the invitation.html file that you modified in the previous assessment to create a more effective process for entering information and creating invitations for volunteers. Rather than having to enter each volunteer and create an invitation one at a time, you will create a script that will...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary rivals? How will the acquisition of Reebok by Adidas impact the structure of the athletic shoe industry? Is this likely to be favorable or unfavorable for New Balance? 2- What issues does New Balance management need to address? 3-What recommendations would you make to New Balance Management? What does New Balance need to do to continue to be successful? Should management continue to invest...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT