>> 2+2 ans = 4 >> x = 2+2 x = 4 >> x x = 4 >> y = x + x y = 8 >> x = x^x x = 256 >> y = 2*x/5 y = 102.4000 >> (exp(2)-exp(-2))/2 ans = 3.6269 >> sinh(2) ans = 3.6269 >> log(2) ans = 0.6931 >> log 2 Undefined function 'log' for input arguments of type 'char'. >> 4+log(3) ans = 5.0986 >> cos(pi/3) ans = 0.5000 >> log10(1000) ans = 3 >> log7(1000) Undefined function or variable 'log7'. >> nthroot(8,3) ans = 2 >> nthroot(3,8) ans = 1.1472 >> ans^8 ans = 3.0000 >> format long >> nthroot(3,8) ans = 1.147202690439877 >> ans^8 ans = 3.000000000000000 >> z = 4 + 2*i z = 4.000000000000000 + 2.000000000000000i >> z = 4 + 2i z = 4.000000000000000 + 2.000000000000000i >> z = (4-3*i)/(4+2*i) z = 0.500000000000000 - 1.000000000000000i >> z = (4-3*i) /(4+ 2*i) z = 0.500000000000000 - 1.000000000000000i >> real(z) ans = 0.500000000000000 >> imag(z) ans = -1 >> abs(z) ans = 1.118033988749895 >> angle(z) ans = -1.107148717794090 >> ans*180/pi ans = -63.434948822922010 >> >> >> [3 7.1 9.2 1.3] ans = 3.000000000000000 7.100000000000000 9.199999999999999 1.300000000000000 >> [3 6+1.1 9.2 1.3] ans = 3.000000000000000 7.100000000000000 9.199999999999999 1.300000000000000 >> [3 6 +1.1 9.2 1.3] ans = Columns 1 through 4 3.000000000000000 6.000000000000000 1.100000000000000 9.199999999999999 Column 5 1.300000000000000 >> [3 6+1.1 9.2 1.3] ans = 3.000000000000000 7.100000000000000 9.199999999999999 1.300000000000000 >> [3,6+1.1,9.2,1.3] ans = 3.000000000000000 7.100000000000000 9.199999999999999 1.300000000000000 >> v = [3,6+1.1,9.2,1.3] v = 3.000000000000000 7.100000000000000 9.199999999999999 1.300000000000000 >> v = [3;6+1.1;9.2;1.3] v = 3.000000000000000 7.100000000000000 9.199999999999999 1.300000000000000 >> v = [3,6+1.1,9.2,1.3]' v = 3.000000000000000 7.100000000000000 9.199999999999999 1.300000000000000 >> v = [3,6+1.1,9.2,1.3] v = 3.000000000000000 7.100000000000000 9.199999999999999 1.300000000000000 >> v = [3,6+1.1,9.2,1.3]' v = 3.000000000000000 7.100000000000000 9.199999999999999 1.300000000000000 >> sqrt(v) ans = 1.732050807568877 2.664582518894846 3.033150177620620 1.140175425099138 >> w = 1:4 w = 1 2 3 4 >> w = 1:0.5:4 w = Columns 1 through 4 1.000000000000000 1.500000000000000 2.000000000000000 2.500000000000000 Columns 5 through 7 3.000000000000000 3.500000000000000 4.000000000000000 >> w = 1:4 w = 1 2 3 4 >> v v = 3.000000000000000 7.100000000000000 9.199999999999999 1.300000000000000 >> v = v' v = 3.000000000000000 7.100000000000000 9.199999999999999 1.300000000000000 >> v*w Error using * Inner matrix dimensions must agree. >> v .* w ans = 3.000000000000000 14.199999999999999 27.599999999999998 5.200000000000000 >> v ./ w ans = 3.000000000000000 3.550000000000000 3.066666666666666 0.325000000000000 >> >> >> >> >> >> t = 0:0.1:1 t = Columns 1 through 4 0 0.100000000000000 0.200000000000000 0.300000000000000 Columns 5 through 8 0.400000000000000 0.500000000000000 0.600000000000000 0.700000000000000 Columns 9 through 11 0.800000000000000 0.900000000000000 1.000000000000000 >> -t.^2 ans = Columns 1 through 4 0 -0.010000000000000 -0.040000000000000 -0.090000000000000 Columns 5 through 8 -0.160000000000000 -0.250000000000000 -0.360000000000000 -0.490000000000000 Columns 9 through 11 -0.640000000000000 -0.810000000000000 -1.000000000000000 >> exp(-t.^2) ans = Columns 1 through 4 1.000000000000000 0.990049833749168 0.960789439152323 0.913931185271228 Columns 5 through 8 0.852143788966211 0.778800783071405 0.697676326071031 0.612626394184416 Columns 9 through 11 0.527292424043049 0.444858066222941 0.367879441171442 >> y = t.*exp(-t.^2) y = Columns 1 through 4 0 0.099004983374917 0.192157887830465 0.274179355581369 Columns 5 through 8 0.340857515586485 0.389400391535702 0.418605795642619 0.428838475929091 Columns 9 through 11 0.421833939234439 0.400372259600647 0.367879441171442 >> >> >> plot(t,y) >> plot(t,y,'o-') >> >> >> >> t = 0:0.01:1; >> y = t.*exp(-t.^2); >> who Your variables are: ans t v w x y z >> whos Name Size Bytes Class Attributes ans 1x11 88 double t 1x101 808 double v 1x4 32 double w 1x4 32 double x 1x1 8 double y 1x101 808 double z 1x1 16 double complex >> plot(t,y) >> plot(t,y,'o-') >> >> >> help cross cross Vector cross product. C = cross(A,B) returns the cross product of the vectors A and B. That is, C = A x B. A and B must be 3 element vectors. C = cross(A,B) returns the cross product of A and B along the first dimension of length 3. C = cross(A,B,DIM), where A and B are N-D arrays, returns the cross product of vectors in the dimension DIM of A and B. A and B must have the same size, and both SIZE(A,DIM) and SIZE(B,DIM) must be 3. Class support for inputs A,B: float: double, single See also dot. Reference page for cross >> >> >> >> >> A = [1 2 0; 2 5 -1; 4,10,-1] A = 1 2 0 2 5 -1 4 10 -1 >> A = [1 2 0; 2 5 -1 4,10,-1] A = 1 2 0 2 5 -1 4 10 -1 >> Q = [1 2 3;4 5 6;7 8 9] Q = 1 2 3 4 5 6 7 8 9 >> A+Q ans = 2 4 3 6 10 5 11 18 8 >> Q .* A ans = 1 4 0 8 25 -6 28 80 -9 >> Q * A ans = 17 42 -5 38 93 -11 59 144 -17 >> >> >> Q / A ans = 1 -6 3 10 -9 3 19 -12 3 >> Q*inv(A) ans = 1 -6 3 10 -9 3 19 -12 3 >> inv(A)*Q ans = -1 4 9 1 -1 -3 -1 -2 -3 >> A\Q ans = -1 4 9 1 -1 -3 -1 -2 -3 >> A/Q Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.652118e-18. ans = 1.0e+17 * -0.094575592174780 0.189151184349561 -0.094575592174780 -0.283726776524341 0.567453553048682 -0.283726776524341 -0.535928355657089 1.071856711314178 -0.535928355657089 >> >> >> >> b = [4 5 6]' b = 4 5 6 >> x = A\b x = 18 -7 -4 >> A*x ans = 4 5 6 >> >> >> >> A = randn(6000,6000); >> whos Name Size Bytes Class Attributes A 6000x6000 288000000 double Q 3x3 72 double ans 3x1 24 double b 3x1 24 double t 1x101 808 double v 1x4 32 double w 1x4 32 double x 3x1 24 double y 1x101 808 double z 1x1 16 double complex >> b = randn(6000,1); >> tic, x = A\b; toc Elapsed time is 2.421418 seconds. >> >> >> >> eye(5) ans = 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 >> det(A) ans = Inf >> A = [1 2 0; 2 5 -1; 4,10,-1] A = 1 2 0 2 5 -1 4 10 -1 >> det(A) ans = 1 >> det(Q) ans = -9.516197353929915e-16 >> exempel1 >> >> >> exempel1 >> >> >> k = 0:31; >> termer = (k.^2+1).*sin(pi*k/8) termer = 1.0e+02 * Columns 1 through 4 0 0.007653668647302 0.035355339059327 0.092387953251129 Columns 5 through 8 0.170000000000000 0.240208678452935 0.261629509039023 0.191341716182545 Columns 9 through 12 0.000000000000000 -0.313800414539374 -0.714177848998413 -1.127133029663770 Columns 13 through 16 -1.450000000000000 -1.570595205269187 -1.393000358937499 -0.864864557145104 Columns 17 through 20 -0.000000000000001 1.109781953858761 2.298097038856279 3.344443907690857 Columns 21 through 24 4.010000000000000 4.083547533699887 3.429467888754759 2.028222191534980 Columns 25 through 28 0.000000000000002 -2.395598286605462 -4.787112908632929 -6.744320587332391 Columns 29 through 32 -7.850000000000000 -7.779065663745034 -6.371032098490802 -3.681414619352172 >> sum(termer) ans = -2.573997819968435e+03 >> k = 0:31; >> sum((k.^2+1).*sin(pi*k/8)) ans = -2.573997819968435e+03 >> >> >> k = 1:4 k = 1 2 3 4 >> faktorer = (10-k+1)./k faktorer = 10.000000000000000 4.500000000000000 2.666666666666667 1.750000000000000 >> prod(faktorer) ans = 210 >> prod((10-k+1)./k) ans = 210 >> nchoosek(10,4) ans = 210 >> publish('exempel1','pdf') ans = /Users/jove/Desktop/Arbete_laptop/M0031M/Matlab/html/exempel1.pdf >>