Thursday, April 16, 2020

MATLAB Basics Part 1


1.What is MATLAB ?

To solve Math & Engineering problems this is been created to using syntax like common science & engineering notation. 
--Cleve Moler [Professor] built this for their students

2.Which fields this is been used ?
  • Machine Learning
  • Robotics
  • Image Process
  • Biology
  • Engineers & Scientists also uses to develop
    • Automation
    • Medical Devices
    • Solar Systems
  • etc..
3.Is MATLAB is case sensitive ?
Yes,Variables & Function names are case sensitive.
Note : If observes,So even though generally quotes MATLAB is case sensitive programming language is not completely ,Like below where allows case insensitive 
  • Property Names
  • Scripts and Functions stored in a MATLAB file with a .m extension in Windows 
4.strcmp VS strcmpi ?
Both compares the string and "strcmpi" ignores the case while comparing.

5.MATLAB Variables ?
Ex: pi -->Default function

6.Write the expression for below example ?
>> a=3;
>> b=2;
>> c=-6;
>> x1=(-b+sqrt(b^2-4*a*c))/(2*a)

x1 =

    1.1196

>> x2 = (-b-sqrt(b^2-4*a*c))/(2*a)

x2 =

   -1.7863

7.Functions & Vector Array declaration ?


8.plot(x,y) function example?xlim,ylim functions use?How to increase the number of elements of X & Y axis ?
-->xlim,ylim sets the axis limits
-->As you observe the plot is getting more line elements based on available space,So it will auto selects the points linspace based on the available space. linspace also a function can set custom value




9.linspace function ? Uniformly Spaced Vectors example ?
Ex:Find temperature in Centigrade and Fahrenheit
10.How to add the comments ?
%{Comment Text}%

11.What is logical Vector ?How logical Vector access original Vector ?

Logical Vector is used to access only specific data based on certain conditions.
Script :
>> %{Original Vector}%
>> data = [0.01;0.02;0.01;0.27;0.39;0.01;0.65;0.50];
>> %{Logical Vector}%
>> ind = data > 0.1;
>> activity =data(ind);
>> %{Get the result from Original Vector with below condition}%
>> ind = data <=0.1;
>> %{Update the original vector data - values<=0.1 to 0 }%
>> data(ind) = 0;


12.Element Wise Vector Operations (*  /  ^) ?
Script :
>>v1 = [1,2,3,4];
>>v2 = [2,4,6,8];
>>M =  v1.*v2;
>>D =  v2./v1;
>>S =  v1.^v2;
>>A =  v1+ v2;
>>Sub =  v2- v1;

1.For all the operation Vector Dimensions should be same
2.Should precede by  '.' for these vector operations  like  v1.*v2, v1 ./v2 , v1 .^v2


13.Smooth plotting with more number of elements ?
Script :

>>%{f(x) = 3x^2 + 2x -6}%
>>x = -2:0.1:2;
>>y = 3*x.^2 + 2*x -6;
>>plot(x,y);




13.Vector Transpose ?
Rows to Columns & Columns to Rows
Script :
>>%{Vector Transpose}%
>>v = [2 -1 8.5 6 19];
>>c = v';

                     

No comments:

Post a Comment