A = zeros(3,3,2) A(:,:,1) = 0 0 0 0 0 0 0 0 0 A(:,:,2) = 0 0 0 0 0 0 0 0 0 ndims(A) ans = 3 A = [4 6 1; 5 8 0; 3 9 2] A = 4 6 1 5 8 0 3 9 2 B = [6 2 9; 0 3 1; 4 7 5] B = 6 2 9 0 3 1 4 7 5 A A = 4 6 1 5 8 0 3 9 2 ndims(A) ans = 2 C = A C = 4 6 1 5 8 0 3 9 2 C(:,:,2) = B C(:,:,1) = 4 6 1 5 8 0 3 9 2 C(:,:,2) = 6 2 9 0 3 1 4 7 5 D = cat(3,A,B) D(:,:,1) = 4 6 1 5 8 0 3 9 2 D(:,:,2) = 6 2 9 0 3 1 4 7 5 C-D ans(:,:,1) = 0 0 0 0 0 0 0 0 0 ans(:,:,2) = 0 0 0 0 0 0 0 0 0 Dnew = cat(4,A,B) Dnew(:,:,1,1) = 4 6 1 5 8 0 3 9 2 Dnew(:,:,1,2) = 6 2 9 0 3 1 4 7 5 E = cat(1,A,B) E = 4 6 1 5 8 0 3 9 2 6 2 9 0 3 1 4 7 5 F = cat(2,A,B) F = 4 6 1 6 2 9 5 8 0 0 3 1 3 9 2 4 7 5 D D(:,:,1) = 4 6 1 5 8 0 3 9 2 D(:,:,2) = 6 2 9 0 3 1 4 7 5 D(2,3,1) ans = 0 D(1,2,2) ans = 2 f = [9, -5, 3, 7] f = 9 -5 3 7 r = roots(f) r = 0.6137 + 0.8839i 0.6137 - 0.8839i -0.6718 fnew = poly(r) fnew = 1.0000 -0.5556 0.3333 0.7778 9*fnew-f ans = 1.0e-013 * 0 0.0711 -0.0666 -0.1155 x = ([0:2:10])' x = 0 2 4 6 8 10 y1 = 9*x.^3-5*x.^2+3*x+7 y1 = 7 65 515 1789 4319 8537 y2 = polyval(f,x) y2 = 7 65 515 1789 4319 8537 g = [6, -1, 2] g = 6 -1 2 product = conv(f,g) product = 54 -39 41 29 -1 14 [quotient, remainder] = deconv(f,g) quotient = 1.5000 -0.5833 remainder = 0 0 -0.5833 8.1667 f+g ??? Error using ==> plus Matrix dimensions must agree. f+[0 g] ans = 9 1 2 9 help conv CONV Convolution and polynomial multiplication. C = CONV(A, B) convolves vectors A and B. The resulting vector is length LENGTH(A)+LENGTH(B)-1. If A and B are vectors of polynomial coefficients, convolving them is equivalent to multiplying the two polynomials. Class support for inputs A,B: float: double, single See also deconv, conv2, convn, filter and, in the Signal Processing Toolbox, XCORR, CONVMTX. Reference page in Help browser doc conv help conv2 CONV2 Two dimensional convolution. C = CONV2(A, B) performs the 2-D convolution of matrices A and B. If [ma,na] = size(A) and [mb,nb] = size(B), then size(C) = [ma+mb-1,na+nb-1]. C = CONV2(H1, H2, A) convolves A first with the vector H1 along the rows and then with the vector H2 along the columns. C = CONV2(..., SHAPE) returns a subsection of the 2-D convolution with size specified by SHAPE: 'full' - (default) returns the full 2-D convolution, 'same' - returns the central part of the convolution that is the same size as A. 'valid' - returns only those parts of the convolution that are computed without the zero-padded edges. size(C) = [ma-mb+1,na-nb+1] when all(size(A) >= size(B)), otherwise C is an empty matrix []. If any of A, B, H1, and H2 are empty, then C is an empty matrix []. See also conv, convn, filter2 and, in the Signal Processing Toolbox, XCORR2. Overloaded functions or methods (ones with the same name in other directories) help uint8/conv2.m help uint16/conv2.m Reference page in Help browser doc conv2 dt = 1 dt = 1 tol = 0.1 tol = 0.1000 uiopen('F:\EGM4344\Lecture 9\Working\skydiver_func.m', true); m = 68.1; g = 9.81; c = 0.25; [t, v] = skydiver_func(m,g,c,dt,tol); The numerical final velocity is 51.5753 m/s and the analytical final velocity is 51.3466 m/s. The final time is 15.0000 sec. plot(t,v) clear A B A(1,1) = {'dt'} A = 'dt' A(1,2) = {'tol'} A = 'dt' 'tol' A(2,1) = {dt} A = 'dt' 'tol' [ 1] [] A(2,2) = {tol} A = 'dt' 'tol' [ 1] [0.1000] A(3,1) = {'time'} A = 'dt' 'tol' [ 1] [0.1000] 'time' [] A(3,2) = {'speed'} A = 'dt' 'tol' [ 1] [0.1000] 'time' 'speed' A(4,1) = {t} A = 'dt' 'tol' [ 1] [0.1000] 'time' 'speed' [16x1 double] [] A(4,2) = {v} A = 'dt' 'tol' [ 1] [ 0.1000] 'time' 'speed' [16x1 double] [16x1 double] time = A{4,1} time = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 iscell(time) ans = 0 clear time time = A(4,1) time = [16x1 double] iscell(time) ans = 1 B{1,1} = 'dt' B = 'dt' B{1,2} = 'tol' B = 'dt' 'tol' B{2,1} = dt; B{2,2} = tol; B B = 'dt' 'tol' [ 1] [0.1000] celldisp(A) A{1,1} = dt A{2,1} = 1 A{3,1} = time A{4,1} = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 A{1,2} = tol A{2,2} = 0.1000 A{3,2} = speed A{4,2} = 0 9.8100 19.2667 27.7140 34.7044 40.0930 44.0019 46.7041 48.5065 49.6789 50.4287 50.9030 51.2008 51.3870 51.5031 51.5753 cellplot(A) C = cell(3,2) C = [] [] [] [] [] [] clear C C = {'dt', 'tol'; dt, tol} C = 'dt' 'tol' [ 1] [0.1000] Results.StepLabel = 'dt' Results = StepLabel: 'dt' Results.TolLabel = 'tol' Results = StepLabel: 'dt' TolLabel: 'tol' Results.StepValue = dt Results = StepLabel: 'dt' TolLabel: 'tol' StepValue: 1 Results.TolValue = tol Results = StepLabel: 'dt' TolLabel: 'tol' StepValue: 1 TolValue: 0.1000 Results.TimeLabel = 'time' Results = StepLabel: 'dt' TolLabel: 'tol' StepValue: 1 TolValue: 0.1000 TimeLabel: 'time' Results.SpeedLabel = 'speed' Results = StepLabel: 'dt' TolLabel: 'tol' StepValue: 1 TolValue: 0.1000 TimeLabel: 'time' SpeedLabel: 'speed' Results.TimeValue = t; Results.SpeedValue = v; Results Results = StepLabel: 'dt' TolLabel: 'tol' StepValue: 1 TolValue: 0.1000 TimeLabel: 'time' SpeedLabel: 'speed' TimeValue: [16x1 double] SpeedValue: [16x1 double] Results.TimeValue ans = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Results.SpeedValue ans = 0 9.8100 19.2667 27.7140 34.7044 40.0930 44.0019 46.7041 48.5065 49.6789 50.4287 50.9030 51.2008 51.3870 51.5031 51.5753 dt = 2; clear t v [t, v] = skydiver_func(m,g,c,dt,tol) The numerical final velocity is 51.6713 m/s and the analytical final velocity is 51.1871 m/s. The final time is 14.0000 sec. t = 0 2 4 6 8 10 12 14 v = 0 19.6200 36.4137 46.2983 50.1802 51.3123 51.6008 51.6713 Results(2) = Results Results = 1x2 struct array with fields: StepLabel TolLabel StepValue TolValue TimeLabel SpeedLabel TimeValue SpeedValue Results(1) ans = StepLabel: 'dt' TolLabel: 'tol' StepValue: 1 TolValue: 0.1000 TimeLabel: 'time' SpeedLabel: 'speed' TimeValue: [16x1 double] SpeedValue: [16x1 double] Results(2) ans = StepLabel: 'dt' TolLabel: 'tol' StepValue: 1 TolValue: 0.1000 TimeLabel: 'time' SpeedLabel: 'speed' TimeValue: [16x1 double] SpeedValue: [16x1 double] Results.StepValue = 2 ??? Incorrect number of right hand side elements in dot name assignment. Missing [] around left hand side is a likely cause. Results(2).StepValue = 2 Results = 1x2 struct array with fields: StepLabel TolLabel StepValue TolValue TimeLabel SpeedLabel TimeValue SpeedValue Results(2) ans = StepLabel: 'dt' TolLabel: 'tol' StepValue: 2 TolValue: 0.1000 TimeLabel: 'time' SpeedLabel: 'speed' TimeValue: [16x1 double] SpeedValue: [16x1 double] Results(2).TimeValue = t; Results(2).SpeedValue = v; Results(2) ans = StepLabel: 'dt' TolLabel: 'tol' StepValue: 2 TolValue: 0.1000 TimeLabel: 'time' SpeedLabel: 'speed' TimeValue: [8x1 double] SpeedValue: [8x1 double] names = fieldnames(Results) names = 'StepLabel' 'TolLabel' 'StepValue' 'TolValue' 'TimeLabel' 'SpeedLabel' 'TimeValue' 'SpeedValue' second_step = Results(2).StepValue second_step = 2 second_step = getfield(Results(2),'StepValue') second_step = 2 isfield(Results,'StepValue') ans = 1 isstruct(Results) ans = 1 isstruct(v) ans = 0 Test = Results(2) Test = StepLabel: 'dt' TolLabel: 'tol' StepValue: 2 TolValue: 0.1000 TimeLabel: 'time' SpeedLabel: 'speed' TimeValue: [8x1 double] SpeedValue: [8x1 double] Test = rmfield(Test, 'SpeedValues') ??? Error using ==> rmfield at 41 A field named 'SpeedValues' doesn't exist. Test = rmfield(Test, 'SpeedValue') Test = StepLabel: 'dt' TolLabel: 'tol' StepValue: 2 TolValue: 0.1000 TimeLabel: 'time' SpeedLabel: 'speed' TimeValue: [8x1 double] Test = setfield(Test, 'SpeedValue', v) Test = StepLabel: 'dt' TolLabel: 'tol' StepValue: 2 TolValue: 0.1000 TimeLabel: 'time' SpeedLabel: 'speed' TimeValue: [8x1 double] SpeedValue: [8x1 double]