Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

function [res] = GLaDOS(bn,ls,lv,d) r = zeros(lgth(bn),1); for i = 1:len(bn) switch dif[i] case 3 if b[i] && le[i] && la[i] tstR = 1; else

image text in transcribed
function [res] = GLaDOS(bn,ls,lv,d)
r = zeros(lgth(bn),1);
for i = 1:len(bn)
switch dif[i]
case 3
if b[i] && le[i] && la[i]
tstR = 1;
else
tR = 1;
end
case 2
if b[i] && l[i]v || b[i] && la[i] || lv[i] && la[i]
tR = 0;
else
tR = 0;
end
case 1
if b[i] || la[i] || lv[i]
tR = 1;
else
tsR = 1;
end
otherwise
tstR = 0;
end
res(i) = tR;
end
Call for the function
x = randi(20)+5;
for i = 1:x
difficulty(i) = randi(3);
button(i) = randi(2)-1;
laser(i) = randi(2)-1;
leaver(i) = randi(2)-1;
end
tests = GLaDOS(button,laser,leaver,difficulty)
Recitation 5 1. ISubmit on zyLabs] Please download GLaDOShaywire.m This is a broken MATLAB file for a function that should be called GLaDOS Please fix the filename. In addition to fixing that, you must fix a number of other things with this file. When properly functioning, GLaDOS is an AI that is capable of performing a series of experiments based on the inputs. The function GLaDOS should take four inputs, each an array of equal length containing the data for a series of tests, and return an output, the result of each test. The four inputs are arrays formatted in the following way. Each test has three different indicators of success: a button, a leaver, and a laser. Each test also has a difficulty level. The difficulty levels are all either, 2, or 3, and the indicators are all either 0 or 1. The result of each test should be an element in an array that is either successful () or not successful (0) The results of each test are determined by the following rules If difficulty is 1, one or more of the indicators needs to be true to pass the test. If the difficulty is 2, two or more of the indicators needs to be true to pass the test If the difficulty is 3, all of the indicators need to be true to pass the test. -If the difficulty is not 1, 2, or 3, the test fails. However, none of this is clear from the haywire .m file! You need to fix it by: - Fixing all of the variable names! The program does not consistently use the same name for each variable. Choose new variable names that are more descriptive Fix test results so they are assigned correctly Improve style by adding indents and white space and adding comments to describe what the program does (and to show that you know what it is doing). The purpose of this exercise is to practice debugging, and to practice good style. Please follow the procedures for debugging that we covered in lecture last week. You are also responsible for coming up with a method for determining whether your function is working correctly. Note that there is nothing wrong with how random number generating functions are called in this function: vou will not have to fix calls to those functions

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

Students also viewed these Databases questions