Students will create a Disaster Recovery Plan for either the organization they work for or one they wish to work for in the future.

Students will create a Disaster Recovery Plan for either the organization they work for or one they wish to work for in the future. The plan will follow the template/example provided. Student should request prior authorization of company to be addressed to ensure that all students are working on unique companies. **Even though this is a technical document, for academic purposes, all sources should be cited and referenced.

Describe how one can implement each of the following operations on an array so that the time it takes does not depend on the array’s size n. a. Delete the ith element of an array

1. Describe how one can implement each of the following operations on an array so that the time it takes does not depend on the array’s size n. a. Delete the ith element of an array (1 ≤ i ≤ n).

b. Delete the ith element of a sorted array (the remaining array has to stay sorted, of course).

2. If you have to solve the searching problem for a list of n numbers, how can you take advantage of the fact that the list is known to be sorted? Give separate answers for

a. lists represented as arrays.

b. lists represented as linked lists.

3. a. Show the stack after each operation of the following sequence that starts with the empty stack: push(a), push(b), pop, push(c), push(d), pop

b. Show the queue after each operation of the following sequence that starts with the empty queue: enqueue(a), enqueue(b), dequeue, enqueue(c), enqueue(d), dequeue

Once you have Racket installed, open DrRacket. Here is what DrRacket looks like on Linux; it should look similar on Windows and macOS:

Lab #2 — Scheme Exercises CS 152 Section 5 — Fall 2020 Michael McThrow San José State University

Prelude – Installing and Using DrRacket We will be using the DrRacket IDE in this course for running Scheme programs. DrRacket is available for Windows, macOS, and Linux. You can download it by going to https://racket-lang.org, clicking on the “Download” button on the top right of the page, and choosing the appropriate platform for your computer.

Once you have Racket installed, open DrRacket. Here is what DrRacket looks like on Linux; it should look similar on Windows and macOS:

Note that the window has two sections. The first section where you see “#lang racket” is the source code file. The second section is the interpreter, which some programmers call the REPL, which stands for the “Read Eval Print Loop,” which describes how the user interface for interactive Lisp interpreters is implemented. (This REPL terminology has been now widely applied for other interactive interpreters, such as those for Python and JavaScript.) When you write your programs, you’re going to use the upper portion. However, if you just want to evaluate an expression on the fly, you can use the REPL on the lower portion.

Now, notice the “#lang racket” in the source code file section of DrRacket. That indicates that the program written below that line will be in the Racket programming language, which is a variant of

 

 

Scheme. For this assignment, however, we will be sticking to functions that are included in the R6RS version of Scheme. This enables us to use the REPL (sadly R6RS Scheme doesn’t have REPL support implemented in DrScheme) and to make use of DrScheme’s excellent debugging facilities.

Let’s try out the REPL by evaluating (+ 2 (* 3 5)). Type “(+ 2 (* 3 5))” at the prompt (with no quotes) and press Enter.

When you write your code, you are going to use the upper portion of the window, and you are going to use the Run button to run your code, either the entirety of the source code or a selection of it.

For a more detailed tutorial of the DrRacket IDE, please visit the DrRacket IDE manual at https://docs.racket-lang.org/drracket/.

Warmup Exercises (40 points) 1. (10 points) Write a function named fizz-buzz that accepts no arguments. The fizz-buzz

function outputs numbers 1 to 100 (inclusive) and prints them line-by-line as standard output. If a number is divisible by 3, we print “fizz” instead of the number. If a number is divisible by

 

 

5, we print “buzz” instead of the number. If a number is divisible by both 3 and 5 (e.g., 15), we print “fizzbuzz” instead of the number.

Hint: Scheme provides a remainder function (e.g., (remainder 3 2) evaluates to 1.) The display function accepts both numbers and strings. Note, though, that unlike Java’s System.out.println() function, display does not automatically append a new line.

2. (15 points) Write a function named gcd that accepts two arguments m and n. This computes the greatest common denominator of m and n; you may assume these are integers. For example, if m is 16 and n is 36, the greatest common denominator is 4. You may assume that m and n are integers.

