Questions
4. The product y = Ax of an m n matrix A times a vector x...

4. The product y = Ax of an m n matrix A times a vector x = (x1; x2; : : : ; xn)T can be computed row-wise as y = [A(1,:)*x; A(2,:)*x; ... ;A(m,:)*x]; that is y(1) = A(1,:)*x y(2) = A(2,:)*x ... y(m) = A(m,:)*x Write a function M-file that takes as input a matrix A and a vector x, and as output gives the product y = Ax by row, as denoted above (Hint: use a for loop to denote each entry of the vector y.) Your M-file should perform a check on the dimensions of the input variables A and x and return a message if the dimensions do not match. Call the file myrowproduct.m. Note that this le will NOT be the same as the myproduct.m example. Test your function on a random 5x2 matrix A and a random 2x1 vector x. Compare the output with A*x. Repeat with a 3x5 matrix and a 5x1 vector and with a 3x5 matrix and a 1x5 vector. Use the command rand to generate the random matrices for testing. Include in your lab report the function M-file and the output obtained by running it.

5. Recall that if A is an m n matrix and B is a p q matrix, then the product C = AB is denoted if and only if n = p, in which case C is an m q matrix.

(a) Write a function M-file that takes as input two matrices A and B, and as output produces the product by columns of the two matrix. For instance, if A is 3x4 and B is 4x5, the product is given by the matrix C = [A*B(:,1), A*B(:,2), A*B(:,3), A*B(:,4), A*B(:,5)]The function file should work for any dimension of A and B and it should perform a
check to see if the dimensions match (Hint: use a for loop to denote each column of C). Call the file columnproduct.m.Test your function on a random 5x3 matrix A and a random 3x5 matrix B . Compare the output with A*B. Repeat with 3 x 6 and 6 x 4 matrices and with 3 x 6 and 4 x 6 matrices.Use the command rand to generate the random matrices for testing. Include in your lab report the function M-file and the output obtained by running it.

(b) Write a function M- file that takes as input two matrices A and B, and as output produces the product by rows of the two matrices. For instance, if A is 3 x 4 and B is 4x5, the product AB is given by the matrix C = [A(1,:)*B; A(2,:)*B; A(3,:)*B] The function file should work for any dimension of A and B and it should perform a check to see if the dimensions match (Hint: use a for loop to denote each row of C). Call the file rowproduct.m. Test your function on a random 5x3 matrix A and a random 3x5 matrix B . Compare the output with A*B. Repeat with 3 x 6 and 6 x 4 matrices and with 3 x 6 and 4 x 6 matrices. Use the command rand to generate the random matrices for testing.
Include in your lab report the function M-file and the output obtained by running it.

In: Advanced Math

Please add to this Python, Guess My Number Program. Add code to the program to make...

Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins.

import random
def menu():
print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit")
while True:
#using try-except for the choice will handle the non-numbers
#if user enters letters, then except will show the message, Numbers only!
try:
c=int(input("Enter your choice: "))
if(c>=1 and c<=3):
return c
else:
print("Enter number between 1 and 3 inclusive.")
except:
#print exception
print("Numbers Only!")
  
def guessingGame():
min_number=1
max_number=10
#set number of guesses = 0
numGuesses=0
guessed_numbers = [] # list of guessed numbers
rand=random.randint(min_number, max_number)
#prints the header, welcoming the user
#print("\nWelcome to the Guess My Number Program!")
#While loop, comparing the users guessed number with the random number.
#If it matches, it will say you guessed it.
while (True):
#use try-block
try:
guess=eval(input("Please try to guess my number between 1 and 10:"))
guessed_numbers.append(guess)
#check if the guess is less than 0, then continye to beginning of the loop
if(guess<0):
continue;
elif (guess==rand):
#increment the guess count by 1
numGuesses=numGuesses+1
print("You guessed it! It took you {} attempts".format(numGuesses))
# print the guesses numbers list
print('You picked the following numbers: '+str(guessed_numbers))
#break will end the loop once the guess is a match.
#Conditions if the guess is too low or too high to keep guessing
break
elif(guess < rand):
#increment the guess count by 1
numGuesses = numGuesses +1
print("Too low")
else:
#increment the guess count by 1
numGuesses = numGuesses + 1
print("Too high")
except:
#print exception
print("Numbers only!")
  
def guessingGameComp():
countGuess=0
guessed_numbers = [] # list of guessed numbers
userNumber=int(input("\nPlease enter a number between 1 and 10 for the computer to guess:"))
while userNumber<1 or userNumber>10:
userNumber=int(input("Guess a number between 1 and 10: "))
while True:
countGuess+=1
compRand = random.randint(1,10)
guessed_numbers.append(compRand)
if(userNumber==compRand):
print("The computer guessed it! It took {} attempts".format(countGuess))
print("The computer guessed the following numbers: "+str(guessed_numbers))
break
elif(compRand<userNumber):
print("The computer guessed {} which is too low".format(compRand))
else:
print("The computer guessed {} which is too high".format(compRand))
  
