Showing posts with label MATLAB. Show all posts
Showing posts with label MATLAB. Show all posts

Computing logarithms and roots in MATLAB

MATLAB: The Language of Technical Computing
MATLAB: The Language of Technical Computing

Welcome! 

In today's post, we will be finding logarithms, both natural logarithms and logarithms to an arbitrary base. Also we would be finding roots of numbers; square roots, cube roots and eventually nth roots, where n can be any integer.

Hence lets get started!




Plotting Trigonometric Functions in MATLAB

MATLAB: The Language of Technical Computing
MATLAB: The Language of Technical Computing

Welcome! Today's post is going to be exciting! We are going to finally use MATLAB to plot graphs!

Plotting of graphs is a fundamental step in mathematical analysis. Plotting a graph helps us visualize the function the graph is of. Hence we must learn how to do it at an early stage.

In this post, we are going to plot trigonometric functions like:

  • sine
  • cosine
  • tangent
  • secant
  • cosecant
  • cotangent
Hence let's get started!



Rounding off numbers using Round, Floor, Ceil and Fix functions in MATLAB

MATLAB: The Language of Technical Computing
MATLAB: The Language of Technical Computing

Welcome once again to a new session of MATLAB!

Today we are going to learn some number rounding functions. Since numbers are what we deal with at almost all times in MATLAB, it is important we learn some operations upon them. Today's session will enable you to round off numbers in MATLAB in different ways according to the different needs one may face while working with MATLAB.

The functions that we would be studying together would be:

  • Round Function
  • Floor Function
  • Ceil Function
  • Fix Function
Hence lets get started!



Finding Cumulative Sum of elements in a matrix with/without loops

MATLAB: The Language of Technical Computing
MATLAB: The Language of Technical Computing

Hello and Welcome to everyone once again. Today we would be learning how to generate cumulative sum of elements with and without using loops.

Chances are, if you didn't know what cumulative sum, loops and MATLAB are, you wouldn't be here in the first place, hence I wouldn't be taking the trouble of explaining cumulative sum or loops to you here.
But still, for an introduction

  • Cumulative Sum: Quoting from mathworld.wolfram.com, "a cumulative sum is a sequence of partial sums of a given sequence. For example, the cumulative sums of the sequence {a,b,c,...}, are (a), (a+b), (a+b+c), ...."
  • Loops: Loops are iterative statements. They are used when a fixed set of code needs to be executed again and again until a condition or a set of conditions are satisfied. They are of many types. In this article, we would be using the for loop.
  • Running Sum/Total: "A running total is the summation of a sequence of numbers which is updated each time a new number is added to the sequence, by adding the value of the new number to the previous running total. Another term for it is partial sum."
    It is just the same as Cumulative Sum, with the only difference that as compared to Cumulative Sum, where the total sum is calculated and displayed at once, in Running Sum, just as the definition says, sum is calculated in steps, every time a new new element is added to the sequence.
So lets get started!



Relational and Logical Operations in MATLAB

MATLAB: The Language of Technical Computing
MATLAB: The Language of Technical Computing

Welcome once again, to a new post on MATLAB!

Today as you might have read from the title, we are going to learn about Relational and Logical Operations that we can perform in MATLAB over arrays. Matrices can undergo relational and logical operations made up of GREATER/ LESSER THAN, (NOT) EQUAL TO, XOR, OR, AND, NOT operators in MATLAB. To learn that first, we must first learn about relational and logical operators in general.



Matrix Manipulations

MATLAB: The Language of Technical Computing
MATLAB: The Language of Technical Computing

Hey folks!
Today's lesson is gonna go big! While the previous lesson was just on making simple matrices and performing simple operation over them, today's lesson is gonna go advanced.
Once a matrix is made, it needs to be manipulated. Learn how to concatenate, index, randomize, sort, shift, reshape/resize, rotate, flip matrices with proper code snippets!



Creating a One and Two Dimensional Array/Matrix, Performing Arithmetic and Matrix operations


MATLAB: The Language of Technical Computing
MATLAB: The Language of Technical Computing



Hello Everyone!
Keeping in line with the previous group of rather diverse posts on MATLAB by one of our old partners, I'd like to continue them further with a more meaningful purpose.
As in the title hence, this would be the first stepping stone in learning MATLAB from the basics :)