3. (5 points) Write a function named linear-search that accepts two arguments: items and key. This function performs a linear search on the list items, determining whether key (an integer) is among those items. The function evaluates to true (#t) if the key is found, and false (#f) is the key is not found. For this function, when it comes to operating on the list, you are only allowed to use the Scheme functions first and rest; you may not use Scheme’s built-in search functions, nor are you allowed to take advantage of maps and filters.

4. (10 points) Write a function named my-remove that accepts two arguments: items (a list) and key. This function returns a new list that does not have any elements that match the key. Once again, you may only use first and rest for traversing the existing list, and for creating the new list, you are limited to the cons, list, and append functions.

Binary Search Tree (60 points) We will be writing a binary search tree in Scheme. Recall from CS 146 that a binary search tree is a data structure that allows for the storage of elements in a manner that is amenable to performing searches in O(log n) in the average case. For example, suppose we are adding the elements 3, 4, 2, 5, 8, 1, and 4.5 (in that order) to construct a binary search tree. We will end up with the resulting tree:

 

 

In Scheme, we could represent the above binary search tree as a collection of embedded lists:

(3 (2 (1)) (4 () (5 (4.5) (8))))

Each node is a list with up to three elements. The first element of the list refers to the node’s value. If a node is terminal (i.e., has no children), then it is represented as a one-element list. If a list has only two elements, that means the node only has a left child. If a node has only a right child, then it has three elements, but because there is no left child, the second element is the empty list (). A node with both a left and right child has three elements: the value, the left child, and the right child.

Let’s do each insertion step by step:

3 => (3) 4 => (3 () (4)) 2 => (3 (2) (4)) 5 => (3 (2) (4 () (5))) 8 => (3 (2) (4 () (5 () (8)))) 1 => (3 (2 (1)) (4 () (5 () (8)))) 4.5 => (3 (2 (1)) (4 () (5 (4.5) (8))))

Note that no duplicate elements are allowed in the binary search tree.

Write the following functions as follows (note: you may assume that all elements in the binary search tree are numbers): 1. (22.5 points) add-to-binary-search-tree with two arguments bst (the binary search tree)

and item, which is the item to be inserted into the binary search tree. This function returns a new binary search tree in its correct order. Note that if item is already in the binary search tree, then this function simply returns the existing binary search tree.

2. (7.5 points) create-binary-search-tree with argument items, a list of items to be inserted into the binary search tree. This function returns a new binary search tree with all of the items inside, excluding duplicates.

3. (15 points) search-binary-search-tree with two arguments bst (the binary search tree) and key, which is the item to search for in the binary search tree. This function returns #t if found and #f otherwise.

4. (15 points) binary-search-tree-to-list with two arguments bst (the binary search tree) and traversal, a symbol that indicates the traversal method. If the symbol is preorder, then place the elements in a list using preorder traversal. If the symbol is inorder, then use inorder traversal. If the symbol is postorder, then use postorder traversal.

Rules • No side effects are allowed with the exception of the display function and other functions that

print to the screen. • No mutation is allowed; this includes the use of set! • No do loops; either use recursion or map/filter/fold style functions (for-all is acceptable). • Make sure all of your code cleanly runs when turning it in; if I cannot evaluate your function,

that function gets a grade of zero.

 

 

• No external libraries or Racket-only libraries; use only the R6RS Scheme standard library.

Recommendations and Hints • I highly recommend writing some test cases for your code. One of the nice things about coding

without side effects is that you can just use simple equality functions to test what your functions evaluate to.

• Functional programming can sometimes feel like a mind-bending exercise for beginners. I highly recommend working out your programs on paper and thinking about how you would express with recursion, map, filter, and/or fold what you would normally express with loops in your Java programs. In some ways it’s like learning how to code again. But don’t feel discouraged; remember the first time you learned how to program, or the first time you learned how to write in assembly language. With practice, though, then functional programming will be second nature for you.

• Helper functions are vital in an immutable world. Remember that you can have as many arguments as you can in your helper functions.

• You are allowed to define your own top-level functions besides the ones that have been specified as common helper functions, but these functions are subject to the same restrictions as the others (for example, these functions can’t take advantage of any features that the functions specified cannot take advantage of).

Instructions for Turning In the Assignment Please place all of your functions in a file called lab2.rkt. This is the file that you will be turning in to me via Canvas.

 

  • Prelude – Installing and Using DrRacket
  • Warmup Exercises (40 points)

Scheme Exercises

Lab #2 — Scheme Exercises CS 152 Section 5 — Fall 2020 Michael McThrow San José State University

Prelude – Installing and Using DrRacket We will be using the DrRacket IDE in this course for running Scheme programs. DrRacket is available for Windows, macOS, and Linux. You can download it by going to https://racket-lang.org, clicking on the “Download” button on the top right of the page, and choosing the appropriate platform for your computer.

Once you have Racket installed, open DrRacket. Here is what DrRacket looks like on Linux; it should look similar on Windows and macOS:

Note that the window has two sections. The first section where you see “#lang racket” is the source code file. The second section is the interpreter, which some programmers call the REPL, which stands for the “Read Eval Print Loop,” which describes how the user interface for interactive Lisp interpreters is implemented. (This REPL terminology has been now widely applied for other interactive interpreters, such as those for Python and JavaScript.) When you write your programs, you’re going to use the upper portion. However, if you just want to evaluate an expression on the fly, you can use the REPL on the lower portion.

Now, notice the “#lang racket” in the source code file section of DrRacket. That indicates that the program written below that line will be in the Racket programming language, which is a variant of

 

 

Scheme. For this assignment, however, we will be sticking to functions that are included in the R6RS version of Scheme. This enables us to use the REPL (sadly R6RS Scheme doesn’t have REPL support implemented in DrScheme) and to make use of DrScheme’s excellent debugging facilities.

Let’s try out the REPL by evaluating (+ 2 (* 3 5)). Type “(+ 2 (* 3 5))” at the prompt (with no quotes) and press Enter.

When you write your code, you are going to use the upper portion of the window, and you are going to use the Run button to run your code, either the entirety of the source code or a selection of it.

For a more detailed tutorial of the DrRacket IDE, please visit the DrRacket IDE manual at https://docs.racket-lang.org/drracket/.

Warmup Exercises (40 points) 1. (10 points) Write a function named fizz-buzz that accepts no arguments. The fizz-buzz

function outputs numbers 1 to 100 (inclusive) and prints them line-by-line as standard output. If a number is divisible by 3, we print “fizz” instead of the number. If a number is divisible by

 

 

5, we print “buzz” instead of the number. If a number is divisible by both 3 and 5 (e.g., 15), we print “fizzbuzz” instead of the number.

Hint: Scheme provides a remainder function (e.g., (remainder 3 2) evaluates to 1.) The display function accepts both numbers and strings. Note, though, that unlike Java’s System.out.println() function, display does not automatically append a new line.

2. (15 points) Write a function named gcd that accepts two arguments m and n. This computes the greatest common denominator of m and n; you may assume these are integers. For example, if m is 16 and n is 36, the greatest common denominator is 4. You may assume that m and n are integers.

3. (5 points) Write a function named linear-search that accepts two arguments: items and key. This function performs a linear search on the list items, determining whether key (an integer) is among those items. The function evaluates to true (#t) if the key is found, and false (#f) is the key is not found. For this function, when it comes to operating on the list, you are only allowed to use the Scheme functions first and rest; you may not use Scheme’s built-in search functions, nor are you allowed to take advantage of maps and filters.

4. (10 points) Write a function named my-remove that accepts two arguments: items (a list) and key. This function returns a new list that does not have any elements that match the key. Once again, you may only use first and rest for traversing the existing list, and for creating the new list, you are limited to the cons, list, and append functions.

Binary Search Tree (60 points) We will be writing a binary search tree in Scheme. Recall from CS 146 that a binary search tree is a data structure that allows for the storage of elements in a manner that is amenable to performing searches in O(log n) in the average case. For example, suppose we are adding the elements 3, 4, 2, 5, 8, 1, and 4.5 (in that order) to construct a binary search tree. We will end up with the resulting tree:

 

 

In Scheme, we could represent the above binary search tree as a collection of embedded lists:

(3 (2 (1)) (4 () (5 (4.5) (8))))

Each node is a list with up to three elements. The first element of the list refers to the node’s value. If a node is terminal (i.e., has no children), then it is represented as a one-element list. If a list has only two elements, that means the node only has a left child. If a node has only a right child, then it has three elements, but because there is no left child, the second element is the empty list (). A node with both a left and right child has three elements: the value, the left child, and the right child.

Let’s do each insertion step by step:

3 => (3) 4 => (3 () (4)) 2 => (3 (2) (4)) 5 => (3 (2) (4 () (5))) 8 => (3 (2) (4 () (5 () (8)))) 1 => (3 (2 (1)) (4 () (5 () (8)))) 4.5 => (3 (2 (1)) (4 () (5 (4.5) (8))))

Note that no duplicate elements are allowed in the binary search tree.

Write the following functions as follows (note: you may assume that all elements in the binary search tree are numbers): 1. (22.5 points) add-to-binary-search-tree with two arguments bst (the binary search tree)

and item, which is the item to be inserted into the binary search tree. This function returns a new binary search tree in its correct order. Note that if item is already in the binary search tree, then this function simply returns the existing binary search tree.

2. (7.5 points) create-binary-search-tree with argument items, a list of items to be inserted into the binary search tree. This function returns a new binary search tree with all of the items inside, excluding duplicates.

3. (15 points) search-binary-search-tree with two arguments bst (the binary search tree) and key, which is the item to search for in the binary search tree. This function returns #t if found and #f otherwise.

4. (15 points) binary-search-tree-to-list with two arguments bst (the binary search tree) and traversal, a symbol that indicates the traversal method. If the symbol is preorder, then place the elements in a list using preorder traversal. If the symbol is inorder, then use inorder traversal. If the symbol is postorder, then use postorder traversal.

Rules • No side effects are allowed with the exception of the display function and other functions that

print to the screen. • No mutation is allowed; this includes the use of set! • No do loops; either use recursion or map/filter/fold style functions (for-all is acceptable). • Make sure all of your code cleanly runs when turning it in; if I cannot evaluate your function,

that function gets a grade of zero.

 

 

• No external libraries or Racket-only libraries; use only the R6RS Scheme standard library.

Recommendations and Hints • I highly recommend writing some test cases for your code. One of the nice things about coding

without side effects is that you can just use simple equality functions to test what your functions evaluate to.

• Functional programming can sometimes feel like a mind-bending exercise for beginners. I highly recommend working out your programs on paper and thinking about how you would express with recursion, map, filter, and/or fold what you would normally express with loops in your Java programs. In some ways it’s like learning how to code again. But don’t feel discouraged; remember the first time you learned how to program, or the first time you learned how to write in assembly language. With practice, though, then functional programming will be second nature for you.

• Helper functions are vital in an immutable world. Remember that you can have as many arguments as you can in your helper functions.

• You are allowed to define your own top-level functions besides the ones that have been specified as common helper functions, but these functions are subject to the same restrictions as the others (for example, these functions can’t take advantage of any features that the functions specified cannot take advantage of).

Instructions for Turning In the Assignment Please place all of your functions in a file called lab2.rkt. This is the file that you will be turning in to me via Canvas.

 

  • Prelude – Installing and Using DrRacket
  • Warmup Exercises (40 points)

Create a Python dictionary that returns a list of values for each key. The key can be whatever type you want. 

Create a Python dictionary that returns a list of values for each key. The key can be whatever type you want.

Design the dictionary so that it could be useful for something meaningful to you. Create at least three different items in it. Invent the dictionary yourself. Do not copy the design or items from some other source.

Next consider the invert_dict function from Section 11.5 of your textbook.

# From Section 11.5 of:
# Downey, A. (2015). Think Python: How to think like a computer scientist. Needham, Massachusetts: Green Tree Press.

def invert_dict(d):
inverse = dict()
for key in d:
val = d[key]
if val not in inverse:
inverse[val] = [key]
else:
inverse[val].append(key)
return inverse

Modify this function so that it can invert your dictionary. In particular, the function will need to turn each of the list items into separate keys in the inverted dictionary.

Run your modified invert_dict function on your dictionary. Print the original dictionary and the inverted one.

Include your Python program and the output in your Learning Journal submission.

Describe what is useful about your dictionary. Then describe whether the inverted dictionary is useful or meaningful, and why.

PART 2

 

Describe how tuples can be useful with loops over lists and dictionaries, and give Python code examples. Create your own code examples. Do not copy them from the textbook or any other source. 

Your descriptions and examples should include the following: the zip function, the enumerate function, and the items method.

Each student, independently of the team will prepare a brief summary for the week’s simulation efforts. This report will include the following information: 

Each student, independently of the team will prepare a brief summary for the week’s simulation efforts. This report will include the following information:

  1. What was your one corporate generic strategy as reviewed from our text for the week?  Break this down by your target market and your competitive advantage.  Why?  Did your overall strategy change since week 1?  Why?
  2. What was your strategic action plan going into the rounds detailed in Blackboard including the reasons for the moves and how it relates to your overall strategy?  What are your objective and measurable goals for the moves?  Did you have to make operationally reactive moves not related to your strategy?  Why?
  3. What was the objective, fact-based results compared to your intended moves and the reasons of these moves generally? How did your moves advance your one Generic Strategy?  Be specific.  Did you get the objective results you expected?  Why/why not?  Share any objective measures from the simulation program that are pertinent to the strategic implementation results and note any purely operational moves.  How did your competition and the external environment impact your moves?  What is your analysis of this data results compared to your intended results?
  4. What do you think the next set of objective and measurable moves you will have to consider, and what will you suggest to your partners regarding next week’s moves?
  5. What have you learned and how does this relate to other lessons in this course and to your career?
  6. Provide a log regarding the specific dates and times that you accessed the simulation system including specifically when and how you and your teammate reviewed and discussed the simulation system data and decided on your moves to make.  A sample is provided in week 1.

Your report this week should cover periods 5 thru 6 inclusively with fact-based objective data that you analyze from both periods.  DO NOT copy from your first paper.  Each paper must be written in your own words with proper APA referencing.

Your grade for each of the simulation report papers will be based on your analysis and critical thinking around the selection and implementation of the corporate strategy for your company.  Your analysis must be increasingly more thorough with each paper as you become more familiar with the simulation program and with the concepts from our course.

Your assignment will be between 1000 and 1500 words and follow APA Guidelines. Include a cover page and at least your course text as a reference.

References: Thompson textbook 2021.

Feedback: Please use the documents I have attached and no google words copied. Every letter should be written on own.

Simulation Report

Simulation Report 01 2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Simulation Report

Introduction

In team D, utilization of StratSimManagement Simulation tool over since the first input in week one over the four periods has proven to be very effective in the understanding market environment, making projections, and remaining objective to the leading cause for action in the automotive industry. The primary strategy is to become an automotive leader while promoting quality and safety in car manufacturing (Gonzalez-Fuentes et al., 2021). The objectives that the team within the simulation effect had in mind includes creating minor updates for Defy in terms of interior, safety, and quality, opening new distribution centers, improving all cars in economy, family, truck, and luxury cars for “Deluxe” as part of competitive advantage for the company. Indeed, the best value for each period was designed effectively.

Strategy

The firm’s corporate generic strategy was to be the leading automobile firm in the industry to promote the quality and safety of car production (Gonzalez-Fuentes et al., 2021). The company would achieve this by narrowing down to the main market demands and needs and being ready to use innovation to gain a competitive advantage over other brands in the market and remain the business leader. It is commonly known that consumers look for safety measures, quality, and interior designs which offer luxury and comfort while using cars, and that’s the primary strategy while making innovations and areas for improvement. Thus, since each of the vehicles in the different classification such as luxury, economy, family, and truck have different needs and require additional input, in each segment, analysis was done based on the need for the consumers, value for the car, and competitors input in such segment to make sure the cars are outstanding while maintaining the role of business leaders which means attracting more customers, having the more significant market shares and proper market penetration. The overall strategy did not change as it touched all production elements to marketing, making it very effective.

The strategic action plan was mainly centered on objectivity and looking at the entire production force at all aspects through the decision making to see that every decision made impacts the long-term goal and impact for the organization in the market based on each car segment (Gonzalez-Fuentes et al., 2021). For instance, the first decisions were to invest in safety through technological innovation, then under product development, the approach taken as opening new development center. The firm utilizes direct marketing and advertising in the East and later in the South in consumer marketing. Product marketing for specific brands such as project Delite had minor upgrades and required marketing while based on quality input to meet consumer brands. For Detonka, marketing was mainly based on its performance power. New dealerships were opened, and manufacturing was maximized to remain competitive.

Based on the strategic action plan, all the moves explained above had measurable goals set and input as to why taking that action plan was the best choice of input, mainly in remaining competitive in the market. For instance, since decisions were based on market forces and forecasting, a car brand like Defy required only minor updates in the family segment where the car, despite being in a very competitive environment, the car segment had 33% of the entire market share and made the input balance, the company increased the advantages to 60% while decreasing promotion by 40% and maintained leading on the segment.

In segments such as luxury cars, consumers are looking for interior, safety, and quality; thus, all innovations were based on creating upstandingness in quality. The outcome is that the segment has remained a tremendous high-income enterprise. Therefore, for Deluxe luxury, in the first instance, the company tried to change the marketing theme by focusing on advertisements based on styling without making significant changes. It increased advantages by 37%. However, changes were made in the next improvement plan to increase its size, style, interior, and quality when focusing on electric launching in Y6, and the prices increased by $37,999. To make the outcome better for dealers, a discount of 15% was granted, which led to outstanding marketing and sustainable input in the marketing campaign and development.

To increase market share, the company had to open new distribution centers, where three dealers were set to open in the North and South, one dealer was set to open in the East, and one in the West. At the same time, as the dealers were opening up, the need to increase capacity was considerably high since the production pattern had not been changed even without the dealership. Thus, available production had to take a plus one in decisions. Opening all the branches creates a high market reach and makes it easy for consumers to get the best brands in the entire section, which keeps the overall strategy of being ahead of the competition real.

The other strategic decision was to improve all cars, even those with minor market share, by focusing on value for money in what the consumers are looking for and what the company is offering which increased sales even in the low segment brands (Gonzalez-Fuentes et al., 2021). For Deluxe in the market, quality and affordability are good equation that works best. Thus, setting the prices above $35K and the competitors having the same brand set between $40.3K and $40.7K will form the market as competitive as possible. The production cost also requires a reduction in production, which can be made through additional automaking to focus on what is best for the interest of consumers that takes 10% cost in building the current capacity. Thus, all changes that will be done in the production schedule will be done all around from pricing, dealership, marketing, and safety measures to ensure no fine is given.

The Detonka truck is among the brands that experienced innovation through safety and styling. The advantages increased to 35, which is a good input that placed the company in a great position when dealing with development options and brand inputs that serve best. It was a significant investment making all the changes from plant automation to ensuring all the vehicle segments were increased; thus, financing was 3M in credit at an interest of 3.5% and 3M loan repayment. The company also sold bonds of $1000.

Conclusion

The firm planned to remain competitive and maintain leadership in automotive marketing through quality and safety. A significant input made the company competitive through innovation based on technology to maintain safety, product development, consumer marketing, distribution, and manufacturing. The outcome has been outstanding, with the company increasing its revenue and strengthening its competitive position. It was a significant input to keep the company on its productive margin. Group members did all the strategies held via Zoom meetings on 18, 19, and 22 December 2021.

 

 

 

 

 

 

 

References

Gonzalez-Fuentes, M., Robertson, K. R., & Davis, J. C. (2021). Creativity as a Reflective Learning Exercise: Informing Strategic Marketing Decisions Through Digital Storytelling. Marketing Education Review, 1-9.

Please use the sample format as attached mlx file and upload both mlx and pdf. Make sure to sign problems and which part is it.

Please use the sample format as attached mlx file and upload both mlx and pdf. Make sure to sign problems and which part is it.

By hand part you should write by hand and take a picture then insert it in.

Notes.

  • When uploading your work, be sure to choose correct pages, without missing any, for each problem. Besides, make sure all pages are in order, no page is rotated, and none of your code or hand-written work is cut out.
  • According to our homework policies, you are allowed to collaborate for homework assignments in a group of up to 5 students. If you did, please list all your collaborators at the top of your homework, below your name.
  • Homework must be prepared using a live script (.mlx file). Submission generated using any other means (e.g., Words with MATLAB screenshots) will not be accepted.
  • Starting from this assignment, you will be asked to write MATLAB functions. Unlike scripts, functions can be included inside your mlx file at the very end of the document. So you no longer need to write an external m-file and print its content using the type function. For more detailed instruction, please read

[Guide] How to Embed Functions in Live Scripts:

 

Method 1: Using Code Example Environment

Suppose that you have written a function as a separate function m-file, myfoo.m and now you want to include its contents within your homework live script, HW2_Kim.mlx. At the top of MATLAB window, click on Insert > Code Example. It creates a blank box. Any text typed within this box will be formatted in monospaced fonts with syntax highlighting.

Drawbacks:

  • The box is not an executable code block.
  • If you make changes to myfoo.m, you need update the code example block accordingly (by copying and pasting).

Method 2: Using TYPE Function

Still suppose that you have a function written as a separate m-file titled myfoo.m. Then you can simply type

type myfoo

within a code block. The contents of myfoo.m will be printed out in your live script.

Note:

  • We have been using this to print out the contents of external script m-files. This works in the exact same way for function m-files.

Drawbacks:

  • If you forget to run that block after your final edit, your live script will show an outdated version of your function.
  • As you complete more and more assignments, your folders will be filled with more m-files and may be difficult to manage unless you are well-organized.

Method 3 (Recommended): Writing Functions at the End of Live Script

Instead of writing a separate m-file, you may just write the function at the very bottom of the document. The functions are local to the live script, and so you are able to call the function anywhere inside the live script. This way, your mlx file is fully self-contained and you no longer need to go back and forth between Editor and Live Editor. See the live script accompanying Lecture 9; all functions defined for the live script are gathered in the last section titled “Functions Used”.

This is my recommended method!

The only caveat I can think of:

  • Suppose Problem 1(a) asks you to write a function, and so you write it at the end of your live script. You then exports it to a pdf file and find out that Problem 1 solutions are on pp. 1–2, with the function written for 1(a) appearing on p. 7. In this case, when you upload the pdf file to Gradescope, you have to select pages 7, 1, and 2 for Problem 1, in that order.

Improved triangular substitutions; adapted from FNC

Updated on September 30, 2021

Hints for Homework 5

1. (Improved triangular substitutions; adapted from FNC 2.3.5)

(a) The function backsub handles the case in which A is upper triangular; call it U:

U

 x1 x2 · · · xp

 

︸ ︷︷ ︸ =X

=

 b1 b2 · · · bp

 

︸ ︷︷ ︸ =B

.

For any j ∈ N[1,p], the solution of Uxj = bj is obtained by applying the backward substitution formula given in lecture:

 xn,j =

bn,j un,n

and

xi,j = 1 ui,i

 bi,j − n∑

k=i+1 ui,kxk,j

  for i = n− 1,n− 2, . . . , 1.

Encode these formulas using nested for-loops in your program: • outer loop: iterate over columns (j = 1, 2, . . . ,p) • inner loop: implement the backward substitution formula (i = n,n− 1, . . . , 1).

You may use the following template to begin your program backsub.m1 by function X = backsub(U,B) % BACKSUB X = backsub(U,B) % Solve multiple upper triangular linear systems. % Input: % U upper triangular square matrix (n-by-n) % B right-hand side vectors concatenated into an (n-by-p) matrix % Output: % X solution of UX = B (n-by-p)

[n,p] = size(B); % grab dimensions X = zeros(n,p); % preallocate output %% Implement back. subs. formula (nested for-loop)

end

1You do not need to write external function m-files. Simply write them at the end of the document as instructed in the problem.

1

 

 

The function forelim can be written in a very analogous manner. Note. If you want to include a check for triangularity of the coefficient matrix, use

istriu (upper triangular) or istril (lower triangular), e.g., if ~istriu(U)

error(’The matrix U must be upper triangular.’); end

The inclusion of such a check will not be part of the grading rubrics. (b) One way to test your code using the given examples is to compute the norm of the

difference of the analytical inverse and the numerically calculated inverse. For example, L1 = …..; L1inv = …..; % analytical inverse given L1invNum = ltinverse(L1); % numerically calculated inverse norm(L1inv – L1invNum) % norm of the difference

We want to see a small norm, if not zero.

2. (Triangular substitution and stability; FNC 2.3.6)

(a) In this part, you show that x = (1, 1, 1, 1, 1)T solves the system for any values of α and β; this is an analytical result.

(b) In this second part, however, you check whether the computer indeed produces the same answer for changing values of β while α is fixed. When the problem says “Using MATLAB, solve the system . . .”, it simply means that you use the backslash \ to solve the system Ax = b.

3. (Vectorizing mylu.m; FNC 2.4.7)

(a) For this part, follow the direction given in the problem: • delete the keyword for in the inner loop; (just for, not the rest) • delete the matching end of the inner loop; • put a semicolon at the end of i = j+1:n.

This defines i to be a vector of indices (j + 1,j + 2, . . . ,n). Passing i into L or A in the next two lines, the code effectively accesses the (j + 1)st through nth rows of the respective matrices; see the slides titled “Using Vectors as Indices” in Lecture 7 on arrays.

(b) Let x ∈ Rn and A ∈ Rn×n, not necessarily the ones appearing in the problem. The ordinary elementwise vector/matrix notation refers to the convention of denoting the elements of a vector or a matrix using subscripts such as

• xi: the ith element of vector bx; • Ai,j: the element of A on the ith row and jth column.

In MATLAB, they are expressed as x(i) and A(i,j), respectively. Now, let’s concen- trate on the matrix case:

A(< rowindex >,< columnindex >)

When one of the two indices is a vector, as in the case of the problem, it represents the slice of the matrix on a specified row or column. For example,

2

 

 

• A row vector consisting of 5th through 8th elements on the 3rd row of A:

A(3, 5 : 8) −→ [ A3,5 A3,6 A3,7 A3,8

] • A column vector consisting of 5th through 8th elements on the 3rd column of A:

A(5 : 8, 3) −→

  A5,3 A6,3 A7,3 A8,3

 

When both indices are vectors, it represents the submatrix on the specified rows and columns. For example,

• The submatrix of A between 2nd and 4th rows and between 1st and 5th columns:

A(2 : 4, 1 : 5) −→

 A2,1 A2,2 A2,3 A2,4 A2,5A3,1 A3,2 A3,3 A3,4 A3,5 A4,1 A4,2 A4,3 A4,4 A4,5

 

You are to translate the MATLAB statements in your vectorized mylu into mathematical notations as shown above.

4. (Application of LU factorization: FNC 2.4.6)

(a) Recall the following properties of the determinant from linear algebra: • det(AB) = det(A) det(B). • det(T) = t11t22 · · ·tnn =

∏n i=1 tii, where T ∈ Rn×n is a triangular matrix.

(b) Try to vectorize your code. The function can be written in only couple lines (excluding the function header and the end statement) without using any loop. It would be also useful to recall that if you only want to generate the second output of a certain function, you put ~ in place of the first output argument as a placeholder. For instance, if you only need U from mylu(A), instead of calling it with [L,U] = mylu(A), use

[~, U] = mylu(A);

Note. Use the vectorized version of mylu which you already wrote for Question 3.

5. (Proper usage of lu; FNC 2.6.1) The expression U \ L \ b is equivalent to (U \ L) \ b.

6. (FLOP Counting)

(a) Consider the following example question. Question. How would you code x = ABb most efficiently in MATLAB, and how many flops are needed? Answer. There are only two ways2 to code it: x=A*(B*b) or x=(A*B)*b. If the former is used, MATLAB i. carries out B*b: matrix-by-vector multiplication (∼ 2n2 flops)

2This is the same as x = A*B*b.

3

 

 

ii. left-multiplies the previous result by A: another matrix-by-vector multiplication (∼ 2n2 flops)

In total, it takes ∼ 4n2 flops. On the other hand, the latter version requires the matrix- by-matrix multiplication A*B, which already takes ∼ 2n3 flops. So the former is the efficient one.

Lesson. Avoid matrix-by-matrix multiplication as much as possible! Also remember to use the backslash operator if matrix inversion is required, instead of inv. When \ is invoked, MATLAB in general does a pivoted Gaussian elimination, which takes ∼ (2/3)n3 flops.

7. (Matrix norms; Sp20 midterm) Hints are found in the lecture for 10/01/21 (F).

Re-create at least 1 visual aid from Tufte’s article that you believe would better describe the dangers surrounding the launch.

Expand upon your week 1 discussion posts and in a 3 page double spaced, APA formated document, describing the specific aspects from the Challenger accident that helps us better understand the importance of effective data visualization.

Also, complete the following activity:

  • Re-create at least 1 visual aid from Tufte’s article that you believe would better describe the dangers surrounding the launch.
  • Expound upon Richard Feynman’s congressional investigation and articulate a better argument as to the cause of the accident.
  • What did you learn from this case study?