Question
Please write the code using matlab
1) i. Create an anonymous function named optimist, that accepts a single variable as input i Create a row vector Tthat represents the number of seconds in two minutes, starting ii. Call the function optimist on the vector T, store the result in variable R1 and returns the double of that variable from one and ending at a hundred and twenty v. Create an anonymous function named pessimist, that accepts a single variable as input and returns the half of that variable Call the function pessimist on the vector R1, store the result in variable R2 Create an anonymous function named realist, that accepts a single variable as input and successively applies the functions optimist & pessimist, then returns the result. Hint Functions can be inputs to other functions v. vi. i i Call the function realist on the vector T, store the result in variable R3 Create an anonymous function named empiric, that accepts two variables as input. This function should return one if the input variables are equal, and zero otherwise. Hint: Incorporate a built-in function that determines if all values in a vector are greater than zero. For simplicity, you can assume that this function will only be called with inputs of equal dimensions ix. Call the function empiric on the vectors R2 and R3, store the result in R4 x. Create an anonymous function named nihilist, that accepts a single variable as input and returns zero xi Call the function nihilist on the vector R4, store the result in RS xii Print R5
0 0
Add a comment Improve this question Transcribed image text
Answer #1

i) Please save this code as optimist otherwise it will not work

function f=optimist(a)
f=a.*2;
end

ii)

T=linspace(1,120,120);

------------------------------------------------------------------------------------------------------------------------------------

Output-

T =

Columns 1 through 10

1 2 3 4 5 6 7 8 9 10

Columns 11 through 20

11 12 13 14 15 16 17 18 19 20

Columns 21 through 30

21 22 23 24 25 26 27 28 29 30

Columns 31 through 40

31 32 33 34 35 36 37 38 39 40

Columns 41 through 50

41 42 43 44 45 46 47 48 49 50

Columns 51 through 60

51 52 53 54 55 56 57 58 59 60

Columns 61 through 70

61 62 63 64 65 66 67 68 69 70

Columns 71 through 80

71 72 73 74 75 76 77 78 79 80

Columns 81 through 90

81 82 83 84 85 86 87 88 89 90

Columns 91 through 100

91 92 93 94 95 96 97 98 99 100

Columns 101 through 110

101 102 103 104 105 106 107 108 109 110

Columns 111 through 120

111 112 113 114 115 116 117 118 119 120

iii)

T=linspace(1,120,120);
R1=optimist(T);

---------------------------------------------------------------------------------------------------------------------------------

Output-

R1 =

Columns 1 through 10

2 4 6 8 10 12 14 16 18 20

Columns 11 through 20

22 24 26 28 30 32 34 36 38 40

Columns 21 through 30

42 44 46 48 50 52 54 56 58 60

Columns 31 through 40

62 64 66 68 70 72 74 76 78 80

Columns 41 through 50

82 84 86 88 90 92 94 96 98 100

Columns 51 through 60

102 104 106 108 110 112 114 116 118 120

Columns 61 through 70

122 124 126 128 130 132 134 136 138 140

Columns 71 through 80

142 144 146 148 150 152 154 156 158 160

Columns 81 through 90

162 164 166 168 170 172 174 176 178 180

Columns 91 through 100

182 184 186 188 190 192 194 196 198 200

Columns 101 through 110

202 204 206 208 210 212 214 216 218 220

Columns 111 through 120

222 224 226 228 230 232 234 236 238 240

iv) please save this code with name pessimist otherwise it will not work.

function f=pessimist(a)
f=a./2;
end

v.)

R2=pessimist(R1);

--------------------------------------------------------------------------------------------------------------------------------------

Output-

R2 =

Columns 1 through 10

1 2 3 4 5 6 7 8 9 10

Columns 11 through 20

11 12 13 14 15 16 17 18 19 20

Columns 21 through 30

21 22 23 24 25 26 27 28 29 30

Columns 31 through 40

31 32 33 34 35 36 37 38 39 40

Columns 41 through 50

41 42 43 44 45 46 47 48 49 50

Columns 51 through 60

51 52 53 54 55 56 57 58 59 60

Columns 61 through 70

61 62 63 64 65 66 67 68 69 70

Columns 71 through 80

71 72 73 74 75 76 77 78 79 80

Columns 81 through 90

81 82 83 84 85 86 87 88 89 90

Columns 91 through 100

91 92 93 94 95 96 97 98 99 100

Columns 101 through 110