def main():
print("Welcome to my Guess the number program!")
while True:
userChoice=menu()
if userChoice==1:
guessingGame()
elif userChoice==2:
guessingGameComp()
elif userChoice==3:
print("\nThank you for playing the guess the number game!")
break
else:
print("Invalid choice!!!")
#call the main function
main()   

In: Computer Science

Program must be OOP design.   Prompt the user to enter 10 doubles and fill an array...

Program must be OOP design.  

  1. Prompt the user to enter 10 doubles and fill an array
  2. Print the array
  3. Fill an array with 10 random numbers and print the array
  4. Sort the array -- then print
  5. Delete index[ 3] of the array and re-print the array

JAVA

This is my program so far. I am having trouble with my delete element method.



import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;


public class ArrayPlay {

    Random rand = new Random();//assign random number variable
    private double[] tenNumArray = new double[10];//initiate array containing 10 doubles.

    Scanner input = new Scanner(System.in);//create new scanner


    public Random getRand() {
        return this.rand;
    }

    public void setRand(Random rand) {
        this.rand = rand;
    }

    public double[] getTenNumArray() {
        return this.tenNumArray;
    }

    public void setTenNumArray(double[] tenNumArray) {
        this.tenNumArray = tenNumArray;
    } //end getters//setters

    //begin method
    public void fillArrayAndDisplay() {//begin prompt User method

        // #1 Prompt the user to enter 10 doubles and fill an array
        System.out.println("Enter ten elements to fill the array");
        for (int i = 0; i < this.tenNumArray.length; i++) {//for index equals 1 count plus 1 to 10
            this.tenNumArray[i] = input.nextDouble();//placing values index values into the array
        }//end for loop

        // #2 Print array
        System.out.println("The Numbers you entered into the array are");
        System.out.printf(Arrays.toString(this.tenNumArray)); // displays user filled array
    }//ends prompt User and print method


    // #3 Fill an array with 10 random numbers and print the array
    public void randomArrayAndDisplay() {   //begins random numbers and display array
        for (int i = 0; i < this.tenNumArray.length; i++) {
            this.tenNumArray[i] = rand.nextInt(10);//create the random numbers using Random class object. set to 10
        }
        System.out.println("\n The Randomly generated numbers are; ");
        System.out.printf(Arrays.toString(this.tenNumArray)); // displays random numbers
    }//ends random array and display method

    //  4. Sort the array -- then print
    public void sortNumberAndDisplay() {

        Arrays.sort(this.tenNumArray); //replaces your whole sort function
        System.out.println("\n The random numbers sorted are: ");
        System.out.printf(Arrays.toString(this.tenNumArray)); // replaces your display line
       }// end sort array method

    // #5. Delete index[ 3] of the array and re-print the array
    //begin delete element method
    public void deleteArrayElements(int index) {
        // If the array is empty
        // or the index is not in array range
        // return the original array
        if (this.tenNumArray == null
                || index >= this.tenNumArray.length || index < 0) {
            System.out.println("\n\n No deletion operation can be performed\n\n");

        } else {
            double[] tempArray = new double[this.tenNumArray.length - 1];

            // Copy the elements except the index
            // from original array to the other array
            for (int i = 0, k = 0; i < this.tenNumArray.length; i++) {

                // if the index is
                // the removal element index
                if (i == index) {
                    continue;
                }

                // if the index is not
                // the removal element index
                tempArray[k++] = this.tenNumArray[i];
            }

            // return the resultant array
            System.out.println(tempArray[4] + " \n delete num " + " ");

        }


    }

    public void loop(){
        fillArrayAndDisplay();//runs prompt user
        randomArrayAndDisplay();
        sortNumberAndDisplay();
        deleteArrayElements(3);//delete index 3
    }

}















In: Computer Science

Suppose the Dutch government issued a bond with 20 years until maturity, a face value of...

Suppose the Dutch government issued a bond with 20 years until maturity, a face value of €1000 and a coupon rate of 10% paid annually. The yield to maturity when the bond was issued was 5%.

  1. What was the present value of the coupons when the bond was issued?

  2. What was the present value of the bond when it was issued?

  3. Assuming the yield to maturity remains constant, what is the price of the bond

    immediately before it makes the first coupon payment?

  4. Assuming the yield to maturity remains constant, what is the price of the bond

    immediately after it makes the first payment?

In: Finance

Seventy homes that were for sale in Gainesville, Florida in Spring of 2019 were randomly selected....

Seventy homes that were for sale in Gainesville, Florida in Spring of 2019 were randomly selected. A regression model to predict house price in thousands was run based on first floor square footage and the indicator variable for NorthWest (1 if the house was in the NW, O if not).

