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

Tuesday, April 27, 2021

Slope Line Equation for MATLAB Coding




THIS is a little problem which is mostly faced by Students in MATLAB coding that How to write code for this type of function (Piecewise).
when we write a code for the given code we will convert this one function into three parts.
1. Less then A (-0.5):

Just write the code as 
x = [-1:0.1:1];
for i = 1:1:21
    if (x(i)) < -0.5)
        y(i) = 0
end
end

2. Grater then B (0.5):

and write the code for x > 0.5
x = [-1:0.1:1];
for i = 1:1:21
    if (x(i)) > 0.5)
        y(i) = 1
end
end

3. Between A to B:

and here is little bit complex to find A to B Slop equation.

A point is at (x = -0.5 , y = 0) and B is at (x = 0.5 , y = 1)
then
Line equation format is y = m.x + c 
m is the slope of the line in equation which is = (Delta (y)/ Delta (x)) or (YB - YA) / (XB - XA)
which is in this case 
m = {1 - 0} / {0.5 - (-0.5)}
m = 1
and equation format is (YB - YA) = m (XB - XA) 
here A is start point which we know (-0.5, 0) and finding next point toward B so
YB replace as just Y and XB with X that is unknown point 
Y - 0 = 1 * (X + 0.5)
so the Y = X + 0.5 
if x = -0.5 then y = 0
as shown in above graph

m = 1;
x = [-1:0.1:1];
for i = 1:1:21
    else 
        y(i) = m * x(i) + 0.5;
end
end


IN THIS CASE: 
A point is at (x = -0.5 , y = -1) and B is at (x = 0.5 , y = 1)


m = {1 - (-1)} / {0.5 - (-0.5)}
m = 2
Y - (-1) = 2 * (X + 0.5)
Y+1 = 2 * X +1
so the Y = 2 * X 
if x = -0.5 then y = -1
as shown in above graph

m = 2;
x = [-1:0.1:1];
for i = 1:1:21
    else 
        y(i) = m * x(i);
end
end



 

Read More

Sunday, April 25, 2021

ANN Activation functions in MATLAB

 


Artificial Neural Network (ANN) is new and emerging research and problem optimization tool now a days, which's very helpful in research at MS and PhD level. MATLAB is best engineering simulation machine tool which replace your hardware for analysis.
So here I am sharing ANN basic concept with photo then I want to share activation function MATLAB code and results.
in above perception (at right hand) diagram f(x) is called activation function which is basically limiting function.
Activation function has some following types with diagrams and coding

1- Binary Uni-polar function:




1.2- Binary Bi-polar function:



2- Piece-wise Linear Uni-polar function: 



2.2- Piece-wise Linear Bi-polar function:



3- Sigmoid Uni-polar function:  




3.2- Sigmoid Bi-polar function:



Now Activation final code where these all functions are called to display all plots together

  1. clc;
  2. clear all;
  3. close all;
  4. a = 6; % alfa for sigmoid function
  5. v = [-1:0.1:1];
  6. [fv1] = Binary_uni(v)
  7. [fv2] = Binary_bi(v)
  8. [fv3] = Piecewise_uni(v)
  9. [fv4] = Piecewise_bi(v)
  10. [fv5] = Sigmoid_uni(v,a)
  11. [fv6] = Sigmoid_bi(v,a)

  12. subplot(2,3,1);
  13. plot(v,fv1)
  14. title('Binary activation Unipolar f')
  15. xlabel('v')
  16. ylabel('f(v)')

  17. subplot(2,3,4);
  18. plot(v,fv2)
  19. title('Binary activation Bipolar f')
  20. xlabel('v')
  21. ylabel('f(v)')

  22. subplot(2,3,2);
  23. plot(v,fv3)
  24. title('Piecewise activation Unipolar f')
  25. xlabel('v')
  26. ylabel('f(v)')

  27. subplot(2,3,5);
  28. plot(v,fv4)
  29. title('Piecewise activation Bipolar f')
  30. xlabel('v')
  31. ylabel('f(v)')

  32. subplot(2,3,3);
  33. plot(v,fv5)
  34. title('Sigmoid activation Unipolar f')
  35. xlabel('v')
  36. ylabel('f(v)')

  37. subplot(2,3,6);
  38. plot(v,fv6)
  39. title('Sigmoid activation Bipolar f')
  40. xlabel('v')
  41. ylabel('f(v)')
Result out:


If you like this post then like and comment

Read More

Important Artical

Popular Articals

Total Page views in This Month

© 2019-20 Electronics Garage. Designed by Uzma 0101 & Distributed by elektronicsgarage1.blogspot.com