This basic problem demonstrates the while-loop. (USE MATLAB)
Write a Matlab function called steps that takes one scalar as an input argument and returns two scalars as output arguments. If it is called this way [n, d_left] = steps(d), then it sets n equal to the minimum number of steps required to move from a distance of one foot away from a wall to a distance less than d feet from the wall. The first step is 1/2 foot. If a second step is required, it is 1/4 foot. If a third step is required, it is 1/8 foot, and so forth, with each subsequent step being half the distance of the step before. The second output, d_left, is the distance to the wall after n steps. Here is an example run:
>>[n,d_left] = steps(0.001)
n =
10
d_left =
9.7656e-04
MATLAB CODE------------------------------ function [n,d_left]=steps(d) % Error check if(d>=1) error('distance must be less than 1 feet') end %initiate output n=0; d_left=1; dnew=1; while(dnew>d) dnew=dnew/2; n=n+1; end d_left=abs(d-dnew*2) end
OUTPUT------------
steps(0.001) d_left = 9.5312e-04 ans = 10
This basic problem demonstrates the while-loop. (USE MATLAB) Write a Matlab function called steps that takes one scalar...
MATLAB Write a function called next_prime that takes a scalar positive integer input n. Use a while-loop to find and return k, the smallest prime number that is greater than n. Feel free to use the built-in isprime function (do not use nextprime). MATLAB
Write your answer code into one function file on matlab The spiral of Archimedes. The spiral of Archimedes is a curve described in polar coordinates by the equation r= kθ Where r is the distance of a point from the origin, and d is the angle of that point in radians with respect to the origin. Write a function file to compute the spiral of Archimedes with varying number of inputs (no input, one input, two inputs) for k, 0 and varying number of...
Write a MATLAB script, using either a single or nested for-loop, that will print the factorials for the numbers between 1 and 100 (inclusive). The factorial of n (n!) is the product of the positive integers less than or equal to n. For example: 3! = 3 * 2 * 1. For this question you cannot use the built-in MATLAB factorial function, but you can use other MATLAB functions if you wish. MATLAB code!MATLAB code!MATLAB code!MATLAB code!
(Requires use of MATLAB) Write a function myfibonacci (n), which prompts all elements of the fibonacci sequence to the screen which are smaller than or equal n. Base your code on a while loop. Test your code with n=0, n=1, n=5 and n=25.
The problem demonstrates the use of the random number generator to recover previously generated random numbers Write a function called randi test that takes two scalar positive integer arguments maxi and n, and retums two output arguments: a row vector of n2 elements and and n-by-n matrix. The two output arguments must contain the exact same set of random integers that fall between 1 and maxi Do this using the random number genertor, not by reshaping the data Example n,v-randi...
*** write in matlab *** use for loops largestfactor_for Write a function that takes a positive integer greater than one and returns its largest factor (other than itseir). You must use a for loop to solve this problem. Do not use functions factor), primes(), and divisors() . Do not use while loops Do not use vectorized code. alargestfactor 105) 35 largestfactor_for Write a function that takes a positive integer greater than one and returns its largest factor (other than itseir)....
python program sample output Problem 3 (Taking User Input) Write a function called userGuess(n) that takes an integer n as an argument. This function should display n to the user and prompt them to enter the number num that is the largest power of 2 less than or equal to n. Have your function return the user's input num (it will be used in the next problem) Problem 4 (Making a Game) Finally, create a main() function for your program....
PLEASE USE MATLAB This is a basic problem that illustrates the concept of strings. A palidrome is a string of characters that is read the same forwards as it is backwards. For example, racecar' is a palindrome; reversing the order of the characters leaves the string unchanged. Write a otherwise. function called isPalindrome that accepts one input and returns one output. The input str is a string of characters, and the output is 1 if str is a palindrome, For...
This code NEEDS TO BE DONE IN MATLAB!!!! Write a function that takes one input, an integer number n, and returns a matrix that is nxn, where the value of each number is the distance from the upper-left to bottom-right diagonal. (Use while loops if you can!) Numbers below the diagonal should be negative, and numbers above the diagonal should be positive. For example, if your input was 5, your output would be: 0 1 2 3 4 -1 0...
Question: MATLAB: In a file called mywhile.m, and using the keyword while, write a function to find the first integer larger than one (n) such that (2n)! > 5n.Then write a more general function, mywhile2.m, returning the first integer such that (an)! > xn for any a and any x. Show your results for a = 3 and x = 32. So far I have for part a i have: %Description: This function would find the first integer larger than...