Você está na página 1de 3
7. Create a 3 x Smatrix. Perform each of the following using only vectorized code: © Find the maximum value in each column = Find the maximum value in each row = Find the maximum value in the entire matrix 11. Write a function repvec that receives a vector and the number of times each element is to be duplicated. The function should then retum the resulting vector. Do this, problem using built-in functions only, Here are some examples of calling the function: 12. The mathematician Euler proved the following: Poylitay 6 a7 9716 Rather than finding a mathematical proof for this, try to verify whether the conjecture seems to be true or not. (Note: Two basic ways to approach this are choosing a number of terms to add or loop until the sum is close to x”/6.) 1, Write a function that will receive as an input argument a temperature in degrees Fahrenheit, and will retum the temperature in both degrees Celsius and Kelvin. The conversion factors are C = (F - 32) * /9 and K = C + 273.16. 3.A vector can be represented by its rectangular coordinates x and y or by its polar coordinates r and @. For positive values of x and y, the conversions from rectangular to polar coordinates in the range from 0 to 2 are r= y/x? + y? and 8 = arctan(y/x), The function for arctan is atan. Write a function recpo! to receive as input arguments the rectangular coordinates and return the corresponding polar coordinates. 8 Write a function that will receive an integer n and a character as input arguments, and will print the character n times. E 25, The resistance R in ohms of a conductor is given by R = + where Eis the potential in volts and [is the current in amperes. Write a script that will: = Call a function to prompt the user for the potential and the current. = Call a function that will print the resistance; this will call a subfunction to calculate and return the resistance, Write the functions as well 26. The power in wattsis given by P = El. Modify the program in Exercise 25 to calculate ‘and print both the resistance and the power. Modify the subfunction so that it calculates and returns both values. 28, The geographic coordinate system is used to represent any location on Barth as ‘a combination of altitude and longitude values. These values are angles that can be vwnitten in the decimal degrees (DD) form or the degrees, minutes, seconds (DMS) form just lke time For example, 24 5° is equivalent to 24°30'0". White a script that wll prompt, the user for an angle in DD form and will print in sentence format the same angle in DMS form. The script should error-check for invalid user input. The angle conversion is to be done by calling a separate function in the script. An example of running the script is Enter an angle in decimal degrees form equivalent to 24 a 4.56 degrees 34. Write a menu-cdriven program to investigate the constant n. Model it after the program that explores the constant e Pi (n) is the ratio of a citcle's circumference to its diameter. Many mathematicians have found ways to approximate x. For example, Machin’s formula is 4 arctan(+) ~ arctan( 51, 5) 239, Leibniz. found that x can be approximated by: 44 “T3765 7t9 ‘This is called a sum of a series. There are six terms shown in this series. The first term is 4, the second term is -4/3, the third term is 4/5, and so forth. For example, the menu-driven program might have the following options: ‘= Print the result from Machin’s formula = Print the approximation using Leibniz’s formula, allowing the user to specify how many tems to use, = Print the approximation using Leibniz’s formula, looping until a “good” approximation is found. » Exit the program. 3. Write a function prodby2 that will receive a value of a positive integer n and will calculate and return the product of the odd integers from 1 to n (or from 1 to n= 1ifn is even). 7. Write a script that will: = Generate a random integer in the range from 2 to 5 = Loop that many times to = Prompt the user for a number ‘= Print the sum of the numbers entered thus far with one decimal place 14. Write a function that will receive a matrix as an input argument, and will calculate and retum the overall average of all numbers in the matrix. Use loops, not built-in functions, to calculate the average. 23. The inverse of the mathematical constant e can be approximated as follows’ (-3) White a script that will loop through values of n until the difference between the approximation and the actual value is less than 0.0001. The script should then print out the built-in value of e* and the approximation to four decimal places, and also print the value of n required for such accuracy. ‘7. The eccentricity of an ellipse is defined as Pe where ais the semimajor axis and bis the semiminor axis of the ellipse. A script prompts the user for the values of a and b Since division by 0 is not possible, the script prints an error message if the value of a is 0 (it ignores any other errors, however). If a is not 0, the script calls a function to calculate and retum the eccentricity, and then the script prints the result. Write the soript and the function.

Você também pode gostar