If anyone of you would like to recap on their knowledge of MATLAB as a programming language, you are highly recommended to do so from here: An Introduction to MATLAB



Input/Output and File Statements in MATLAB

MATLAB

Input / Output is possible in various forms in MATLAB. There are numerous functions for sending data to the Standard output device (monitor) and for reading data from the standard input device (keyboard). 
In MATLAB, there are three methods to assign a value to a variable:
Using the assignment (=) statement
Read the data from a file stored in the system
Take the value as an input from the user

Input() Function
To accept data from the user, one can use input() function.

R = input(‘Enter the Radius of the circle: ‘);


When this statement is executed, the string ‘Enter the Radius of the circle: ‘ is printed on the screen and the system waits for the user to enter a value. The data accepted is stored in the variable R. Notice, the type of the variable R is not specified. R can take any value valid in MATLAB, it can be character, integer, floating point number, string, or even an empty value (if the user presses enter without entering any value).




Polynomials in MATLAB

MATLAB

Expressions that contain some number of variables and constants combined using operations such as addition, subtraction, multiplication and whole-number exponents are called POLYNOMIALS.
For example,
x2 + x + 1, x3 + x2 + x + 1
In MATLAB, polynomials can be represented as row vectors.
To declare a polynomial, say P(x) = 3x2 + 2x + 1, we use:
P = [3, 2, 1];
Or
P = [3, 2, 1];

Note that the coefficients of the variables are taken in the row vector and not the powers.

To declare a polynomial such as Q(x) = 13x3 + 4, we use
Q = [13, 0, 0, 4];
(Because 13 x3 + 4 can be written as 13x3 + 0x2 + 0x + 4.)




Vectors and Matrices in MATLAB

MATLAB

Matrices are the basic data elements in MATLAB. This helps to make the code shorter and easier to understand as it reduces the number of loops and repeating statements. Single variables are treated as a matrix of a single element, also called scalars.
To declare a vector in MATLAB,
A= [10 34 29]; %row vector (1, 3)                                    
Or
B = [114, 09, 46]; %row vector (1, 3)
Or
C= [101; 900; 20]; %column vector (3, 1)
Or
D= [1, 2, 3; 4, 5, 6; 7, 8, 9]; %3x3 Matrix




MATLAB: Operators, Constants, Variables and Expressions

MATLAB

An M-File contains a set of instructions written by the user using certain words and symbols according to the syntax rules specified in MATLAB. Any MATLAB command given in the command window can be used in an M-File. MATLAB contains various features and commands that make it a widely used and preferred language. This is because
Ø  It has incredibly powerful matrix and vector notations that make the coding compact.
Ø  It invisibly handles all memory allocations and supports file input/output, and string manipulation.
Ø  It contains a large set of functions that are available
Ø  It is equipped with powerful debugging features to locate and remove errors in M-Files




Some Basic Commands in MATLAB

      MATLAB
MATLAB, on opening, shows 2 screens, one of which is the command window and the other is the editor.
The command window is used to execute all the commands, while the editor is used to write your code.
When some basic commands are entered on the command window, a result corresponding to the command is displayed. The command window can perform basic operations like addition, subtraction, multiplication, division, logarithm etc.

">>" is known as the command prompt. It appears automatically on every new line in the command window.

For example, when we enter "2+3" in the command window, the value 5 will be assigned to a variable.

"Ans" is a default variable, and the value is assigned to this variable if no other is specified.

>>2+3
>>Ans =
>> 5





An Introduction To MATLAB

MATLAB

MATLAB (short for Matrix-Laboratory) is a software package designed specifically to perform scientific computations and visualizations. It was developed by MathWorks, first released in 1984. It is an Object-Oriented Language, and contains features such as classes, inheritance etc. Besides a large variety of default built-in functions, user-defined functions can also be included and used. MATLAB includes C and C++ Math libraries that support the development of stand-alone applications.

The basic data type in MATLAB is a matrix. Matrices are defined as arrays. A scalar in MATLAB is treated as a matrix of a single row and a single column. Single-row vectors and a single-column vectors are treated as horizontal and vertical vectors respectively. Variables and their types need not be declared, and can be directly initialized.




Powered by Blogger.