Term Estimate Std. Error
Intercept -92.27 51.04
NorthWest -67.62 29.87
firstfloorsquarefootage 0.216 0.013

Find the predicted house price in thousands for a house with 1,953 square feet on the first floor and in the SW. Round your answer to two decimal points.

In: Statistics and Probability

A company issued the following semi-annual bonds:       Face amount:   $80,000       Coupon rate:     8%      ...

A company issued the following semi-annual bonds:

      Face amount:   $80,000

      Coupon rate:     8%

      Yield:                   6%

      Life:                   20 years

a. Compute the selling price of the bonds.

  1. Prepare the journal entry for the issuance of the bonds using the selling price from part (a).

                                              

c. Prepare the amortization schedule for only the first two interest periods using the interest

     method.

    CASH                  INTEREST EXPENSE                   AMORTIZATION                        BOOK VALUE

d. Prepare the journal entry to record the first interest payment on the bonds using the

     schedule completed in part (c).


                           

In: Accounting

When the price is $30 per unit, buyers in a market are willing to buy 400...

When the price is $30 per unit, buyers in a market are willing to buy 400 gadgets and when the price is $60 per unit, they are only willing to buy 100 gadgets. When the price is $30 per unit, sellers in a market are only willing to sell 150 gadgets and when the price is $60 per unit, they are willing to sell 225 gadgets. Assume (1) the economic environment of buyers (their income, tastes or preferences, other prices, and expectations) and sellers (technology, input prices, etc.) are constant and (2) the demand and supply curves are linear all along. What price in this market would make the quantity demanded equal to 200 units?

In: Economics

Karl’s income elasticity of demand for peanut butter is 0.20 while his price elasticity of demand...

Karl’s income elasticity of demand for peanut butter is 0.20 while his price elasticity of demand for peanut butter is -1.20.    Karl’s income is $20,000 per year and the price of peanut butter is currently $4.00.    Karl currently spends $2,000 per year on peanut butter   Pea butter is taxed which increases its price by 5%.

a. Calculate what happens to Karl’s purchases of peanut butter.

b. Will Karl end up spending on peanut butter after the price increase? Explain

c. If Karl’s income increased by $100 (5% of 2,000) would he consume the same amount of peanut butter as he did before the price increase? Explain.

In: Economics

Determining opportunity cost Juanita is deciding whether to buy a skirt that she wants, as well...

Determining opportunity cost Juanita is deciding whether to buy a skirt that she wants, as well as where to buy it. Three stores carry the same skirt, but it is more convenient for Juanita to get to some stores than others. For example, she can go to her local store, located 15 minutes away from where she works, and pay a marked-up price of $100 for the skirt: Store Travel Time Each Way Price of a Skirt (Minutes) (Dollars per skirt) Local Department Store 15 100 Across Town 30 86 Neighboring City 60 63 Juanita makes $56 an hour at work. She has to take time off work to purchase her skirt, so each hour away from work costs her $56 in lost income. Assume that returning to work takes Juanita the same amount of time as getting to a store and that it takes her 30 minutes to shop. As you answer the following questions, ignore the cost of gasoline and depreciation of her car when traveling. Complete the following table by computing the opportunity cost of Juanita's time and the total cost of shopping at each location. Store Opportunity Cost of Time Price of a Skirt Total Cost (Dollars) (Dollars per skirt) (Dollars) Local Department Store 100 Across Town 86 Neighboring City 63 Assume that Juanita takes opportunity costs and the price of the skirt into consideration when she shops. Juanita will minimize the cost of the skirt if she buys it from the _____ .

In: Economics

PROBLEM 3. In Torp, there are 200 people who want to sell their used cars. Everybody...

PROBLEM 3.

In Torp, there are 200 people who want to sell their used cars. Everybody knows that 100 of these cars are "lemons" and 100 of these cars are "good." The problem is that nobody except the original owners know which are which. Owners of lemons will be happy to get rid of their cars for any price greater than $200. Owners of good used cars will be willing to sell them for any price greater than $1,500, but will keep them if they can't get $1,500. There are a large number of buyers who would be willing to pay $2,500 for a good used car but would pay only $300 for a lemon. When these buyers are not sure of the quality of the car they buy, they are willing to pay the expected value of the car, given the knowledge they have.

A. If all 200 used cars in Torp were for sale, how much would buyers be willing to pay for a used car? Would owners of good used cars be willing to sell their used cars at this price? Would there be an equilibrium in which all used cars are sold? Describe the equilibrium that would take place in Torp.

B. Suppose that instead of there being 100 cars of each kind, everyone in town is aware that there are 120 good cars and 80 lemons. How much would buyers be willing to pay for a used car? Would owners of good used cars be willing to sell their used cars at this price? Would there be an equilibrium in which all used cars are sold? Would there be an equilibrium in which only the lemons were sold? Describe the possible equilibrium or equilibria that would take place in Torp.

In: Economics