Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Requirements: this exercise, you will write a function trough_create that create

ID: 3587461 • Letter: R

Question

Requirements: this exercise, you will write a function trough_create that creates the vectors y and ye that form the outline for the cross-section of a trough. Input variables: Func -Any arbitrary function of x in MATLAB, eg. Func = @(x) x^2-4 EndPoint - The final value within the x vector. Output variables: xa linearly spaced vector with 119 elements. It starts at 0 and ends at EndPoint ythe vector Func(x); ye - a vector that has the same element as x, but where each element is equal to the initial value for y. Potentially Useful Functions: linspace, ones. Function Template: function [x,y,ye] % INSERT CODE trough-create(Func , EndPoint) HERE - end

Explanation / Answer

%arbitary function
Func = @(x) x.^2-4;

function [x,y,y0] = trough_create(Func,EndPoint)

%create x vector
  
x = linspace(0,EndPoint,119)
  
%pass x vector to Func and store the result vector in y
  
y = Func(x)
  
% create a y0 vector same size as x and multily the vector with a scalar of first element in y
y0 = ones(size(x))*y(1)

end

%call function
trough_create(Func,118);

%%%%%%%%%%%%%%%%%%%%%

sample output

x =

Columns 1 through 13:

0 1 2 3 4 5 6 7 8 9 10 11 12

Columns 14 through 26:

13 14 15 16 17 18 19 20 21 22 23 24 25

Columns 27 through 39:

26 27 28 29 30 31 32 33 34 35 36 37 38

Columns 40 through 52:

39 40 41 42 43 44 45 46 47 48 49 50 51

Columns 53 through 65:

52 53 54 55 56 57 58 59 60 61 62 63 64

Columns 66 through 78:

65 66 67 68 69 70 71 72 73 74 75 76 77

Columns 79 through 91:

78 79 80 81 82 83 84 85 86 87 88 89 90

Columns 92 through 104:

91 92 93 94 95 96 97 98 99 100 101 102 103

Columns 105 through 117:

104 105 106 107 108 109 110 111 112 113 114 115 116

Columns 118 and 119:

117 118

y =

Columns 1 through 10:

-4 -3 0 5 12 21 32 45 60 77

Columns 11 through 20:

96 117 140 165 192 221 252 285 320 357

Columns 21 through 30:

396 437 480 525 572 621 672 725 780 837

Columns 31 through 40:

896 957 1020 1085 1152 1221 1292 1365 1440 1517

Columns 41 through 50:

1596 1677 1760 1845 1932 2021 2112 2205 2300 2397

Columns 51 through 60:

2496 2597 2700 2805 2912 3021 3132 3245 3360 3477

Columns 61 through 70:

3596 3717 3840 3965 4092 4221 4352 4485 4620 4757

Columns 71 through 80:

4896 5037 5180 5325 5472 5621 5772 5925 6080 6237

Columns 81 through 90:

6396 6557 6720 6885 7052 7221 7392 7565 7740 7917

Columns 91 through 100:

8096 8277 8460 8645 8832 9021 9212 9405 9600 9797

Columns 101 through 110:

9996 10197 10400 10605 10812 11021 11232 11445 11660 11877

Columns 111 through 119:

12096 12317 12540 12765 12992 13221 13452 13685 13920

y0 =

Columns 1 through 20:

-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4

Columns 21 through 40:

-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4

Columns 41 through 60:

-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4

Columns 61 through 80:

-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4

Columns 81 through 100:

-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4

Columns 101 through 119:

-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4

%%%%%%%%%%%%%%%%%%%%%%

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote