% This is a good idea clear ; % This creates reserves a memory adress and stores the % value three in this memory dress my_variable1 = 3. % Create another variable, you can use the contents of old variables my_variable2 = my_variable1 + 2. % Replaces the contents of a given memory adress by the current % contents of this adress(i.e. 3.) + 2.1 my_variable1 = my_variable1 + 2.1 % Create an array or a bunch of variables at one time: % % t(1) = 0, t(1) = .1, t(2) = 0.2, t(3) = 0.3 t = [0:0.1:0.3] t(4) = t(2) + t(4) % Create a new array which has the same length as t % x(1) = 0, x(2) = 0 x = zeros(1, length(t)) % % Now x(1) = t(1), x(2) = t(2), ... x = t % Now x2(1) = t(1)^2, x2(2)= t(2)^2, .... % Notice the .* notation which does an element wise multiplaction % Be sure to inclue the . otherwise you will get some unexpected behaviour x2 = t.*t % % You can also raise this to a power 3 % x3(1)=t(1)^3 x3(2) =t(2)^3 x3(3)=t(3)^3 x3 = t.^3 % One can also define simple constants two = 2. % and create new arrays % We now create an empty array with length equal to the % length of the array t % % For the moment we set this arry to zero. % % Notice the semi-colon here. If you add a semi-colon % it will not print out the array in the terminal. % This is useful to control what gets printed out two_thirds_x2 = zeros(1, length(t)) ; % We can now loop over the elements of the array t % length(t) for i = 1:length(t) two_thirds_x2(i) = two/3.*t(i)*t(i) ; end % This makes a plot which shows the actual points % The '-o' thing tells matlab to make a circle and a line % instead of just a line plot(t, x, '-o', t,x2, '-o',t,x3,'-o', t, two_thirds_x2, '-o')