Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute MATLAB/Octave Online

% Line starting with "%" is called a comment in MATLAB, this line is ignored by the compiler. Almost all programming language has comment feature. In C, we give comments via "//" and in Python via "#".

% row matrix
% comma or space is used to separate elements of a row
r_matrix1 = [2 4 5 6 7]

r_matrix2 = [2, 4, 5, 6, 7]

% column matrix
% semicolon is used to separate rows
c_matrix = [2; 3; 4; 5; 7]

% 3*3 square matrix
sq_matrix = [1 2 3; 4 5 6; 7 8 9]

% diagonal matrix
diag_matrix1 = [1 0 0; 0 2 0; 0 0 3]

% D = diag(v) returns a square diagonal matrix with the elements of vector v on the main diagonal.
diag_matrix2 = diag(r_matrix1)

diag_matrix3 = diag([1,2,3])


%Addition, Subtraction, Multiplication 
m1 = [10 2 3; 14 5 6; 1 8 9]
m2 = [-11 7 8; 14 -5 6; 0 -1 9]

sum = m1 + m2
diff = m1 - m2

mul = m1 * m2

%Matrix divison in MATLAB has two types - right division, left divsion

%Matrix right division. B/A is roughly the same as B*inv(A). More precisely, B/A = (A'\B')'.
rdiv = m1/m2

%matrix left division. If A is a square matrix, A\B is roughly the same as inv(A)*B.
ldiv = m1\m2

%determinant
m = [ 1 2 3; 2 3 4; 1 2 5]
d = det(m)    

%transpose
mT = m'

%inverse
mI = inv(m)

%If the matrix is singular i.e. the determinant of the matrix is zero, then the inverse does not exist.

m2 = [0 0; 0 0]   % 2*2 matrix
d2 = det(m2)      % determinant will be 0
mI2 = inv(m2)     % inverse not possible, so you will warning by MATLAB coz of this 

%Eigenvalue
% e = eig(A) returns a column vector containing the eigenvalues of square matrix A.

e = eig(m)  % matrix m is defined earlier as [ 1 2 3; 2 3 4; 1 2 5]

%Operations
A = [1 2 3; 2 3 4; 1 2 5]
B = [-3 4 7; 5 8 -2; 0 1 3]

% X^p is X to the power p, if p is a scalar. If p is an integer, the power is computed by repeated squaring. You will learn about this method in Algorihtm course.

result1  = (A + B)^2     % could have done this also: (A + B) * (A + B)

result2  = A^2 + B^2     % could have done this also: A*A + B*B 

result3  = A' * B' 

result4  = B' * A

result5  = A^2 + B^2 - A*B + B'*A'

det_AB = det(A*B)

det_BA = det(B*A)







Execute MATLAB/Octave Online

x = [1 2 3 4 5 6 7 8 9 10];
y1 = [.16 .08 .04 .02 .013 .007 .004 .002 .001 .0008 ];
y2 = [.16 .07 .03 .01 .008 .003 .0008 .0003 .00007 .00002 ];

semilogy(x,y1,'-bo;y1;',x,y2,'-kx;y2;');
title('Plot title');
xlabel('X Axis');
ylabel('Y Axis');

print -dpng figure.png

Execute MATLAB/Octave Online

clear all
close all
clc

%Gaurav Sharma
%AERO 6330
%Hw 3

format long;

time = 0.3; %total time of computations
delt = 0.01; %step size

%Initial conditions
t(1) = 0.0;
x(1) = 1.0;
y(1) = 2.0;
z(1) = 3.0;
vx(1) = 2.0;
vy(1) = 3.0;
vz(1) = 4.0;

syms t vx vy vz x y z;
fx = symfun (6*vx-9*x, [t x y z vx vy vz]);
syms t vx vy vz x y z;
fy = symfun (6*vy-9*y, [t x y z vx vy vz]);
syms t vx vy vz x y z;
fz = symfun (6*vz-9*z, [t x y z vx vy vz]);

vxdot = fx(t, vx, vy, vz, x, y, z); %(t,r,v); %fx = 6*vx-9*x;
vydot = fy(t, vx, vy, vz, x, y, z); %(t,r,v); %fy = 6*vy-9*y;
vzdot = fz(t, vx, vy, vz, x, y, z); %(t,r,v); %fz = 6*vz-9*z;

%vdot = [vxdot vydot vzdot];
% v = [vx vy vz];
% r = [x y z];

index = 0.0;

for i=1:delt:time+1;

k1x = delt*fx(t,x,y,z,vx,vy,vz);
k1y = delt*fy(t,x,y,z,vx,vy,vz);
k1z = delt*fz(t,x,y,z,vx,vy,vz);

k2x = delt*fx((t+(delt/2)),(x+(delt*vx)/2),(y+(delt*vy)/2),(z+(delt*vz)/2),(vx+(k1x/2)),(vy+(k1y/2)),(vz+(k1z/2)));
k2y = delt*fy((t+(delt/2)),(x+(delt*vx)/2),(y+(delt*vy)/2),(z+(delt*vz)/2),(vx+(k1x/2)),(vy+(k1y/2)),(vz+(k1z/2)));
k2z = delt*fz((t+(delt/2)),(x+(delt*vx)/2),(y+(delt*vy)/2),(z+(delt*vz)/2),(vx+(k1x/2)),(vy+(k1y/2)),(vz+(k1z/2)));

k2x

k3x = delt*fx((t+(delt/2)),(x+((delt*vx)/2)+((delt*k1x)/4)),(y+((delt*vy)/2)+((delt*k1y)/4)),(z+((delt*vz)/2)+((delt*k1z)/4)),(vx+(k2x/2)),(vy+(k2y/2)),(vz+(k2z/2)));
k3y = delt*fy((t+(delt/2)),(x+((delt*vx)/2)+((delt*k1x)/4)),(y+((delt*vy)/2)+((delt*k1y)/4)),(z+((delt*vz)/2)+((delt*k1z)/4)),(vx+(k2x/2)),(vy+(k2y/2)),(vz+(k2z/2)));
k3z = delt*fz((t+(delt/2)),(x+((delt*vx)/2)+((delt*k1x)/4)),(y+((delt*vy)/2)+((delt*k1y)/4)),(z+((delt*vz)/2)+((delt*k1z)/4)),(vx+(k2x/2)),(vy+(k2y/2)),(vz+(k2z/2)));

k4x = delt*fx((t+delt),(x+(delt*vx)+((delt*k2x)/2)),(y+(delt*vy)+((delt*k2y)/2)),(z+(delt*vz)+((delt*k2z)/2)),(vx+k3x),(vy+k3y),(vz+k3z));
k4y = delt*fy((t+delt),(x+(delt*vx)+((delt*k2x)/2)),(y+(delt*vy)+((delt*k2y)/2)),(z+(delt*vz)+((delt*k2z)/2)),(vx+k3x),(vy+k3y),(vz+k3z));
k4z = delt*fz((t+delt),(x+(delt*vx)+((delt*k2x)/2)),(y+(delt*vy)+((delt*k2y)/2)),(z+(delt*vz)+((delt*k2z)/2)),(vx+k3x),(vy+k3y),(vz+k3z));

%updating time
t = t + delt;

%updating position
x(index+1) = x(index) + (delt*vx(index)) + ((delt*(k1x + k2x + k3x))/6);
y(index+1) = y(index) + (delt*vy(index)) + ((delt*(k1y + k2y + k3y))/6);
z(index+1) = z(index) + (delt*vz(index)) + ((delt*(k1z + k2z + k3z))/6);

%updating velocity
vx(index+1) = vx(i) + ((k1x + 2*k2x + 2*k3x + k4x)/6);
vy(index+1) = vy(i) + ((k1y + 2*k2y + 2*k3y + k4y)/6);
vz(index+1) = vz(i) + ((k1z + 2*k2z + 2*k3z + k4z)/6);

index = index + 1;
end

vx
vy
vz

x
y
z

test1

x = [1 2 3 4 5 6 7 8 9 10];
y1 = [.16 .08 .04 .02 .013 .007 .004 .002 .001 .0008 ];
y2 = [.16 .07 .03 .01 .008 .003 .0008 .0003 .00007 .00002 ];

semilogy(x,y1,'-bo;y1;',x,y2,'-kx;y2;');
title('Plot title');
xlabel('X Axis');
ylabel('Y Axis');

print -dpng figure.png

test

x = [1 2 3 4 5 6 7 8 9 10];
y1 = [.16 .08 .04 .02 .013 .007 .004 .002 .001 .0008 ];
y2 = [.16 .07 .03 .01 .008 .003 .0008 .0003 .00007 .00002 ];

semilogy(x,y1,'-bo;y1;',x,y2,'-kx;y2;');
F=4+6

scaa

x = [1 2 3 4 5 6 7 8 9 10];
y1 = [.16 .08 .04 .02 .013 .007 .004 .002 .001 .0008 ];
y2 = [.16 .07 .03 .01 .008 .003 .0008 .0003 .00007 .00002 ];

semilogy(x,y1,'-bo;y1;',x,y2,'-kx;y2;');
title('Plot title');
xlabel('X Axis');
ylabel('Y Axis');

print -dpng figure.png

https://github.com/opencobra/cobratoolbox

x = [1 2 3 4 5 6 7 8 9 10];
y1 = [.16 .08 .04 .02 .013 .007 .004 .002 .001 .0008 ];
y2 = [.16 .07 .03 .01 .008 .003 .0008 .0003 .00007 .00002 ];

semilogy(x,y1,'-bo;y1;',x,y2,'-kx;y2;');
title('Plot title');
xlabel('X Axis');
ylabel('Y Axis');

print -dpng figure.png

trretet

S = 'HEX to BIN';
disp(S)

HEX='4fcb0fb818159a00'
hex_to_bin=dec2bin(hex2dec(HEX));
printf("BIN = %s\n",hex_to_bin)
printf("LEN = %d\n",length(hex_to_bin))
%disp(hex_to_bin)
%for i = (length(hex_to_bin)):-1:1
for i = 1:(length(hex_to_bin))
    y=str2num(hex_to_bin(i));
    x=[i-1,y];
    disp(x)
    new_arr(1,i)=i-1;
    new_arr(2,i)=num2str(y);
end

Execute MATLAB/Octave Online

x = [1 2 3 4 5 6 7 8 9 10];
y1 = [.16 .08 .04 .02 .013 .007 .004 .002 .001 .0008 ];
y2 = [.16 .07 .03 .01 .008 .003 .0008 .0003 .00007 .00002 ];

semilogy(x,y1,'-bo;y1;',x,y2,'-kx;y2;');
title('Plot title');
xlabel('X Axis');
ylabel('Y Axis');

print -dpng figure.png

wsfdsfdf

x = [1 2 3 4 5 6 7 8 9 10];

disp(x)



index = 1;
while 1
    if (index +1) > (length(x))
        % End of array
        break
    end
    
    if (x(index)) - x(index +1) < -2
        % Pass it.
        break
    end
    
    disp(x(index));
    index++;
end

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.