Rewrite Listing 2.9, ComputeDistance.py, using the following function for computing the distance between two points.def distance(x1, y1, x2, y2):
Q: Given any n by n square matrix, write a program that reflects the matrix across its major diagonal.…
A: In the above problem if we carefully analyze the problem we can see that the result matrix is the…
Q: if n <- 1 return arr [n] else for i in 2..n arr [i] <- arr [1-1] + arr [i-2] return arr[n] d) def…
A: The following function f uses recursion: def f(n): if n <= 1 return n else return f(n-1) + f(n-2)…
Q: Modify the program from Problem 1 and use the strtok function to count the number of words in the…
A: Actually, program is an executable software that runs on a computer.
Q: Write a program of multiply two matrices without using functions?
A: Sample Response: //C++ program to multiply two matrices without using functions#include…
Q: 3. An easier way to compute the gcd in python is to use the function gcd in the math library. Using…
A: code : import math print(math.gcd(12345,333)) Code Snapshot : Output : Answer : 3
Q: I'm trying to write a program where I can choose the multiplier, divisors, and number. I was able to…
A: def collatz(n,p,q): list1 = [n] if n == 1: return [1] elif n % 2 == 0:…
Q: Consider the following function: void fun_with_recursion(int x) { printf("%i\n", x);…
A: According to the question below the solution
Q: # Exercise 1. Implement the algorithm covered in lectures that determines if an integer n is prime.…
A: The code and the output is given in step 2.
Q: MATLAB code
A: Matlab Script: function y = mostZeros(A)[r c] = size(A);%gives number of rows and columnsy_temp =…
Q: In the box below, write a recursive Fibonacci function that computes the Fibonacci number for input…
A: Input : n - an integer value Output : Fibonacci series from 0 to n using recursion
Q: For f(x)=e*cos(3.x³), ƒ(x)=-2xe[3 sin(3 x²)+cos (3 .x³)]. Write a program FullName2.sce that samples…
A: Given: Code on Scilab Plz
Q: Write program to check whether a number is Palindrome or not. [Hint]: A palindrome number is a…
A: As there is no programing language mentioned so i attempted this question in c language. Palindrome…
Q: Task 06: Use the recursive definition of Fibonacci series and write a function int fib(int n) that…
A: ALGORITHM:- 1. Take input for the value of n from the user. 2. Pass it to the fib() function. 3.…
Q: : Exponential Series is a series which is used to find the value of e. The formula us express the…
A: Given an exponential series which is used to calculate the value of ex. We need to write a C program…
Q: A. What is the truth table for the following? B. What is the output function? Submit your answer in…
A:
Q: Write a function that will calculate the sum of all the numbers multiple of 3 from 1 to n using…
A: The program is written in C language. Please find the source code and code comments in the following…
Q: The following function f uses recursion: def f(n): if n 0 a <- a + i + (i-1) return a f(n): arr[0]…
A: Asked question The following function f uses recursion:def f(n):if n <= 1return nelsereturn…
Q: Write a program to compute the most frequent numbers in vectors ( x ), and ( y ) if x= a*b y=a* c a…
A: Note: The syntactical code in the question is in Matlab, hence answering the code in Matlab. Given…
Q: write a program to read four real variables, then use function for finding the largest value between…
A: The solution to the given problem is below.
Q: Implement the numerical approximation of using the following series, (conforming to 6 decimal…
A: ANSWER:-
Q: Write a triangle (x0, y0, x1, y1, x2, y2) function to draw the triangle with vertices (x0, y0), (x1,…
A: Here is the python code: See below step for code
Q: Write a code to calculate double func(int x,int y) recursively. When x <1 & ys 1 When x and y both…
A: Input : Value of x Value of y Output : Value returned by func(x,y).
Q: Write a recursive function F(N) that generalízes the following function: NF(N) 1 4 2 10 3 19 4 37 5…
A: Giving the python recursive function as follows :
Q: use R program to come up with: 9*(-9)102, 9*(-9)101 +9*(-9)100 + 99*(-9)99 + 99*(-9)98 + 9*(-9)97 +…
A: We are given the below equation that needs to solved using R programming.…
Q: Fibonacci numbers are a sequence of integers, starting with 1, where the value of each number is the…
A: Program plan: With RECURSION Prompt for a number Pass this number to function Fibonacci. Check if…
Q: Write a recursive function named multiply that takes two positive integers as parameters and returns…
A: def multiply(a, b): if b == 0: return 0 if b == 1: return a return a +…
Q: Rewrite Exercise 3.4 using the following func tion to return the area of a pentagon: def area(s):
A: Given: Rewrite Exercise 3.4 using the following func tion to return the area of a pentagon: def…
Q: Using recursive functions, given three letters in the alphabet, get their permutations together with…
A: Given that Using recursive functions in Python, given three letters in the alphabet, get their…
Q: Write a program in javascript to find the sum of 2 given variables. If the variables are equal then…
A: Required:- Please find the code below with the output.
Q: Replace the following program by two different programs to the same effect : XCHG SI,BX MOV AX,BX
A: Two different programs with same affect
Q: Rewrite the function up() using the loop instead of the recursion, to do the same task.
A: Program: // C Program#include <stdio.h>// up functionint up(int x){ /* old code…
Q: 4. Boolean algebra a, b, and c are Boolean variables. F(a, b, c) is a Boolean function with the…
A: The all three parts to be solved below:
Q: Write a recursive function that find the sum of the following series. 1+ 1/2 + 1/4 + 1/8 + ... +…
A: #include <stdio.h> #include<math.h> // Function to return sum of 1/1 + 1/4 + 1/8 + ..+…
Q: Write a program using recursive function, to calculate the following equation z = (yl - yl) ( (x-y)!
A: The algorithm Start Var x, y Input x and y from user. z = (factorial(x) - factorial(y) / factorial…
Q: Let n be a valid input, i.e., a natural number. Which of the following functions returns the same…
A: The recursion is a common mathematical and programming concept. The method of recursion implies that…
Q: Write an iterative and recursive function that returns the sum of all the integers from O to a given…
A: def sum_till_n_rec(num): # if num reached 0 if num == 0: return 0 # otherwise return num +…
Q: Write a function "sumofEven" that takes an int "n" and returns the sum of all even integers starting…
A: We have to write a function "sumOfEven" to find sum of even numbers from 1 to n we have given sample…
Q: Implement the following functions without using the library: a. int power (int n, int m) [Returns:…
A: Implement the function in C language: int power(int n,int m) The function takes input two integer…
Q: Write a program to compute the functions: Natural logarithms, integer value, and absolute value for…
A: Since no programming language is mentioned, I am using Matlab. Code: y=input('Enter y value:…
Q: Write a recursive function to compute the following series: m(i) = 1/2 + 2/ 3 + . . . + i/i + 1…
A: Recursive function to compute the following series: m(i) = 1/2 + 2/ 3 + . . . + i/i + 1 Write a…
Q: IN PYTHON, Using recursion: ask the user for the length of a square and the character they want to…
A: Required: IN PYTHON, Using recursion: ask the user for the length of a square and the character…
Q: Write a recursive function to compute the following series: m(i) = 1 + 1/2 + 1/3 + . . . + 1/i Write…
A: PROGRAM CODE: public class Main { /** Main method */ public static void main(String[] args) {…
Q: The output of the following program is to draw a group of stars in the form of
A: For the given code output with the details given below.
Q: Implement the numerical approximation of √√2 using for loop, (conforming to 12 dec places). 2 X₁ = 1…
A: Given:
Q: Write a recursive function that can use to add all the numbers from 5 to n, where n>5. n will be…
A: #include <stdio.h>int add_num(int a,int n); int main () { int n = 9; int c; c =…
Q: write a recursive function that checks see if the first letter matches the last letter, return the…
A: write a recursive function that checks see if the first letter matches the last letter, return the…
Rewrite Listing 2.9, ComputeDistance.py, using the following function for computing the distance between two points.
def distance(x1, y1, x2, y2):
Step by step
Solved in 2 steps with 1 images
- Fibonacci numbers are a sequence of integers, starting with 1, where the value of each number is the sum of the two previous numbers, e.g. 1, 1, 2, 3, 5, 8, etc. Write a function called fibonacci that takes a parameter, n, which contains an integer value, and have it return the nth Fibonacci number. (There are two ways to do this: one with recursion, and one without.)[Fish Tank] You play with a clown fish that has an initial size so. The fish can eat other fish in a tank organized in m columns and n rows. The fish at column i and row j has a positive size si,j. When your fish eats another fish, it grows by that amount. For example, if your clown fish has a size of 10 and eats a fish of size 5, it becomes of size 15. You cannot eat a fish that is bigger than your size. The game starts by eating any fish in the first (left-most) column that is not bigger than yours. After that, you advance one column at a time by moving right. You have only three allowed moves. You either stay at the same row, move one row higher or one row lower. You will always move to the right. Thus, you will make exactly m moves to advance from left to right. Your goal is to exit the fish tank from the right with the biggest possible size. The figure below shows an example with the best answer highlighted. In this case, the final fish size is 71 (10+8+7+24+22). You are required…b. Drawing a polygon Now that you can draw a circle, the next step is to draw a polygon inside the circle. Write a function DrawPolygon (N). The points of a N-sided polygon should be at angles 2π/N. You should add an extra point at the end so your polygon looks closed. Use your function to draw a 5-sided polygon (after drawing the circle): DrawCircle() DrawPolygon (5) plt.show() Write below your function to draw a N sided polygon and then use it to draw a 5-sided polygon. You can use dTheta = 2*np.pi/N in your function. ? Answer (start) # ANSWER ME Answer (end)
- Q2: In this question, you will write a Python function to compute the Hadamard product of two matrices. The Hadamard product is the "component-wise" product of two matrices. That is, each entry of the product matrix is equal to the product of its corresponding entries of the input matrices. Here is an example: a11 a12 a21 a22 a23 a31 a13 SH a32 033 A b11 b12 b13 b21 b22 b23 b31 b32 b33. B = [an bu a21 b21 a31 b31 a12 b12 a22 b22 a32 b32 a13 b13 a23 b23 a33 b33. Hadamard product of A and B Write a Python function to compute the Hadamard product of two matrices as follows. a) The inputs to the function are two matrices. b) The function should check whether the two matrices have the same size. If not, it should print "The input matrices are not of the same size". c) If two matrices are of the same size, the function computes the Hadamard product and returns the answer. Use for loops to compute the Hadamard product.(Learning Objective: students will be able to apply their knowledge of the built-in random package to generate simulations of simple phenomena.) Write a function: • dicesim(D1,D2,trials) that takes as input the number of sides on die 1 (D1) and die2 (D2) and the number of trials. Your function should repeatedly sum pairs of random numbers between 1 and D1 and 1 and D2 and keep track of how many times each sum occurs. The function returns a numpy array with the fraction each sum of rolls occured. Since the numbers are chosen at random, the fractions will differ some from run to run. One run of the function print(p22.dicesim(6,6,10000)) resulted in: [0. 0. 0.0259 0.0615 0.0791 0.1086 0.139 0.1633 0.1385 0.114 0.0833 0.0587 0.0281] or displayed using the code from Section 16.1.1.: PMF of X Note: you should submit a file with only the standard comments at the top and the function. The grading scripts will then import the file for testing.Evaluate the function y (shown in the photo.) for x = 3 to x = 5 in steps of 0.5. Write the complete code.
- What does the following function do? int fun(int x, int y) if (y == 0) return 0; return (x + fun(x, y-1)); O a. X O b. X+y Oc X*y AX+x P O e. None of the above.Going missing Some calculations involving blank values may give different results to what you might expect. For example, when you pass a blank value into the AND() function, it is treated as TRUE. This is often unhelpful. To make blanks behave in a sensible way in calculations, you must first convert them to be "not available" using NA(). This function takes no inputs, and returns a missing value. To convert a blank value to a missing value, use this pattern. =IF(ISBLANK(cell), NA(), cell) Instruction In column H, use AND() to find women who have kids and get benefits. In column I, convert the blanks in column G to missing values. In column J, again find women who have kids and get benefits, this time using column I rather than G. please show the formula used to "has kids and gets benefits" , "gets benefits with missing values", has kids and gets benefits". Thank you Is non-white Has over 12 years of school? Is married? Has kids? Has young kids? Is head of household? Gets…Let A = {a, b, c} and B = {u, v}. Write a. A × B b. B × A
- Re-write the following function so that a given XAND return the value of f(x).Rewrite Exercise 3.5 using the following function to return the area of a regular polygon:def area(n, side):Complete the function that calculates the sum of the first n+1 terms of the geometric series a, ar, ar² ar³, ar4 . note that the series begins with a and the last term is ar", in total there are n+1 terms. ar" ... [ ]: # complete the function given the variables a,r,n and return the value as series_sum. def sum_geometric_series(a,r,n): # your code here return series_sum