101 102 103 104 105 106 107 108 109 110

Columns 111 through 120

111 112 113 114 115 116 117 118 119 120

Add a comment
Know the answer?
Add Answer to:
Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please do this problem in matlab and show me the code. Thanks. please do this problem...

    please do this problem in matlab and show me the code. Thanks. please do this problem in Matlab and show me the code. Thanks. Problem #1: Circuits and linear-systems In the last HW you developed the governing equations for the “Wheatstone”-bridge circuit used extensively in engineering applications (shown below). B R R2 A D G m RA с E The resulting equations were solved for the output voltage and currents using the function: function [V_out, I_vector] =Wheatstone_bridge (v_in, R_vector) In...

  • Please write the code in VHDL 1. An entity named reorder has an 8-bit std_logic_vector input...

    Please write the code in VHDL 1. An entity named reorder has an 8-bit std_logic_vector input and an 8-bit std logic_ vector output. The bits of the entity's output vector have the reverse order of the bits of its input vector. The architecture must use a single concurrent call to a function The function, named reorder_vec, is defined in the declaration section and returns a std_logic vector whose bits have the reverse order of the bits in the std_logic vector...

  • Homework 4 – Create your own Function Create your own function in C that accepts one...

    Homework 4 – Create your own Function Create your own function in C that accepts one input number and returns a double number. The themes for the functions should be one of the following:  Calculates 3.14 times of the square of input number. For example, if 2 is input then 12.56 should be returned. (e.g. 3.14*2*2 = 12.56)  Divides the number by 3 and returns the result. For example, if 6 was input then 2.0 should be returned....

  • Create and call a function Using the Visual Basic Editor: create a VBA procedure named call_function...

    Create and call a function Using the Visual Basic Editor: create a VBA procedure named call_function that does the following: Prompts the user, using two input boxes, for the height and the radius of the base of a cone. Calls a function named cone_volume and passes the two values to it. Receives a value back from the function and displays it in a message to the user. Create a function named cone_volume that does the following: Receives the two values...

  • MATLAB ASSIGMENT 1. A. Create a function called ch16initials3 Input: row vector of 101 values (Note:...

    MATLAB ASSIGMENT 1. A. Create a function called ch16initials3 Input: row vector of 101 values (Note: input values are specified in the function call) Output: calculated maximum value Create a row vector A of values from 50 down to 0, with an increment of 0.5 Multiply the elements of A and the square of the elements of the input vector Store the results in B Find the maximum value of B and store it in C – this is the...

  • please do this problem in matlab and show me the code. Thanks. please do this problem...

    please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks.please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me...

  • Problem 5 (programming): Create a MATLAB function named lagrange interp.m to perform interpolation using Lagrange polynomials....

    Problem 5 (programming): Create a MATLAB function named lagrange interp.m to perform interpolation using Lagrange polynomials. Download the template for function lagrange interp.m. The tem Plate is in homework 4 folder utl TritonED·TIue function lakes in the data al nodex.xi and yi, as well as the target x value. The function returns the interpolated value y. Here, xi and yi are vectors while x and y are scalars. You are not required to follow the template; you can create the...

  • Pre-Lab 1. Read this laboratory handout in its entirety. 2. Create a function called sample_mu_var that...

    Pre-Lab 1. Read this laboratory handout in its entirety. 2. Create a function called sample_mu_var that calculates and returns the sample mean and sample variance of a vector of data samples to the calling routine. · Your function accepts the input vector of sample data. Your finction returs bot the smple mca and Do not use MATLAB functions such as mean, var or std to compute your result Your function should include simple error checking. (example: isvector )) . Analytically...

  • I am supposed to a pseudocode function named max that accepts two integer values as arguments...

    I am supposed to a pseudocode function named max that accepts two integer values as arguments and returns the value that is greater of the two. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is greater of the two. Is everything correct and complete? //Pseudocode //This function takes two integers as parameters: x and y Begin : Max(x,y) If(x>y) then MAX=x Else MAX=y End if Return...

  • using this array I need to create a user created function in Matlab that does the...

    using this array I need to create a user created function in Matlab that does the following I have this so far but I'm so lost could you please make this with comments on what the codes do Lure dueren suuj (COM 94 97 95 19 91 88 95 87 90 72 78 60 98 87 81 79 76 69 192 80 77 73 78 70 80 89 81 186 94 901 b. Find the lowest grade in Math subject...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT