diff --git a/.github/workflows/directory_workflow.yml b/.github/workflows/directory_workflow.yml
new file mode 100644
index 0000000..751ef7f
--- /dev/null
+++ b/.github/workflows/directory_workflow.yml
@@ -0,0 +1,58 @@
+name: directory_md
+on: [push, pull_request]
+
+jobs:
+ MainSequence:
+ name: DIRECTORY.md
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v1 # v2 is broken for git diff
+ - uses: actions/setup-python@v2
+ - name: Setup Git Specs
+ run: |
+ git config --global user.name github-actions
+ git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
+ git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
+ - name: Update DIRECTORY.md
+ shell: python
+ run: |
+ import os
+ from typing import Iterator
+ URL_BASE = "https://github.com/TheAlgorithms/MATLAB-Octave/blob/master"
+ g_output = []
+ def good_filepaths(top_dir: str = ".") -> Iterator[str]:
+ fs_exts = tuple(".m".split())
+ for dirpath, dirnames, filenames in os.walk(top_dir):
+ dirnames[:] = [d for d in dirnames if d[0] not in "._"]
+ for filename in filenames:
+ if os.path.splitext(filename)[1].lower() in fs_exts:
+ yield os.path.join(dirpath, filename).lstrip("./")
+ def md_prefix(i):
+ return f"{i * ' '}*" if i else "\n##"
+ def print_path(old_path: str, new_path: str) -> str:
+ global g_output
+ old_parts = old_path.split(os.sep)
+ for i, new_part in enumerate(new_path.split(os.sep)):
+ if i + 1 > len(old_parts) or old_parts[i] != new_part:
+ if new_part:
+ g_output.append(f"{md_prefix(i)} {new_part.replace('_', ' ').title()}")
+ return new_path
+ def build_directory_md(top_dir: str = ".") -> str:
+ global g_output
+ old_path = ""
+ for filepath in sorted(good_filepaths(), key=str.lower):
+ filepath, filename = os.path.split(filepath)
+ if filepath != old_path:
+ old_path = print_path(old_path, filepath)
+ indent = (filepath.count(os.sep) + 1) if filepath else 0
+ url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20")
+ filename = os.path.splitext(filename.replace("_", " ").title())[0]
+ g_output.append(f"{md_prefix(indent)} [{filename}]({url})")
+ return "# List of all files\n" + "\n".join(g_output)
+ with open("DIRECTORY.md", "w") as out_file:
+ out_file.write(build_directory_md(".") + "\n")
+ - name: Commit DIRECTORY.md
+ run: |
+ git commit -m "updating DIRECTORY.md" DIRECTORY.md || true
+ git diff DIRECTORY.md
+ git push --force origin HEAD:$GITHUB_REF || true
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..34a1cd7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+.history
+.dist
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..600f1c9
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,101 @@
+# Contributing guidelines
+
+## Before contributing
+
+Welcome to [TheAlgorithms/MATLAB-Octave](https://github.com/TheAlgorithms/MATLAB-Octave.git)! Before sending your pull requests, make sure that you **read the whole guidelines**. If you have any doubt on the contributing guide, please feel free to [state it clearly in an issue](https://github.com/TheAlgorithms/MATLAB-Octave/issues/new) or ask the community in [Gitter](https://gitter.im/TheAlgorithms).
+
+### Contributor
+
+We are very happy that you consider implementing algorithms and data structure for others! This repository is referenced and used by learners from all over the globe. Being one of our contributors, you agree and confirm that:
+
+- You did your work - no plagiarism allowed
+ - Any plagiarized work will not be merged.
+- Your work will be distributed under [MIT License](License) once your pull request is merged
+- You submitted work fulfils or mostly fulfils our styles and standards
+
+**New implementation** is welcome! For example, new solutions for a problem, different representations for a graph data structure or algorithm designs with different complexity.
+
+**Improving comments** and **writing proper tests** are also highly welcome.
+
+When contributing to this repository, please first discuss the change you wish to make via issue,
+email, or any other method with the owners of this repository before making a change.
+
+Please note we have a code of conduct, please follow it in all your interactions with the project.
+
+## Pull Request Process
+
+1. Ensure any install or build dependencies are removed before the end of the layer when doing a
+ build.
+2. Update the README.md with details of changes to the interface, this includes new environment
+ variables, exposed ports, useful file locations and container parameters.
+3. Increase the version numbers in any examples files and the README.md to the new version that this
+ Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
+4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
+ do not have permission to do that, you may request the second reviewer to merge it for you.
+
+## Code of Conduct
+
+### Our Pledge
+
+In the interest of fostering an open and welcoming environment, we as
+contributors and maintainers pledge to making participation in our project and
+our community a harassment-free experience for everyone, regardless of age, body
+size, disability, ethnicity, gender identity and expression, level of experience,
+nationality, personal appearance, race, religion, or sexual identity and
+orientation.
+
+### Our Standards
+
+Examples of behavior that contributes to creating a positive environment
+include:
+
+* Using welcoming and inclusive language
+* Being respectful of differing viewpoints and experiences
+* Gracefully accepting constructive criticism
+* Focusing on what is best for the community
+* Showing empathy towards other community members
+
+Examples of unacceptable behavior by participants include:
+
+* The use of sexualized language or imagery and unwelcome sexual attention or
+advances
+* Trolling, insulting/derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or electronic
+ address, without explicit permission
+* Other conduct which could reasonably be considered inappropriate in a
+ professional setting
+
+### Our Responsibilities
+
+Project maintainers are responsible for clarifying the standards of acceptable
+behavior and are expected to take appropriate and fair corrective action in
+response to any instances of unacceptable behavior.
+
+Project maintainers have the right and responsibility to remove, edit, or
+reject comments, commits, code, wiki edits, issues, and other contributions
+that are not aligned to this Code of Conduct, or to ban temporarily or
+permanently any contributor for other behaviors that they deem inappropriate,
+threatening, offensive, or harmful.
+
+### Scope
+
+This Code of Conduct applies both within project spaces and in public spaces
+when an individual is representing the project or its community. Examples of
+representing a project or community include using an official project e-mail
+address, posting via an official social media account, or acting as an appointed
+representative at an online or offline event. Representation of a project may be
+further defined and clarified by project maintainers.
+
+### Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be
+reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
+complaints will be reviewed and investigated and will result in a response that
+is deemed necessary and appropriate to the circumstances. The project team is
+obligated to maintain confidentiality with regard to the reporter of an incident.
+Further details of specific enforcement policies may be posted separately.
+
+Project maintainers who do not follow or enforce the Code of Conduct in good
+faith may face temporary or permanent repercussions as determined by other
+members of the project's leadership.
diff --git a/DIRECTORY.md b/DIRECTORY.md
new file mode 100644
index 0000000..ec6afbb
--- /dev/null
+++ b/DIRECTORY.md
@@ -0,0 +1,170 @@
+# List of all files
+
+## Algorithms
+ * Arithmetic Analysis
+ * [Bisection](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/arithmetic_analysis/bisection.m)
+ * [False Position](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/arithmetic_analysis/false_position.m)
+ * [Newton](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/arithmetic_analysis/newton.m)
+ * [Secant](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/arithmetic_analysis/secant.m)
+ * Crypto
+ * Sdbm-Hash
+ * [Sdbm](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/crypto/sdbm-hash/sdbm.m)
+ * Divisibility Of Integers
+ * [Multiple](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Divisibility_of_integers/multiple.m)
+ * Genetic-Algorithm
+ * Minimization Of Polynomial Function
+ * [Crossover](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Genetic-Algorithm/Minimization%20of%20polynomial%20function/Crossover.m)
+ * [Doublepointcrossover](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Genetic-Algorithm/Minimization%20of%20polynomial%20function/DoublePointCrossover.m)
+ * [Main](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Genetic-Algorithm/Minimization%20of%20polynomial%20function/main.m)
+ * [Minone](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Genetic-Algorithm/Minimization%20of%20polynomial%20function/minone.m)
+ * [Mutate](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Genetic-Algorithm/Minimization%20of%20polynomial%20function/Mutate.m)
+ * [Roulettewheelselection](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Genetic-Algorithm/Minimization%20of%20polynomial%20function/RouletteWheelSelection.m)
+ * [Run Ga](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Genetic-Algorithm/Minimization%20of%20polynomial%20function/Run_GA.m)
+ * [Singlepointcrossover](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Genetic-Algorithm/Minimization%20of%20polynomial%20function/SinglePointCrossover.m)
+ * [Sortpopulation](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Genetic-Algorithm/Minimization%20of%20polynomial%20function/SortPopulation.m)
+ * [Uniformcrossover](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Genetic-Algorithm/Minimization%20of%20polynomial%20function/UniformCrossover.m)
+ * Imageprocessing
+ * Lsb Based Image Steganography
+ * [Decrypt](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/ImageProcessing/LSB%20based%20Image%20Steganography/decrypt.m)
+ * [Steganography](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/ImageProcessing/LSB%20based%20Image%20Steganography/steganography.m)
+ * Nearest Neighbhor Interpolation
+ * [Zoomimg](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/ImageProcessing/Nearest%20Neighbhor%20Interpolation/zoomimg.m)
+ * Machine Learning
+ * Activation Functions
+ * [Elu](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Activation%20Functions/ELU.m)
+ * [Gelu](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Activation%20Functions/GELU.m)
+ * [Hyperbolic Tangent(Without Inbuilt)](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Activation%20Functions/Hyperbolic_tangent(without%20inbuilt).m)
+ * [Leakyrelu](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Activation%20Functions/LeakyReLU.m)
+ * [Linear(Without Inbuilt)](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Activation%20Functions/Linear(without%20inbuilt).m)
+ * [Parametric Relu](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Activation%20Functions/Parametric_ReLU.m)
+ * [Piecewise(Without Inbuilt)](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Activation%20Functions/Piecewise(without%20inbuilt).m)
+ * [Relu](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Activation%20Functions/ReLU.m)
+ * [Relu6](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Activation%20Functions/ReLU6.m)
+ * [Sigmoid(Without Inbuilt)](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Activation%20Functions/Sigmoid(without%20inbuilt).m)
+ * [Softmax](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Activation%20Functions/Softmax.m)
+ * [Threshold(Without Inbuilt)](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Activation%20Functions/Threshold(without%20inbuilt).m)
+ * Gradient-Descent
+ * [Gradientdescent](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Gradient-Descent/gradientdescent.m)
+ * [Rungradientdescent](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Gradient-Descent/runGradientDescent.m)
+ * Kmeans
+ * [Kmeans](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/kmeans/kmeans.m)
+ * Linear-Regression
+ * [Computecost](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Linear-Regression/computecost.m)
+ * [Gradientdescent](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Linear-Regression/gradientdescent.m)
+ * [Plotdata](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Linear-Regression/plotdata.m)
+ * [Runlinearregression](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Linear-Regression/runLinearRegression.m)
+ * Logistic-Regression
+ * [Costfunction](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Logistic-Regression/costfunction.m)
+ * [Plotdata](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Logistic-Regression/plotdata.m)
+ * [Plotdecisionboundary](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Logistic-Regression/plotdecisionboundary.m)
+ * [Predict](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Logistic-Regression/Predict.m)
+ * [Runlogisticregression](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Logistic-Regression/runLogisticRegression.m)
+ * [Sigmoid](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Logistic-Regression/Sigmoid.m)
+ * Nearest-Neighbor
+ * [Brightness](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Nearest-Neighbor/brightness.m)
+ * Maths
+ * [Euclidean Distance](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/euclidean_distance.m)
+ * [Fibonacci Sequence](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/fibonacci_sequence.m)
+ * [Find Factorial](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/find_factorial.m)
+ * [Highest Common Factor](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/highest_common_factor.m)
+ * [Is Armstrong](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/is_armstrong.m)
+ * [Jaccard Similarity](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/jaccard_similarity.m)
+ * [Lcm](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/lcm.m)
+ * [Linear Diophantine Eqn](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/linear_diophantine_eqn.m)
+ * [Prime Check](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/prime_check.m)
+ * [Prime Factorial](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/prime_factorial.m)
+ * [Shreedharacharyaformula](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/shreeDharacharyaFormula.m)
+ * [Sum Of Digits](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/sum_of_digits.m)
+ * [To Polar](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/to_polar.m)
+ * [Twos Complement Of Binary](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/twos_complement_of_binary.m)
+ * Other
+ * [Tic Tac Toe](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/other/tic_tac_toe.m)
+ * Particle Swarm Optimization
+ * Polynomial Minimization
+ * [Code](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Particle_Swarm_Optimization/Polynomial%20Minimization/code.m)
+ * [Parabola](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Particle_Swarm_Optimization/Polynomial%20Minimization/Parabola.m)
+ * Searching
+ * [Binary Search](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Searching/binary_search.m)
+ * [Jump Search](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Searching/jump_search.m)
+ * [Linear Search](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Searching/linear_search.m)
+ * [Random Search](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Searching/random_search.m)
+ * [Ternarysearch](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Searching/ternarySearch.m)
+ * Sieve Of Eratosthenes
+ * [Sieveer](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Sieve_of_Eratosthenes/sieveER.m)
+ * Sorting
+ * [Bubble Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/bubble_sort.m)
+ * [Cocktail Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/cocktail_sort.m)
+ * [Comb Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/comb_sort.m)
+ * [Counting Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/counting_sort.m)
+ * [Gnome Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/gnome_sort.m)
+ * [Heap Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/heap_sort.m)
+ * [Insertion Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/insertion_sort.m)
+ * [Merge Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/merge_sort.m)
+ * [Permutationsort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/permutationSort.m)
+ * [Quick Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/quick_sort.m)
+ * [Select Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/select_sort.m)
+ * [Shell Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/shell_sort.m)
+ * Strings
+ * [Ispalindrome](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Strings/isPalindrome.m)
+
+## Image-Processing
+ * Blob-Detection-Using-Matlab
+ * [Blobdetection](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/image-processing/Blob-detection-using-Matlab/blobDetection.m)
+ * [Blobusingvideo](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/image-processing/Blob-detection-using-Matlab/BlobUsingVideo.m)
+
+## Matlab For Beginners
+ * Part 1(Learn Basic Programing)
+ * [Add](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_1(learn_basic_programing)/add.m)
+ * [Array](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_1(learn_basic_programing)/array.m)
+ * [Comment](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_1(learn_basic_programing)/comment.m)
+ * [Continuation](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_1(learn_basic_programing)/continuation.m)
+ * [Equal](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_1(learn_basic_programing)/equal.m)
+ * [Equal Add](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_1(learn_basic_programing)/equal_add.m)
+ * [Formatted Output](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_1(learn_basic_programing)/formatted_output.m)
+ * [Individual El Add](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_1(learn_basic_programing)/individual_eL_add.m)
+ * [Intr Math Fun](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_1(learn_basic_programing)/intr_math_fun.m)
+ * [Make Graph](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_1(learn_basic_programing)/make_graph.m)
+ * [Math](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_1(learn_basic_programing)/math.m)
+ * [Nam Var](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_1(learn_basic_programing)/nam_var.m)
+ * [Print](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_1(learn_basic_programing)/print.m)
+ * Part 2(Basic Looping)
+ * [Program1](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_2(basic_looping)/program1.m)
+ * [Program2](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_2(basic_looping)/program2.m)
+ * [Program3](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_2(basic_looping)/program3.m)
+ * [Program4](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_2(basic_looping)/program4.m)
+ * [Program5](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_2(basic_looping)/program5.m)
+ * [Program6](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_2(basic_looping)/program6.m)
+ * [Program7](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_2(basic_looping)/program7.m)
+ * [Wh Loop](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_2(basic_looping)/wh_loop.m)
+ * Part 3(Basic Branching)
+ * [Program1](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_3(basic_branching)/program1.m)
+ * [Program2](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_3(basic_branching)/program2.m)
+ * [Program3](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_3(basic_branching)/program3.m)
+ * [Program4](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_3(basic_branching)/program4.m)
+ * Part 4(Array Nd Matrix)
+ * [Program1](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_4(array_nd_matrix)/program1.m)
+ * [Program10](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_4(array_nd_matrix)/program10.m)
+ * [Program11](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_4(array_nd_matrix)/program11.m)
+ * [Program12](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_4(array_nd_matrix)/program12.m)
+ * [Program2](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_4(array_nd_matrix)/program2.m)
+ * [Program3](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_4(array_nd_matrix)/program3.m)
+ * [Program4](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_4(array_nd_matrix)/program4.m)
+ * [Program5](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_4(array_nd_matrix)/program5.m)
+ * [Program6](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_4(array_nd_matrix)/program6.m)
+ * [Program7](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_4(array_nd_matrix)/program7.m)
+ * [Program8](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_4(array_nd_matrix)/program8.m)
+ * [Program9](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/matlab_for_beginners/part_4(array_nd_matrix)/program9.m)
+
+## Project-Euler
+ * Problem1
+ * [Multiple](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/project-euler/Problem1/multiple.m)
+ * [Solv](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/project-euler/Problem1/solv.m)
+ * Problem2
+ * [Fib](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/project-euler/Problem2/fib.m)
+ * [Solv](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/project-euler/Problem2/solv.m)
+ * Problem3
+ * [Pfz](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/project-euler/Problem3/pfz.m)
+ * [Solv](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/project-euler/Problem3/solv.m)
+ * Problem4
+ * [Ispalindromenumber](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/project-euler/Problem4/isPalindromeNumber.m)
+ * [Solv](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/project-euler/Problem4/solv.m)
diff --git a/LICENSE b/LICENSE
index 5bdfb42..3b79515 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2018 The Algorithms
+Copyright (c) 2020 The Algorithms
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 936ab72..fe6a63b 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,7 @@
-# MATLAB / Octave
+# MATLAB / Octave   
+
+  
+   
These repository is a collection of useful algorithms and data structures built in MATLAB/Octave. In addition you will find solutions from project euler problem sets. The code in this repository is cross-portabel for MATLAB and for Octave.
@@ -6,22 +9,82 @@ These repository is a collection of useful algorithms and data structures built
[Octave](https://www.gnu.org/software/octave/) is a free high-level interpreter language that is equivalent to the textuelle programming language MATLAB.
+## Clone git repository
+
+```sh
+ $ git clone "https://github.com/TheAlgorithms/MATLAB-Octave.git"
+```
+
+You can run and edit the algorithms or contribute to them using [Gitpod.io](https://www.gitpod.io/), a free online development environment, with a single click.
+
+[](http://gitpod.io/#https://github.com/TheAlgorithms/MATLAB-Octave)
+
+
+
### Overview about this repository
---
* project-euler
- * Problem 1
- * Problem 2
- * Problem 3
- * Problem 4
-
+ * [Problem 1](https://github.com/TheAlgorithms/MATLAB-Octave/tree/master/project-euler/Problem1)
+ * [Problem 2](https://github.com/TheAlgorithms/MATLAB-Octave/tree/master/project-euler/Problem2)
+ * [Problem 3](https://github.com/TheAlgorithms/MATLAB-Octave/tree/master/project-euler/Problem3)
+ * [Problem 4](https://github.com/TheAlgorithms/MATLAB-Octave/tree/master/project-euler/Problem4)
+
* algorithms
- * Sieve_of_Eratosthenes
+ * [Sieve_of_Eratosthenes](https://github.com/TheAlgorithms/MATLAB-Octave/tree/master/algorithms/Sieve_of_Eratosthenes)
+ * crypto
+ * [sdbm-hash](https://github.com/TheAlgorithms/MATLAB-Octave/tree/master/algorithms/crypto/sdbm-hash)
+ * searching
+ * [Binary Search](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Searching/binary_search.m)
+ * [Linear Search](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Searching/linear_search.m)
+ * Strings
+ * [Palindrome](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/Strings/isPalindrome.m)
+ * maths
+ * [to_polar](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/to_polar.m)
+ * [Fibonacci Sequence](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/fibonacci_sequence.m)
+ * [Factorial](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/find_factorial.m)
+ * [Highest Common Factor](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/highest_common_factor.m)
+ * [Jaccard Similarity](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/jaccard_similarity.m)
+ * [Prime Check](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/prime_check.m)
+ * [Prime Factorial](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/maths/prime_factorial.m)
+ * arithmetic_analysis
+ * [bisection](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/arithmetic_analysis/bisection.m)
+ * [newton](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/arithmetic_analysis/newton.m)
+ * [secant](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/arithmetic_analysis/secant.m)
+ * [false position](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/arithmetic_analysis/false_position.m)
+ * other
+ * [tic_tac_toe](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/other/tic_tac_toe.m)
+ * sorting
+ * [Bubble Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/bubble_sort.m)
+ * [Counting Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/counting_sort.m)
+ * [Insertion Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/insertion_sort.m)
+ * [Merge Sort](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/sorting/merge_sort.m)
+
+
+* machine-learning
+ * nearest neighbor
+ * [brightness (recognizes the brightness of a color)](https://github.com/TheAlgorithms/MATLAB-Octave/blob/master/algorithms/machine_learning/Nearest-Neighbor/brightness.m)
+ * [k-means clustering](https://github.com/TheAlgorithms/MATLAB-Octave/tree/master/algorithms/machine_learning/kmeans)
+ * [Gradient-Descent](https://github.com/TheAlgorithms/MATLAB-Octave/tree/master/algorithms/machine_learning/Gradient-Descent)
+ * [Logistic-Regression](https://github.com/TheAlgorithms/MATLAB-Octave/tree/master/algorithms/machine_learning/Logistic-Regression)
+ * [Linear-Regression](https://github.com/TheAlgorithms/MATLAB-Octave/tree/master/algorithms/machine_learning/Linear-Regression)
+ * [Activation Functions](https://github.com/TheAlgorithms/MATLAB-Octave/tree/master/algorithms/machine_learning/Activation%20Functions)
+
+
+
+* image-processing
+ * [Blob-detection](https://github.com/TheAlgorithms/MATLAB-Octave/tree/master/image-processing/Blob-detection-using-Matlab)
---
### Contributing
-You can like contribute to this repository. You simply orient on the directory structure.
\ No newline at end of file
+You can like contribute to this repository. You simply orient on the directory structure.
+Please read [CONTRIBUTING.md](CONTRIBUTING.md) for information on how to contribute.
+
+
+## License
+
+Licensed under the [MIT License](LICENSE)
diff --git a/algorithms/Divisibility_of_integers/multiple.m b/algorithms/Divisibility_of_integers/multiple.m
new file mode 100644
index 0000000..0b44077
--- /dev/null
+++ b/algorithms/Divisibility_of_integers/multiple.m
@@ -0,0 +1,17 @@
+function ans = multiple(x, m)
+
+ % multiple : checks whether the first number is
+ % divisible through the second number.
+ % INPUTS: The inputs must be integers.
+ % OUTPUT: Is a boolean value 0 or 1.
+ % THROWS: Throws a assertion error if the inputs invalid.
+
+ assert((x == round(x) && m == round(m)), "The inputs must be integers")
+
+ if m == 0
+ ans = (x == 0);
+ else
+ ans = (mod(x,m) == 0);
+ end
+
+endfunction
\ No newline at end of file
diff --git a/algorithms/Genetic-Algorithm/Minimization of polynomial function/Crossover.m b/algorithms/Genetic-Algorithm/Minimization of polynomial function/Crossover.m
new file mode 100644
index 0000000..165ef2d
--- /dev/null
+++ b/algorithms/Genetic-Algorithm/Minimization of polynomial function/Crossover.m
@@ -0,0 +1,11 @@
+function [y1, y2] = Crossover(x1,x2)
+ m=randi([1,3]);
+ switch m
+ case 1
+ [y1, y2] = SinglePointCrossover(x1,x2);
+ case 2
+ [y1, y2] = DoublePointCrossover(x1,x2);
+ otherwise
+ [y1, y2] = UniformCrossover(x1,x2);
+ end
+end
\ No newline at end of file
diff --git a/algorithms/Genetic-Algorithm/Minimization of polynomial function/DoublePointCrossover.m b/algorithms/Genetic-Algorithm/Minimization of polynomial function/DoublePointCrossover.m
new file mode 100644
index 0000000..eef07cd
--- /dev/null
+++ b/algorithms/Genetic-Algorithm/Minimization of polynomial function/DoublePointCrossover.m
@@ -0,0 +1,11 @@
+function [y1,y2] = DoublePointCrossover(x1,x2)
+ nVar = numel(x1);
+
+ q = randperm(nVar);
+ j1 = min(q(1),q(2));
+ j2 = max(q(1),q(2));
+
+ y1 = [x1(1:j1) x2(j1+1:j2) x1(j2+1:end)];
+ y2 = [x2(1:j1) x1(j1+1:j2) x2(j2+1:end)];
+
+end
\ No newline at end of file
diff --git a/algorithms/Genetic-Algorithm/Minimization of polynomial function/Mutate.m b/algorithms/Genetic-Algorithm/Minimization of polynomial function/Mutate.m
new file mode 100644
index 0000000..6a4f93d
--- /dev/null
+++ b/algorithms/Genetic-Algorithm/Minimization of polynomial function/Mutate.m
@@ -0,0 +1,5 @@
+function y = Mutate(x,mu)
+ flag = rand(size(x)) < mu;
+ y=x;
+ y(flag) = 1-x(flag);
+end
\ No newline at end of file
diff --git a/algorithms/Genetic-Algorithm/Minimization of polynomial function/RouletteWheelSelection.m b/algorithms/Genetic-Algorithm/Minimization of polynomial function/RouletteWheelSelection.m
new file mode 100644
index 0000000..4b08610
--- /dev/null
+++ b/algorithms/Genetic-Algorithm/Minimization of polynomial function/RouletteWheelSelection.m
@@ -0,0 +1,5 @@
+function i = RouletteWheelSelection(p)
+ r= rand*sum(p);
+ c=cumsum(p);
+ i=find(r<=c,1,'first');
+end
\ No newline at end of file
diff --git a/algorithms/Genetic-Algorithm/Minimization of polynomial function/Run_GA.m b/algorithms/Genetic-Algorithm/Minimization of polynomial function/Run_GA.m
new file mode 100644
index 0000000..cb762e5
--- /dev/null
+++ b/algorithms/Genetic-Algorithm/Minimization of polynomial function/Run_GA.m
@@ -0,0 +1,108 @@
+function out = RunGA(problem, params)
+
+ % Problem
+ CostFunction = problem.CostFunction;
+ nVar = problem.nVar;
+
+ % Params
+ MaxIt = params.MaxIt;
+ nPop = params.nPop;
+ beta = params.beta;
+ pC = params.pC;
+ nC = round(pC*nPop/2)*2;
+ mu = params.mu;
+
+ % Template for Empty Individuals
+ empty_individual.Position = [];
+ empty_individual.Cost = [];
+
+ % Best Solution Ever Found
+ bestsol.Cost = inf;
+
+ % Initialization
+ pop = repmat(empty_individual, nPop, 1);
+ for i = 1:nPop
+
+ % Generate Random Solution
+ pop(i).Position = randi([0, 1], 1, nVar);
+
+ % Evaluate Solution
+ pop(i).Cost = CostFunction(pop(i).Position);
+
+ % Compare Solution to Best Solution Ever Found
+ if pop(i).Cost < bestsol.Cost
+ bestsol = pop(i);
+ end
+
+ end
+
+ % Best Cost of Iterations
+ bestcost = nan(MaxIt, 1);
+
+ % Main Loop
+ for it = 1:MaxIt
+
+ % Selection Probabilities
+ c = [pop.Cost];
+ avgc = mean(c);
+ if avgc ~= 0
+ c = c/avgc;
+ end
+ probs = exp(-beta*c);
+
+ % Initialize Offsprings Population
+ popc = repmat(empty_individual, nC/2, 2);
+
+ % Crossover
+ for k = 1:nC/2
+
+ % Select Parents
+ p1 = pop(RouletteWheelSelection(probs));
+ p2 = pop(RouletteWheelSelection(probs));
+
+ % Perform Crossover
+ [popc(k, 1).Position, popc(k, 2).Position] = ...
+ Crossover(p1.Position, p2.Position);
+
+ end
+
+ % Convert popc to Single-Column Matrix
+ popc = popc(:);
+
+ % Mutation
+ for l = 1:nC
+
+ % Perform Mutation
+ popc(l).Position = Mutate(popc(l).Position, mu);
+
+ % Evaluation
+ popc(l).Cost = CostFunction(popc(l).Position);
+
+ % Compare Solution to Best Solution Ever Found
+ if popc(l).Cost < bestsol.Cost
+ bestsol = popc(l);
+ end
+
+ end
+
+ % Merge and Sort Populations
+ pop = SortPopulation([pop; popc]);
+
+ % Remove Extra Individuals
+ pop = pop(1:nPop);
+
+ % Update Best Cost of Iteration
+ bestcost(it) = bestsol.Cost;
+
+ % Display Itertion Information
+ disp(['Iteration ' num2str(it) ': Best Cost = ' num2str(bestcost(it))]);
+
+ end
+
+
+ % Results
+ out.pop = pop;
+ out.bestsol = bestsol;
+ out.bestcost = bestcost;
+
+end
\ No newline at end of file
diff --git a/algorithms/Genetic-Algorithm/Minimization of polynomial function/SinglePointCrossover.m b/algorithms/Genetic-Algorithm/Minimization of polynomial function/SinglePointCrossover.m
new file mode 100644
index 0000000..dba1505
--- /dev/null
+++ b/algorithms/Genetic-Algorithm/Minimization of polynomial function/SinglePointCrossover.m
@@ -0,0 +1,6 @@
+function [y1, y2] = SinglePointCrossover(x1,x2)
+ nVar = numel(x1);
+ j = randi([1, nVar-1]);
+ y1 = [x1(1:j) x2(j+1:end)];
+ y2 = [x2(1:j) x1(j+1:end)];
+end
\ No newline at end of file
diff --git a/algorithms/Genetic-Algorithm/Minimization of polynomial function/SortPopulation.m b/algorithms/Genetic-Algorithm/Minimization of polynomial function/SortPopulation.m
new file mode 100644
index 0000000..11fb8e3
--- /dev/null
+++ b/algorithms/Genetic-Algorithm/Minimization of polynomial function/SortPopulation.m
@@ -0,0 +1,4 @@
+function pop =SortPopulation(pop)
+ [~,so] = sort([pop.Cost]);
+ pop = pop(so);
+end
\ No newline at end of file
diff --git a/algorithms/Genetic-Algorithm/Minimization of polynomial function/UniformCrossover.m b/algorithms/Genetic-Algorithm/Minimization of polynomial function/UniformCrossover.m
new file mode 100644
index 0000000..d5b81a9
--- /dev/null
+++ b/algorithms/Genetic-Algorithm/Minimization of polynomial function/UniformCrossover.m
@@ -0,0 +1,7 @@
+function [y1 , y2] = UniformCrossover(x1,x2)
+ alpha =randi([0,1], size(x1));
+
+ y1 = alpha.*x1 + (1-alpha).*x2;
+ y2 = alpha.*x2 + (1-alpha).*x1;
+
+end
\ No newline at end of file
diff --git a/algorithms/Genetic-Algorithm/Minimization of polynomial function/main.m b/algorithms/Genetic-Algorithm/Minimization of polynomial function/main.m
new file mode 100644
index 0000000..9900821
--- /dev/null
+++ b/algorithms/Genetic-Algorithm/Minimization of polynomial function/main.m
@@ -0,0 +1,36 @@
+clc;
+clear;
+close all;
+
+%% Problem Definition
+
+problem.CostFunction = @(x) minone(x);
+problem.nVar = 100;
+
+
+%% GA Parameters
+
+params.MaxIt = 150;
+params.nPop = 100;
+
+params.beta = 1;
+params.pC = 1;
+params.mu = 0.02;
+
+%% Run GA
+
+out = Run_GA(problem, params);
+
+
+%% Results
+
+figure;
+plot(out.bestcost, 'LineWidth', 2);
+xlabel('Iterations');
+ylabel('Best Cost');
+grid on;
+
+
+
+
+
diff --git a/algorithms/Genetic-Algorithm/Minimization of polynomial function/minone.m b/algorithms/Genetic-Algorithm/Minimization of polynomial function/minone.m
new file mode 100644
index 0000000..941f623
--- /dev/null
+++ b/algorithms/Genetic-Algorithm/Minimization of polynomial function/minone.m
@@ -0,0 +1,3 @@
+function z= minone(x)
+ z = sum(x.^2);
+end
\ No newline at end of file
diff --git a/algorithms/Genetic-Algorithm/Minimization of polynomial function/readme.txt b/algorithms/Genetic-Algorithm/Minimization of polynomial function/readme.txt
new file mode 100644
index 0000000..2a0f848
--- /dev/null
+++ b/algorithms/Genetic-Algorithm/Minimization of polynomial function/readme.txt
@@ -0,0 +1 @@
+this is a minimization agorithm for a single variable function using genetic algorithm
diff --git a/algorithms/ImageProcessing/LSB based Image Steganography/decrypt.m b/algorithms/ImageProcessing/LSB based Image Steganography/decrypt.m
new file mode 100644
index 0000000..6c370bd
--- /dev/null
+++ b/algorithms/ImageProcessing/LSB based Image Steganography/decrypt.m
@@ -0,0 +1,32 @@
+clc;
+clear variables;
+len=str2double(input('Enter the length (character count) of the message you are looking for: ','s'));
+len = len*8;
+image_hide = imread('output.png');
+[rows,columns,channels] = size(image_hide);
+if channels > 1
+ image_hide = rgb2gray(image_hide);
+end
+count=1;
+bitseq='';
+for i=1:rows
+ for j=1:columns
+ %For all the characters in the message
+ if count<=len
+
+ %Retrieve the LSB of the intensity level of the pixel
+ LSB=mod(image_hide(i,j),2);
+ bitseq(count,1) = LSB;
+ count=count+1;
+ end
+ end
+end
+
+%Converting the bit sequence into the original message
+weights = [ 128 64 32 16 8 4 2 1 ];
+
+% elements are taken column wise from bitseq, each char has 8 bits so 8
+% rows
+message_matrix = reshape(bitseq,8,len/8);
+original_message = char(weights*message_matrix);
+disp(['The original message is: ',original_message]);
\ No newline at end of file
diff --git a/algorithms/ImageProcessing/LSB based Image Steganography/imgst1.png b/algorithms/ImageProcessing/LSB based Image Steganography/imgst1.png
new file mode 100644
index 0000000..20ddbae
Binary files /dev/null and b/algorithms/ImageProcessing/LSB based Image Steganography/imgst1.png differ
diff --git a/algorithms/ImageProcessing/LSB based Image Steganography/imgst2.png b/algorithms/ImageProcessing/LSB based Image Steganography/imgst2.png
new file mode 100644
index 0000000..369a68d
Binary files /dev/null and b/algorithms/ImageProcessing/LSB based Image Steganography/imgst2.png differ
diff --git a/algorithms/ImageProcessing/LSB based Image Steganography/input.png b/algorithms/ImageProcessing/LSB based Image Steganography/input.png
new file mode 100644
index 0000000..0fd69be
Binary files /dev/null and b/algorithms/ImageProcessing/LSB based Image Steganography/input.png differ
diff --git a/algorithms/ImageProcessing/LSB based Image Steganography/output.png b/algorithms/ImageProcessing/LSB based Image Steganography/output.png
new file mode 100644
index 0000000..33a64c2
Binary files /dev/null and b/algorithms/ImageProcessing/LSB based Image Steganography/output.png differ
diff --git a/algorithms/ImageProcessing/LSB based Image Steganography/readme.md b/algorithms/ImageProcessing/LSB based Image Steganography/readme.md
new file mode 100644
index 0000000..1fd53ce
--- /dev/null
+++ b/algorithms/ImageProcessing/LSB based Image Steganography/readme.md
@@ -0,0 +1,42 @@
+Image Steganography means hiding data in an image.
+
+This is possible because images are constituted of pixels. Each pixel can be represented as bits. The lower bits don't hold a lot of detail so they can be used to hide our data (by replacing them with corresponding bits of data).
+
+Since most of the information is contained in MSBs (due to their higher weights; bits are multiplied by 2^n for the nth bit and added during binary to decimal conversion), the resulting image is very similar to the human eye if we modify the LSBs only (Least Significant Bits).
+
+The encoding is done using the following steps:
+
+ 1. Convert the image to greyscale
+ 2. Resize the image if needed
+ 3. Convert the message to its binary format
+ 4. Initialize output image same as input image
+ 5. Traverse through each pixel of the image and do the following:
+ - Convert the pixel value to binary
+ - Get the next bit of the message to be embedded
+ - Create a variable temp
+ If the message bit and the LSB of the pixel are same, set temp = 0
+ If the message bit and the LSB of the pixel are different, set temp = 1
+ This setting of temp can be done by taking XOR of message bit and the LSB of the pixel
+ Update the pixel of output image to input image pixel value + temp
+
+ Keep updating the output image till all the bits in the message are embedded
+ Finally, write the input as well as the output image to local system.
+
+The decoding/decryption is done using the following steps:
+
+ 1. Get the output image which was encoded earlier.
+ 2. Input the length of the encoded message (character count).
+ 3. Retrieve the LSBs of each pixel
+ 4. Form a bit sequence from these LSBs
+ 5. Arrange the bit sequence into a matrix of 8 rows and total_message_bits/8 columns
+ (each column will represent a character of 8 bits, hence 8 rows)
+ - Convert the binary value to decimal
+ - Get the corresponding char from ascii
+
+
+ Finally, display the original message.
+
+References:
+[Concept, TDS article](https://towardsdatascience.com/steganography-hiding-an-image-inside-another-77ca66b2acb1),
+[GFG article on LSB based Image Steganography](https://www.geeksforgeeks.org/lsb-based-image-steganography-using-matlab/),
+[GFG article on text extraction from image](https://www.geeksforgeeks.org/text-extraction-from-image-using-lsb-based-steganography/)
diff --git a/algorithms/ImageProcessing/LSB based Image Steganography/steganography.m b/algorithms/ImageProcessing/LSB based Image Steganography/steganography.m
new file mode 100644
index 0000000..a4bf300
--- /dev/null
+++ b/algorithms/ImageProcessing/LSB based Image Steganography/steganography.m
@@ -0,0 +1,58 @@
+clc;
+clear variables;
+% Load the image and convert to grayscale if it is RGB
+I=imread('input.png');
+[rows, columns, numberOfColorChannels] = size(I);
+if numberOfColorChannels > 1
+ I = rgb2gray(I);
+end
+L=256;
+image_hide=I;
+
+message=input('Please enter the message you want to hide: ','s');
+% Each character occupies a byte, so total bits can be found by multiplying
+% string length by 8
+len=strlength(message)*8;
+ascii_values=uint8(message);
+ascii2binary=dec2bin(ascii_values,8);
+
+% Append all binary equivalents of ascii values into one string
+binary_sequence='';
+for i=1:strlength(message)
+ binary_sequence=append(binary_sequence,ascii2binary(i,:));
+end
+
+% To track how many bits of message have been hidden
+bitCount=1;
+
+for i=1:rows
+ for j=1:columns
+
+ if bitCount<=len
+ %Obtain the LSB of the grey level of the pixel
+ LSB=mod(I(i,j),2);
+
+ %Convert the bit from the message to numeric form
+ a=str2double(binary_sequence(bitCount));
+
+ %Perform XOR operation between the bit and the LSB
+ temp=double(xor(LSB,a));
+
+ %Change the bit of the image_hide accordingly
+ image_hide(i,j)=I(i,j)+temp;
+
+ bitCount=bitCount+1;
+ end
+ end
+end
+
+subplot(1,2,1);
+imshow(I);
+title('Input Image');
+
+subplot(1,2,2);
+imshow(image_hide);
+title('Image with Hidden Data');
+
+imwrite(image_hide,'output.png')
+
diff --git a/algorithms/ImageProcessing/Nearest Neighbhor Interpolation/lena_color.bmp b/algorithms/ImageProcessing/Nearest Neighbhor Interpolation/lena_color.bmp
new file mode 100644
index 0000000..901034d
Binary files /dev/null and b/algorithms/ImageProcessing/Nearest Neighbhor Interpolation/lena_color.bmp differ
diff --git a/algorithms/ImageProcessing/Nearest Neighbhor Interpolation/output.png b/algorithms/ImageProcessing/Nearest Neighbhor Interpolation/output.png
new file mode 100644
index 0000000..35dcc44
Binary files /dev/null and b/algorithms/ImageProcessing/Nearest Neighbhor Interpolation/output.png differ
diff --git a/algorithms/ImageProcessing/Nearest Neighbhor Interpolation/readme.md b/algorithms/ImageProcessing/Nearest Neighbhor Interpolation/readme.md
new file mode 100644
index 0000000..e2b4491
--- /dev/null
+++ b/algorithms/ImageProcessing/Nearest Neighbhor Interpolation/readme.md
@@ -0,0 +1,6 @@
+Used for resizing images. It assigns to each location the intensity of its nearest neighbor in original image. Refer [Gonzalez DIP Book](https://www.pearson.com/us/higher-education/program/Gonzalez-Digital-Image-Processing-4th-Edition/PGM241219.html) chapter 1.
+
+Basic algorithm is as follows:
+
+*For every pixel in resized image, we find the coordinate mapping in original image and copy over the pixel intensity from there to pixel in output image.*
+
diff --git a/algorithms/ImageProcessing/Nearest Neighbhor Interpolation/zoomimg.m b/algorithms/ImageProcessing/Nearest Neighbhor Interpolation/zoomimg.m
new file mode 100644
index 0000000..2166227
--- /dev/null
+++ b/algorithms/ImageProcessing/Nearest Neighbhor Interpolation/zoomimg.m
@@ -0,0 +1,27 @@
+clc;
+clear variables;
+image=imread('lena_color.bmp');
+[r,c,d] = size(image);
+zoom = 1.5;
+zr=zoom*r;
+zc=zoom*c;
+
+for i=1:1:zr
+ for j=1:1:zc
+ x=i/zoom;
+ mapi=round(x);
+ y=j/zoom;
+ mapj=round(y);
+ if mapi==0
+ mapi=1;
+ end
+ if mapj==0
+ mapj=1;
+ end
+ res(i,j)=image(mapi,mapj);
+ end
+end
+figure
+imshow(image);
+figure
+imshow(res);
\ No newline at end of file
diff --git a/algorithms/Particle_Swarm_Optimization/Polynomial Minimization/Parabola.m b/algorithms/Particle_Swarm_Optimization/Polynomial Minimization/Parabola.m
new file mode 100644
index 0000000..6415f97
--- /dev/null
+++ b/algorithms/Particle_Swarm_Optimization/Polynomial Minimization/Parabola.m
@@ -0,0 +1,3 @@
+function z = Parabola(x)
+ z = sum(x.^2);
+end
\ No newline at end of file
diff --git a/algorithms/Particle_Swarm_Optimization/Polynomial Minimization/code.m b/algorithms/Particle_Swarm_Optimization/Polynomial Minimization/code.m
new file mode 100644
index 0000000..a34ac18
--- /dev/null
+++ b/algorithms/Particle_Swarm_Optimization/Polynomial Minimization/code.m
@@ -0,0 +1,130 @@
+clc;
+clear;
+close all;
+
+%% Problem Definition
+
+
+CostFunction=@(x) Parabola(x); % Cost Function
+
+nVar = 5; % 5 dimensional-Number of unknown (Decision Variables)
+
+VarSize = [1 nVar]; % Matrix size of Decision Variables
+
+VarMin = -10; % Lower bound of Decision Variables
+VarMax = 10; % Upper bound of Decision Variables
+
+
+%% Parameters of PSO
+
+MaxIt = 1000; % Maximum Numbers of Iterations
+
+nPop = 50; % Population size (Swarm Size)
+
+w = 1; % Inertia Coefficient
+wdamp=0.99; % Damping Ratio of intertia weight
+c1 = 2; % Personal Acceleration Coefficient
+c2 = 2; % Social Acceleration Coefficient
+
+
+
+%% Initialization
+
+% The Particle Template
+empty_particle.Position = []; % position of particle
+empty_particle.Velocity = []; % velocity of particle
+empty_particle.Cost = []; % own measurement of particle(cost value)
+empty_particle.Best.Position = []; % personal best with its position
+empty_particle.Best.Cost = []; % personal best with its cost value
+
+
+particle = repmat(empty_particle, nPop,1); % Create random Population Array
+
+%Initialization Global best
+GlobalBest.Cost=inf; % for minization fun. its infinity before 1st iteration
+
+% Initialize Population Members
+
+ for i=1:nPop
+
+ % Generate Random Solutions
+ particle(i).Position=unifrnd(VarMin,VarMax,VarSize);
+
+ % Initialize Velocity
+ particle(i).Velocity=zeros(VarSize); %matrix with all o of varsize
+
+ % Evaluation at above particle i position
+ particle(i).Cost=CostFunction(particle(i).Position);
+
+ % Update Personal Best value
+ particle(i).Best.Position=particle(i).Position;
+ particle(i).Best.Cost=particle(i).Cost;
+
+ % Update Global Best
+ if particle(i).Best.Cost A(floor(mid))
+ L_SearchRange = floor(mid)+1;
+ else
+ R_SearchRange = floor(mid)-1;
+ if R_SearchRange == 0 %to stop searching when t is less than the minimum value of array
+ counter = counter +1;
+ end
+ end
+ counter = counter+1;
+end
+end
+if counter > floor(log2(array_length))+1
+ disp('target is not found in aray')
+end
+end
diff --git a/algorithms/Searching/jump_search.m b/algorithms/Searching/jump_search.m
new file mode 100644
index 0000000..673df40
--- /dev/null
+++ b/algorithms/Searching/jump_search.m
@@ -0,0 +1,56 @@
+function found_at = jump_search(input_array, search_key)
+ % Contributed by - Harshit Pant, harshitpant83@gmail.com
+ % Reference - https://en.wikipedia.org/wiki/Jump_search
+
+ % input_array - Holds the array in which the 'search_key' is to be searched.
+ % It should be sorted in ascending order.
+ % It can contain -ve numbers as well as non-integers.
+ % search_key - The value to be searched in the 'input_array'.
+ % found_at - The index at which 'search_key' is found in 'input_array'.
+ % -1 is returned if 'search_key' is not found in 'input_array'.
+
+ array_length = length(input_array);
+ found_at = -1;
+
+ % Finding the optimum block_size to be jumped.
+ block_size = sqrt(array_length);
+ block_size = round(block_size);
+
+ % low and high denote the lower
+ % and upper bound of a certain block.
+ low = 1;
+ high = 1 + block_size;
+
+ % Finding the block where the 'search_key' is present
+ % if low >= array_length, the 'search_key' is not found
+ % in the 'input_array', thus, -1 is returned.
+ while input_array(min(high, array_length)) < search_key
+ low = high;
+ high = high + block_size;
+ if low >= array_length
+ return;
+ endif;
+ endwhile;
+
+ % Now that the required block is found,
+ % running a linear search within the block
+ % to find the 'search_key'
+ while input_array(low) < search_key
+ low = low + 1;
+ if low > min(high, array_length)
+ return;
+ endif;
+ endwhile;
+
+ % Checks if the 'search_key' was found within
+ % the block. If found, the index is returned.
+ % If not -1 is returned.
+ if input_array(low) == search_key
+ found_at = low;
+ endif;
+
+endfunction;
+
+% TEST:
+% jump_search([-11.1, -3.3, -1.3, 0.1, 1.5, 3.5, 3.9,...
+% 5.5, 7.5, 9.6, 13.7, 21.3, 35.9], 7.5) == 9
diff --git a/algorithms/Searching/linear_search.m b/algorithms/Searching/linear_search.m
new file mode 100644
index 0000000..337e425
--- /dev/null
+++ b/algorithms/Searching/linear_search.m
@@ -0,0 +1,25 @@
+function p = linear_search(A,t)
+%% linear Search
+% This function linear searches target value (t) in array A.
+% For this, It sequentially checks each entry of the array until a match is found
+% or or the whole list has been searched.
+% If it can find the target returns 1 otherwise 0.
+
+array_length = length(A);
+i = 1;
+searchTermination = 0;
+
+while searchTermination == 0 && i < array_length+1
+ if A(i) == t
+ p = 1;
+ searchTermination = 1;
+ disp('the target is found in the array')
+ else
+ i = i+1;
+ end
+end
+if i == array_length+1
+ p = 0;
+ disp('the target is not found in the array')
+end
+end
diff --git a/algorithms/Searching/random_search.m b/algorithms/Searching/random_search.m
new file mode 100644
index 0000000..e4f2e53
--- /dev/null
+++ b/algorithms/Searching/random_search.m
@@ -0,0 +1,24 @@
+%% Random Search Algorithm (Pure Random Search Algorithm)
+
+% This code finds the minimum of f(x) = x(1)^2 + x(2)^2
+% in which -5 < x(i) < 5
+% This function is a convex and the minimum is at (0,0)
+% The RSA is the simplest algorithm to solve optimization problem
+% it is not efficient and it sometimes cannot solve the problem
+
+clc
+close all
+clear all
+dim=2;
+popsize=100;
+ftarget=0.01;
+numIter=100;
+ObjFun=@(x) sum(x.^2);
+for i=1:numIter
+ candidate=10*rand(dim,popsize)-5;
+ best=min(feval(ObjFun,candidate));
+ if best <= ftarget
+ break;
+ end
+end
+disp(best);
diff --git a/algorithms/Searching/ternarySearch.m b/algorithms/Searching/ternarySearch.m
new file mode 100644
index 0000000..21b4b47
--- /dev/null
+++ b/algorithms/Searching/ternarySearch.m
@@ -0,0 +1,33 @@
+%% Ternary Search
+% This function ternary searches target value in sorted (in increasing order) array.
+%%First, we compare the key with the element at mid1. If found equal, we return mid1.
+%If not, then we compare the key with the element at mid2. If found equal, we return mid2.
+%If not, then we check whether the key is less than the element at mid1. If yes, then recur to the first part.
+%If not, then we check whether the key is greater than the element at mid2. If yes, then recur to the third part.
+%If not, then we recur to the second (middle) part.
+
+
+% function for ternary search
+function returnindex = ternarySearch( array, target, firstIndex , lastIndex)
+if(lastIndex >= firstIndex)
+ mid1 = firstIndex + fix((lastIndex - firstIndex) / 3); %calculating mid1
+ mid2 = lastIndex - fix((lastIndex - firstIndex)/ 3); %calculating mid2
+
+ if(array(mid1)== target)
+ returnindex = mid1;
+
+ elseif(array(mid2) == target)
+ returnindex = mid2;
+ elseif(target < array(mid1))
+
+ returnindex = ternarySearch(array,target,firstIndex, mid1-1);
+ elseif(target > array(mid2))
+ returnindex = ternarySearch(array,target,mid2 + 1, lastIndex);
+ else
+
+ returnindex = ternarySearch(array,target,mid1+1,mid2-1);
+ end
+else
+ returnindex = -1;
+end
+end
diff --git a/algorithms/Sieve_of_Eratosthenes/sieveER.m b/algorithms/Sieve_of_Eratosthenes/sieveER.m
index f3e17fb..29a4a4b 100644
--- a/algorithms/Sieve_of_Eratosthenes/sieveER.m
+++ b/algorithms/Sieve_of_Eratosthenes/sieveER.m
@@ -3,23 +3,18 @@
function y = sieveER(N)
% precondition
assert(N >= 2,"N must be >= 2")
- tmp = 2:1:N; % all numbers from 2 up to N
- y = []; % the answer
+ tmp = [false,true(1,N-1)]; % indexed by all numbers from 2 up to N
- % labels all composite number with 0
- for i = 1 : 1 : length(tmp)
- for j = i+1 : 1 : length(tmp)
- if (mod(tmp(j),tmp(i)) == 0)
- tmp(j) = 0;
- endif
- endfor
+ % labels all composite number with false
+ for i = 2 : 1 : sqrt(N)
+ if (tmp(i))
+ for j = i^2 : i : N
+ tmp(j) = false;
+ endfor
+ endif
endfor
% fills up all prime numbers in vector y
- for i = 1 : 1 : length(tmp)
- if (tmp(i) ~= 0)
- y = [y tmp(i)];
- endif
- endfor
+ y = find(tmp);
endfunction
diff --git a/algorithms/Strings/isPalindrome.m b/algorithms/Strings/isPalindrome.m
new file mode 100644
index 0000000..d3967fb
--- /dev/null
+++ b/algorithms/Strings/isPalindrome.m
@@ -0,0 +1,17 @@
+function y = isPalindrome(inputWord)
+ % Return 1 if input string is a palindrome; 0 otherwise.
+
+ % Gets the length of the input word.
+ inputLength = length(inputWord);
+
+ % Number of pairs to compare.
+ lastIndex = floor( inputLength / 2);
+ y=1;
+ % for every pair of letters in the word check if they match
+ for i = 1 : lastIndex
+ if inputWord(i) ~= inputWord(end + (1 - i))
+ y = 0;
+ end
+ end
+
+end
diff --git a/algorithms/arithmetic_analysis/bisection.m b/algorithms/arithmetic_analysis/bisection.m
new file mode 100644
index 0000000..51a8ef2
--- /dev/null
+++ b/algorithms/arithmetic_analysis/bisection.m
@@ -0,0 +1,44 @@
+%The bisection method for finding the root of a function.
+%f(a) is < 0 and f(b) > 0. By the intermediate value theorem,
+%there exists a number c in between a and b such that f(c) = 0.
+%In other words, there is always a root in between f(a) and f(b).
+%The bisection method takes the midpoint between a and b and evaluates
+%the value of the function at the midpoint. If it is less than 0,
+%a is assigned the midpoint. If it is greater than 0, b is assigned the
+%midpoint. With each iteration, the interval the root lies in is halved,
+%guaranteeing that the algorithm will converge towards the root.
+
+%INPUTS:
+%Function handle f
+%endpoint a
+%endpoint b
+%maximum tolerated error
+
+%OUTPUTS:
+%An approximated value for the root of f within the defined interval.
+
+%Written by MatteoRaso
+
+function y = bisection(f, a, b, error)
+ %Making sure that the user didn't input invalid endpoints.
+ if ~(f(a) < 0)
+ disp("f(a) must be less than 0")
+ elseif ~(f(b) > 0)
+ disp("f(b) must be greater than 0")
+ else
+ c = 1e9;
+ %Loops until we reach an acceptable approximation.
+ while abs(f(c)) > error
+ c = (a + b) / 2;
+ if f(c) < 0
+ a = c;
+ else
+ b = c;
+ endif
+ disp(f(c))
+ endwhile
+ x = ["The root is approximately located at ", num2str(c)];
+ disp(x)
+ y = c;
+ endif
+endfunction
diff --git a/algorithms/arithmetic_analysis/false_position.m b/algorithms/arithmetic_analysis/false_position.m
new file mode 100644
index 0000000..2813c65
--- /dev/null
+++ b/algorithms/arithmetic_analysis/false_position.m
@@ -0,0 +1,41 @@
+%The basic idea behind the false position method is similar to the bisection
+%method in that we continuously shrink the interval the root lies on until
+%the algorithm converges on the root. Unlike the bisection method, the false
+%position method does not halve the interval with each iteration. Instead of
+%using the midpoint of a and b to create the new interval, the false position
+%method uses the x-intercept of the line connecting f(a) and f(b). This
+%algorithm converges faster than the bisection method.
+
+%INPUTS:
+%Function handle f
+%endpoint a
+%endpoint b
+%maximum tolerated error
+
+%OUTPUTS:
+%An approximated value for the root of f within the defined interval.
+
+%Written by MatteoRaso
+
+function y = false_position(f, a, b, error)
+ if ~(f(a) < 0)
+ disp("f(a) must be less than 0")
+ elseif ~(f(b) > 0)
+ disp("f(b) must be greater than zero")
+ else
+ c = 100000;
+ while abs(f(c)) > error
+ %Formula for the x-intercept
+ c = -f(b) * (b - a) / (f(b) - f(a)) + b;
+ if f(c) < 0
+ a = c;
+ else
+ b = c;
+ endif
+ disp(f(c))
+ endwhile
+ x = ["The root is approximately located at ", num2str(c)];
+ disp(x)
+ y = c;
+ endif
+endfunction
diff --git a/algorithms/arithmetic_analysis/newton.m b/algorithms/arithmetic_analysis/newton.m
new file mode 100644
index 0000000..6108072
--- /dev/null
+++ b/algorithms/arithmetic_analysis/newton.m
@@ -0,0 +1,25 @@
+%Newton's method is one of the fastest algorithms to converge on a root.
+%It does not require you to provide any endpoints, but it does require for
+%you to provide the derivative of the function. It is faster than the secant
+%method, but is also not guaranteed to converge.
+
+%INPUTS:
+%function handle f
+%function handle df for the derivative of f
+%initial x-value
+%maximum tolerated error
+
+%OUTPUTS:
+%An approximated value for the root of f.
+
+%Written by MatteoRaso
+
+function y = newton(f, df, x, error)
+ while abs(f(x)) > error
+ x = x - f(x) / df(x);
+ disp(f(x))
+ endwhile
+ A = ["The root is approximately located at ", num2str(x)];
+ disp(A)
+ y = x;
+endfunction
diff --git a/algorithms/arithmetic_analysis/secant.m b/algorithms/arithmetic_analysis/secant.m
new file mode 100644
index 0000000..8ddfb64
--- /dev/null
+++ b/algorithms/arithmetic_analysis/secant.m
@@ -0,0 +1,28 @@
+%Extremely similar to the false position method. The main difference is
+%that the secant method does not actually have a defined interval where
+%the root lies on. It converges faster than the false position method,
+%but it is not always guaranteed to converge.
+
+%INPUTS:
+%Function handle f
+%x1 = a
+%x2 = b
+%maximum tolerated error
+
+%OUTPUTS:
+%An approximated value for the root of f.
+
+%Written by MatteoRaso
+
+function y = secant(f, a, b, error)
+ x = [a, b];
+ n = 2;
+ while abs(f(x(n))) > error
+ x(n + 1) = -f(x(n)) * (x(n) - x(n - 1)) / (f(x(n)) - f(x(n - 1))) + x(n);
+ n = n + 1;
+ disp(f(x(n)))
+ endwhile
+ A = ["The root is approximately ", num2str(x(n))];
+ disp(A)
+ y = x(n);
+endfunction
diff --git a/algorithms/crypto/sdbm-hash/sdbm.m b/algorithms/crypto/sdbm-hash/sdbm.m
new file mode 100644
index 0000000..196cb03
--- /dev/null
+++ b/algorithms/crypto/sdbm-hash/sdbm.m
@@ -0,0 +1,10 @@
+% sdbm: implements the sdbm-hash algorithm
+% argument: str of type string
+% returns: double
+function ans = sdbm(str)
+ hash = 0;
+ for ch = str
+ hash = double(ch) + bitshift(hash,6) + bitshift(hash,16) - hash;
+ endfor
+ ans = hash;
+endfunction
\ No newline at end of file
diff --git a/algorithms/machine_learning/Activation Functions/ELU.m b/algorithms/machine_learning/Activation Functions/ELU.m
new file mode 100644
index 0000000..007cc00
--- /dev/null
+++ b/algorithms/machine_learning/Activation Functions/ELU.m
@@ -0,0 +1,8 @@
+%ELU function
+x = -10:0.01:10;
+a = input('Enter the parameter');
+y = @(x) (a*(exp(x)-1)).*((x < 0)) + (x).*((x > 0)) ;
+fplot(y);
+xlabel('x');
+ylabel('y');
+grid on
diff --git a/algorithms/machine_learning/Activation Functions/GELU.m b/algorithms/machine_learning/Activation Functions/GELU.m
new file mode 100644
index 0000000..32cbca6
--- /dev/null
+++ b/algorithms/machine_learning/Activation Functions/GELU.m
@@ -0,0 +1,7 @@
+%GELU function
+x = -10:0.01:10;
+y = (1/2*x).*(1+tanh(sqrt(2/pi)*(x+0.044715*power(x,3))));
+plot(x,y);
+xlabel('x');
+ylabel('y');
+grid on
diff --git a/algorithms/machine_learning/Activation Functions/Hyperbolic_tangent(without inbuilt).m b/algorithms/machine_learning/Activation Functions/Hyperbolic_tangent(without inbuilt).m
new file mode 100644
index 0000000..eb14706
--- /dev/null
+++ b/algorithms/machine_learning/Activation Functions/Hyperbolic_tangent(without inbuilt).m
@@ -0,0 +1,8 @@
+%hyperbolic tangent function without using inbuilt func
+x = -10:0.01:10;
+a = input('Enter the slope parameter')
+y = (exp(a.*(x))-exp(-a.*(x)))./(exp(a.*(x))+exp(-a.*(x)));
+plot(x,y);
+xlabel('x')
+ylabel('y')
+grid on
diff --git a/algorithms/machine_learning/Activation Functions/LeakyReLU.m b/algorithms/machine_learning/Activation Functions/LeakyReLU.m
new file mode 100644
index 0000000..a1acd50
--- /dev/null
+++ b/algorithms/machine_learning/Activation Functions/LeakyReLU.m
@@ -0,0 +1,7 @@
+%Leaky ReLU function
+x = -10:0.01:10;
+y = @(x) (x).*((x > 0)) + (0.01 * x).*((x < 0)) ;
+fplot(y);
+xlabel('x');
+ylabel('y');
+grid on
diff --git a/algorithms/machine_learning/Activation Functions/Linear(without inbuilt).m b/algorithms/machine_learning/Activation Functions/Linear(without inbuilt).m
new file mode 100644
index 0000000..c4bbbc2
--- /dev/null
+++ b/algorithms/machine_learning/Activation Functions/Linear(without inbuilt).m
@@ -0,0 +1,9 @@
+%linear function without using inbuilt func
+x = -10:0.01:10;
+m = input('Enter the slope');
+y = zeros(size(x));
+y = m*x;
+plot(x,y);
+xlabel('x');
+ylabel('y');
+grid on
diff --git a/algorithms/machine_learning/Activation Functions/Parametric_ReLU.m b/algorithms/machine_learning/Activation Functions/Parametric_ReLU.m
new file mode 100644
index 0000000..af8f51f
--- /dev/null
+++ b/algorithms/machine_learning/Activation Functions/Parametric_ReLU.m
@@ -0,0 +1,8 @@
+%Parametric ReLU function
+x = -10:0.01:10;
+a = input('Enter the value of the slope')
+y = @(x) (x).*((x > 0)) + (a*x).*((x < 0)) ;
+fplot(y);
+xlabel('x');
+ylabel('y');
+grid on
diff --git a/algorithms/machine_learning/Activation Functions/Piecewise(without inbuilt).m b/algorithms/machine_learning/Activation Functions/Piecewise(without inbuilt).m
new file mode 100644
index 0000000..1fd370a
--- /dev/null
+++ b/algorithms/machine_learning/Activation Functions/Piecewise(without inbuilt).m
@@ -0,0 +1,7 @@
+%piecewise function without using inbuilt func
+y = @(x) (1).*((x >= 1/2)) + (x).*((-1/2=6) = 6;
+plot(x,y);
+xlabel('x');
+ylabel('y');
+grid on
diff --git a/algorithms/machine_learning/Activation Functions/Sigmoid(without inbuilt).m b/algorithms/machine_learning/Activation Functions/Sigmoid(without inbuilt).m
new file mode 100644
index 0000000..d536334
--- /dev/null
+++ b/algorithms/machine_learning/Activation Functions/Sigmoid(without inbuilt).m
@@ -0,0 +1,8 @@
+%sigmoid function without using inbuilt func
+x = -10:0.01:10;
+a = input('Enter the slope parameter')
+y = 1./(1 + exp(-a.*(x)));
+plot(x,y);
+xlabel('x')
+ylabel('y')
+grid on
diff --git a/algorithms/machine_learning/Activation Functions/Softmax.m b/algorithms/machine_learning/Activation Functions/Softmax.m
new file mode 100644
index 0000000..83c3a72
--- /dev/null
+++ b/algorithms/machine_learning/Activation Functions/Softmax.m
@@ -0,0 +1,9 @@
+%Softmax function
+syms k
+x = -10:1:10;
+denom = symsum(exp(k),k,-10,10);
+y= @(x) (exp(x)/denom);
+fplot(y);
+xlabel('x');
+ylabel('y');
+grid on
diff --git a/algorithms/machine_learning/Activation Functions/Threshold(without inbuilt).m b/algorithms/machine_learning/Activation Functions/Threshold(without inbuilt).m
new file mode 100644
index 0000000..2c4703d
--- /dev/null
+++ b/algorithms/machine_learning/Activation Functions/Threshold(without inbuilt).m
@@ -0,0 +1,8 @@
+%Threshold function without using inbuilt func
+x = -10:0.01:10;
+y = zeros(size(x));
+y(x>=0)=1;
+plot(x,y);
+xlabel('x');
+ylabel('y');
+grid on
diff --git a/algorithms/machine_learning/Gradient-Descent/data_.txt b/algorithms/machine_learning/Gradient-Descent/data_.txt
new file mode 100644
index 0000000..9903f8e
--- /dev/null
+++ b/algorithms/machine_learning/Gradient-Descent/data_.txt
@@ -0,0 +1,97 @@
+6.1101,17.592
+5.5277,9.1302
+8.5186,13.662
+7.0032,11.854
+5.8598,6.8233
+8.3829,11.886
+7.4764,4.3483
+8.5781,12
+6.4862,6.5987
+5.0546,3.8166
+5.7107,3.2522
+14.164,15.505
+5.734,3.1551
+8.4084,7.2258
+5.6407,0.71618
+5.3794,3.5129
+6.3654,5.3048
+5.1301,0.56077
+6.4296,3.6518
+7.0708,5.3893
+6.1891,3.1386
+20.27,21.767
+5.4901,4.263
+6.3261,5.1875
+5.5649,3.0825
+18.945,22.638
+12.828,13.501
+10.957,7.0467
+13.176,14.692
+22.203,24.147
+5.2524,-1.22
+6.5894,5.9966
+9.2482,12.134
+5.8918,1.8495
+8.2111,6.5426
+7.9334,4.5623
+8.0959,4.1164
+5.6063,3.3928
+12.836,10.117
+6.3534,5.4974
+5.4069,0.55657
+6.8825,3.9115
+11.708,5.3854
+5.7737,2.4406
+7.8247,6.7318
+7.0931,1.0463
+5.0702,5.1337
+5.8014,1.844
+11.7,8.0043
+5.5416,1.0179
+7.5402,6.7504
+5.3077,1.8396
+7.4239,4.2885
+7.6031,4.9981
+6.3328,1.4233
+6.3589,-1.4211
+6.2742,2.4756
+5.6397,4.6042
+9.3102,3.9624
+9.4536,5.4141
+8.8254,5.1694
+5.1793,-0.74279
+21.279,17.929
+14.908,12.054
+18.959,17.054
+7.2182,4.8852
+8.2951,5.7442
+10.236,7.7754
+5.4994,1.0173
+20.341,20.992
+10.136,6.6799
+7.3345,4.0259
+6.0062,1.2784
+7.2259,3.3411
+5.0269,-2.6807
+6.5479,0.29678
+7.5386,3.8845
+5.0365,5.7014
+10.274,6.7526
+5.1077,2.0576
+5.7292,0.47953
+5.1884,0.20421
+6.3557,0.67861
+9.7687,7.5435
+6.5159,5.3436
+8.5172,4.2415
+9.1802,6.7981
+6.002,0.92695
+5.5204,0.152
+5.0594,2.8214
+5.7077,1.8451
+7.6366,4.2959
+5.8707,7.2029
+5.3054,1.9869
+8.2934,0.14454
+13.394,9.0551
+5.4369,0.61705
\ No newline at end of file
diff --git a/algorithms/machine_learning/Gradient-Descent/gradientdescent.m b/algorithms/machine_learning/Gradient-Descent/gradientdescent.m
new file mode 100644
index 0000000..a33c8ff
--- /dev/null
+++ b/algorithms/machine_learning/Gradient-Descent/gradientdescent.m
@@ -0,0 +1,29 @@
+% This function demonstrates gradient descent in case of linear regression with one variable.
+
+% Theta is a column vector with two elements which this function returns after modifying it.
+
+% This function receives the feature vector x, vector of actual target variables Y, Theta
+
+% containing initial values of theta_0 and theta_1, learning rate Alpha, number of iterations
+
+% noi.
+
+function Theta = gradientdescent(x, Y, Theta, Alpha, noi)
+
+ n = length(Y); % Number of training examples.
+
+ for i = 1:noi
+
+ theta_1 = Theta(1) - Alpha * (1 / n) * sum(((x * Theta) - Y) .* x(:, 1)); % Temporary variable to simultaneously update theta_0 but i have used 1 to
+
+ % avoid confusion since indexing in MATLAB/Octave starts from 1.
+
+ theta_2 = Theta(2) - Alpha * (1 / n) * sum(((x * Theta) - Y) .* x(:, 2)); % Temporary variable to simultaneously update theta_1.
+
+ Theta(1) = theta_1; % Assigning first temporary value to update first actual value simultaneously.
+
+ Theta(2) = theta_2; % Assigning second temporary value to update second actual value simultaneously.
+
+ end
+
+end
\ No newline at end of file
diff --git a/algorithms/machine_learning/Gradient-Descent/runGradientDescent.m b/algorithms/machine_learning/Gradient-Descent/runGradientDescent.m
new file mode 100644
index 0000000..60a85a1
--- /dev/null
+++ b/algorithms/machine_learning/Gradient-Descent/runGradientDescent.m
@@ -0,0 +1,29 @@
+% This script will pass sample parameters to gradient descent function and get Theta.
+
+% I have used data consisting of populations as variables and profits as target values.
+
+% Navigate to directory where you keep these three files on octave cli and then execute.
+
+data = load('data_.txt');
+
+Y = data(:, 2); % Y is a column vector with all entries in second column of data matrix.
+
+n = length(Y);
+
+x = [ones(n, 1), data(:,1)]; % x is the matrix with first column as ones and second data.
+
+Theta = zeros(2, 1); % Initial Theta vector with both theta values set to zero (column).
+
+Alpha = 0.01;
+
+noi = 1500;
+
+Theta = gradientdescent(x, Y, Theta, Alpha, noi);
+
+fprintf('New theta vector is below:\n');
+
+fprintf('%f\n', Theta);
+
+fprintf('Expected Theta vector (approx)\n');
+
+fprintf(' -3.6303\n 1.1664\n\n');
\ No newline at end of file
diff --git a/algorithms/machine_learning/Linear-Regression/computecost.m b/algorithms/machine_learning/Linear-Regression/computecost.m
new file mode 100644
index 0000000..ca95974
--- /dev/null
+++ b/algorithms/machine_learning/Linear-Regression/computecost.m
@@ -0,0 +1,9 @@
+function j = computecost(x, Y, Theta)
+
+n = length(Y); % Number of training examples.
+
+j = 0;
+
+j = (1 / (2 * n)) * sum(((x * Theta) - Y).^2);
+
+end
\ No newline at end of file
diff --git a/algorithms/machine_learning/Linear-Regression/data_.txt b/algorithms/machine_learning/Linear-Regression/data_.txt
new file mode 100644
index 0000000..9903f8e
--- /dev/null
+++ b/algorithms/machine_learning/Linear-Regression/data_.txt
@@ -0,0 +1,97 @@
+6.1101,17.592
+5.5277,9.1302
+8.5186,13.662
+7.0032,11.854
+5.8598,6.8233
+8.3829,11.886
+7.4764,4.3483
+8.5781,12
+6.4862,6.5987
+5.0546,3.8166
+5.7107,3.2522
+14.164,15.505
+5.734,3.1551
+8.4084,7.2258
+5.6407,0.71618
+5.3794,3.5129
+6.3654,5.3048
+5.1301,0.56077
+6.4296,3.6518
+7.0708,5.3893
+6.1891,3.1386
+20.27,21.767
+5.4901,4.263
+6.3261,5.1875
+5.5649,3.0825
+18.945,22.638
+12.828,13.501
+10.957,7.0467
+13.176,14.692
+22.203,24.147
+5.2524,-1.22
+6.5894,5.9966
+9.2482,12.134
+5.8918,1.8495
+8.2111,6.5426
+7.9334,4.5623
+8.0959,4.1164
+5.6063,3.3928
+12.836,10.117
+6.3534,5.4974
+5.4069,0.55657
+6.8825,3.9115
+11.708,5.3854
+5.7737,2.4406
+7.8247,6.7318
+7.0931,1.0463
+5.0702,5.1337
+5.8014,1.844
+11.7,8.0043
+5.5416,1.0179
+7.5402,6.7504
+5.3077,1.8396
+7.4239,4.2885
+7.6031,4.9981
+6.3328,1.4233
+6.3589,-1.4211
+6.2742,2.4756
+5.6397,4.6042
+9.3102,3.9624
+9.4536,5.4141
+8.8254,5.1694
+5.1793,-0.74279
+21.279,17.929
+14.908,12.054
+18.959,17.054
+7.2182,4.8852
+8.2951,5.7442
+10.236,7.7754
+5.4994,1.0173
+20.341,20.992
+10.136,6.6799
+7.3345,4.0259
+6.0062,1.2784
+7.2259,3.3411
+5.0269,-2.6807
+6.5479,0.29678
+7.5386,3.8845
+5.0365,5.7014
+10.274,6.7526
+5.1077,2.0576
+5.7292,0.47953
+5.1884,0.20421
+6.3557,0.67861
+9.7687,7.5435
+6.5159,5.3436
+8.5172,4.2415
+9.1802,6.7981
+6.002,0.92695
+5.5204,0.152
+5.0594,2.8214
+5.7077,1.8451
+7.6366,4.2959
+5.8707,7.2029
+5.3054,1.9869
+8.2934,0.14454
+13.394,9.0551
+5.4369,0.61705
\ No newline at end of file
diff --git a/algorithms/machine_learning/Linear-Regression/gradientdescent.m b/algorithms/machine_learning/Linear-Regression/gradientdescent.m
new file mode 100644
index 0000000..a33c8ff
--- /dev/null
+++ b/algorithms/machine_learning/Linear-Regression/gradientdescent.m
@@ -0,0 +1,29 @@
+% This function demonstrates gradient descent in case of linear regression with one variable.
+
+% Theta is a column vector with two elements which this function returns after modifying it.
+
+% This function receives the feature vector x, vector of actual target variables Y, Theta
+
+% containing initial values of theta_0 and theta_1, learning rate Alpha, number of iterations
+
+% noi.
+
+function Theta = gradientdescent(x, Y, Theta, Alpha, noi)
+
+ n = length(Y); % Number of training examples.
+
+ for i = 1:noi
+
+ theta_1 = Theta(1) - Alpha * (1 / n) * sum(((x * Theta) - Y) .* x(:, 1)); % Temporary variable to simultaneously update theta_0 but i have used 1 to
+
+ % avoid confusion since indexing in MATLAB/Octave starts from 1.
+
+ theta_2 = Theta(2) - Alpha * (1 / n) * sum(((x * Theta) - Y) .* x(:, 2)); % Temporary variable to simultaneously update theta_1.
+
+ Theta(1) = theta_1; % Assigning first temporary value to update first actual value simultaneously.
+
+ Theta(2) = theta_2; % Assigning second temporary value to update second actual value simultaneously.
+
+ end
+
+end
\ No newline at end of file
diff --git a/algorithms/machine_learning/Linear-Regression/plotdata.m b/algorithms/machine_learning/Linear-Regression/plotdata.m
new file mode 100644
index 0000000..bb540c4
--- /dev/null
+++ b/algorithms/machine_learning/Linear-Regression/plotdata.m
@@ -0,0 +1,11 @@
+function plotdata(x, Y)
+
+figure;
+
+plot(x, Y, 'rx', 'MarkerSize', 10); % rx means red coloured x.
+
+ylabel('Profit in $10,000s');
+
+xlabel('Population of city in 10,000s');
+
+end
\ No newline at end of file
diff --git a/algorithms/machine_learning/Linear-Regression/runLinearRegression.m b/algorithms/machine_learning/Linear-Regression/runLinearRegression.m
new file mode 100644
index 0000000..5a23f29
--- /dev/null
+++ b/algorithms/machine_learning/Linear-Regression/runLinearRegression.m
@@ -0,0 +1,59 @@
+% This file runs univariate linear regression to predict profits of food trucks based on previous
+
+% actual values of profits in $10,000s in various cities with populations in 10,000s respectively.
+
+clear ; close all; clc ;
+
+fprintf('Plotting data\n');
+
+data = load('data_.txt');
+x = data(:, 1); Y = data(:, 2);
+n = length(Y); % Number of training examples.
+
+plotdata(x, Y);
+
+fprintf('Program paused, press enter to continue\n');
+
+pause;
+
+x = [ones(n, 1), data(:,1)];
+Theta = zeros(2, 1);
+
+noi = 1500; % Number of iterations in gradient descent.
+Alpha = 0.01; % Learning rate.
+
+fprintf('Testing the cost function\n')
+
+j = computecost(x, Y, Theta);
+fprintf('With Theta = [0 ; 0]\nCost computed = %f\n', j);
+fprintf('Expected cost value (approx) 32.07\n');
+
+j = computecost(x, Y, [-1 ; 2]);
+fprintf('With theta = [-1 ; 2]\nCost computed = %f\n', j);
+fprintf('Expected cost value (approx) 54.24\n');
+
+fprintf('Program paused, press enter to continue\n');
+
+pause;
+
+fprintf('Running gradient descent\n');
+
+Theta = gradientdescent(x, Y, Theta, Alpha, noi);
+
+fprintf('Theta found by gradient descent\n');
+fprintf('%f\n', Theta);
+fprintf('Expected Theta vector (approx)\n');
+fprintf(' -3.6303\n 1.1664\n\n');
+
+hold on; % To plot hypothesis on data.
+
+plot(x(:, 2), x * Theta, '-');
+legend('Training data', 'Linear regression');
+
+predict1 = [1, 3.5] * Theta;
+fprintf('For population = 35,000, we predict a profit of %f\n',...
+ predict1*10000);
+
+predict2 = [1, 7] * Theta;
+fprintf('For population = 70,000, we predict a profit of %f\n',...
+ predict2*10000);
\ No newline at end of file
diff --git a/algorithms/machine_learning/Logistic-Regression/Predict.m b/algorithms/machine_learning/Logistic-Regression/Predict.m
new file mode 100644
index 0000000..539bb5c
--- /dev/null
+++ b/algorithms/machine_learning/Logistic-Regression/Predict.m
@@ -0,0 +1,17 @@
+function P = Predict(Theta, X)
+
+n = size(X, 1);
+
+P = zeros(n, 1);
+
+for i = 1 : n,
+
+ if Sigmoid(X * Theta)(i) >= 0.5
+
+ P(i) = 1;
+
+ end
+
+end
+
+end
\ No newline at end of file
diff --git a/algorithms/machine_learning/Logistic-Regression/Sigmoid.m b/algorithms/machine_learning/Logistic-Regression/Sigmoid.m
new file mode 100644
index 0000000..b15e6f2
--- /dev/null
+++ b/algorithms/machine_learning/Logistic-Regression/Sigmoid.m
@@ -0,0 +1,17 @@
+function G = Sigmoid(Z)
+
+G = zeros(size(Z));
+
+a = size(Z);
+
+for i = 1 : a(1, 1),
+
+ for j = 1 : a(1, 2),
+
+ G(i, j) = 1 / (1 + e.^-Z(i, j));
+
+ end
+
+end
+
+end
\ No newline at end of file
diff --git a/algorithms/machine_learning/Logistic-Regression/costfunction.m b/algorithms/machine_learning/Logistic-Regression/costfunction.m
new file mode 100644
index 0000000..c4a88f6
--- /dev/null
+++ b/algorithms/machine_learning/Logistic-Regression/costfunction.m
@@ -0,0 +1,15 @@
+function [j, Grad] = costfunction(Theta, X, Y)
+
+n = length(Y);
+
+j = 0;
+
+j = (1/n)*(-Y'* log(Sigmoid(X * Theta)) - (1 - Y)'* log(1 - Sigmoid(X * Theta))); % See the sigmoid function.
+
+Grad = zeros(size(Theta));
+
+Grad_ = (1 / n) * ((Sigmoid(X * Theta) - Y)' * X);
+
+Grad = Grad_';
+
+end
\ No newline at end of file
diff --git a/algorithms/machine_learning/Logistic-Regression/data.txt b/algorithms/machine_learning/Logistic-Regression/data.txt
new file mode 100644
index 0000000..d7e2995
--- /dev/null
+++ b/algorithms/machine_learning/Logistic-Regression/data.txt
@@ -0,0 +1,100 @@
+34.62365962451697,78.0246928153624,0
+30.28671076822607,43.89499752400101,0
+35.84740876993872,72.90219802708364,0
+60.18259938620976,86.30855209546826,1
+79.0327360507101,75.3443764369103,1
+45.08327747668339,56.3163717815305,0
+61.10666453684766,96.51142588489624,1
+75.02474556738889,46.55401354116538,1
+76.09878670226257,87.42056971926803,1
+84.43281996120035,43.53339331072109,1
+95.86155507093572,38.22527805795094,0
+75.01365838958247,30.60326323428011,0
+82.30705337399482,76.48196330235604,1
+69.36458875970939,97.71869196188608,1
+39.53833914367223,76.03681085115882,0
+53.9710521485623,89.20735013750205,1
+69.07014406283025,52.74046973016765,1
+67.94685547711617,46.67857410673128,0
+70.66150955499435,92.92713789364831,1
+76.97878372747498,47.57596364975532,1
+67.37202754570876,42.83843832029179,0
+89.67677575072079,65.79936592745237,1
+50.534788289883,48.85581152764205,0
+34.21206097786789,44.20952859866288,0
+77.9240914545704,68.9723599933059,1
+62.27101367004632,69.95445795447587,1
+80.1901807509566,44.82162893218353,1
+93.114388797442,38.80067033713209,0
+61.83020602312595,50.25610789244621,0
+38.78580379679423,64.99568095539578,0
+61.379289447425,72.80788731317097,1
+85.40451939411645,57.05198397627122,1
+52.10797973193984,63.12762376881715,0
+52.04540476831827,69.43286012045222,1
+40.23689373545111,71.16774802184875,0
+54.63510555424817,52.21388588061123,0
+33.91550010906887,98.86943574220611,0
+64.17698887494485,80.90806058670817,1
+74.78925295941542,41.57341522824434,0
+34.1836400264419,75.2377203360134,0
+83.90239366249155,56.30804621605327,1
+51.54772026906181,46.85629026349976,0
+94.44336776917852,65.56892160559052,1
+82.36875375713919,40.61825515970618,0
+51.04775177128865,45.82270145776001,0
+62.22267576120188,52.06099194836679,0
+77.19303492601364,70.45820000180959,1
+97.77159928000232,86.7278223300282,1
+62.07306379667647,96.76882412413983,1
+91.56497449807442,88.69629254546599,1
+79.94481794066932,74.16311935043758,1
+99.2725269292572,60.99903099844988,1
+90.54671411399852,43.39060180650027,1
+34.52451385320009,60.39634245837173,0
+50.2864961189907,49.80453881323059,0
+49.58667721632031,59.80895099453265,0
+97.64563396007767,68.86157272420604,1
+32.57720016809309,95.59854761387875,0
+74.24869136721598,69.82457122657193,1
+71.79646205863379,78.45356224515052,1
+75.3956114656803,85.75993667331619,1
+35.28611281526193,47.02051394723416,0
+56.25381749711624,39.26147251058019,0
+30.05882244669796,49.59297386723685,0
+44.66826172480893,66.45008614558913,0
+66.56089447242954,41.09209807936973,0
+40.45755098375164,97.53518548909936,1
+49.07256321908844,51.88321182073966,0
+80.27957401466998,92.11606081344084,1
+66.74671856944039,60.99139402740988,1
+32.72283304060323,43.30717306430063,0
+64.0393204150601,78.03168802018232,1
+72.34649422579923,96.22759296761404,1
+60.45788573918959,73.09499809758037,1
+58.84095621726802,75.85844831279042,1
+99.82785779692128,72.36925193383885,1
+47.26426910848174,88.47586499559782,1
+50.45815980285988,75.80985952982456,1
+60.45555629271532,42.50840943572217,0
+82.22666157785568,42.71987853716458,0
+88.9138964166533,69.80378889835472,1
+94.83450672430196,45.69430680250754,1
+67.31925746917527,66.58935317747915,1
+57.23870631569862,59.51428198012956,1
+80.36675600171273,90.96014789746954,1
+68.46852178591112,85.59430710452014,1
+42.0754545384731,78.84478600148043,0
+75.47770200533905,90.42453899753964,1
+78.63542434898018,96.64742716885644,1
+52.34800398794107,60.76950525602592,0
+94.09433112516793,77.15910509073893,1
+90.44855097096364,87.50879176484702,1
+55.48216114069585,35.57070347228866,0
+74.49269241843041,84.84513684930135,1
+89.84580670720979,45.35828361091658,1
+83.48916274498238,48.38028579728175,1
+42.2617008099817,87.10385094025457,1
+99.31500880510394,68.77540947206617,1
+55.34001756003703,64.9319380069486,1
+74.77589300092767,89.52981289513276,1
\ No newline at end of file
diff --git a/algorithms/machine_learning/Logistic-Regression/plotdata.m b/algorithms/machine_learning/Logistic-Regression/plotdata.m
new file mode 100644
index 0000000..0f206ce
--- /dev/null
+++ b/algorithms/machine_learning/Logistic-Regression/plotdata.m
@@ -0,0 +1,19 @@
+function plotdata(x, Y)
+
+figure;
+
+hold on;
+
+Pos = find(Y == 1);
+
+Neg = find(Y == 0);
+
+plot(x(Pos, 1), x(Pos, 2), 'k+','LineWidth', 2, ...
+ 'MarkerSize', 7);
+
+plot(x(Neg, 1), x(Neg, 2), 'ko', 'MarkerFaceColor', 'y', ...
+ 'MarkerSize', 7);
+
+hold off;
+
+end
\ No newline at end of file
diff --git a/algorithms/machine_learning/Logistic-Regression/plotdecisionboundary.m b/algorithms/machine_learning/Logistic-Regression/plotdecisionboundary.m
new file mode 100644
index 0000000..66aeddd
--- /dev/null
+++ b/algorithms/machine_learning/Logistic-Regression/plotdecisionboundary.m
@@ -0,0 +1,43 @@
+function plotdecisionboundary(Theta, X, Y)
+
+plotdata(X(:,2:3), Y);
+
+hold on;
+
+if size(X, 2) <= 3
+
+ plot_X = [min(X(:,2))-2, max(X(:,2))+2];
+
+ plot_Y = (-1./Theta(3)).*(Theta(2).*plot_X + Theta(1));
+
+ plot(plot_X, plot_Y);
+
+ legend('Admitted', 'Not admitted', 'Decision Boundary');
+
+ axis([30, 100, 30, 100]);
+
+else
+
+ U = linspace(-1, 1.5, 50);
+
+ V = linspace(-1, 1.5, 50);
+
+ Z = zeros(length(U), length(V));
+
+ for i = 1:length(U)
+
+ for j = 1:length(V)
+
+ Z(i,j) = mapFeature(U(i), V(j))*Theta;
+
+ end
+
+ end
+
+ Z = Z';
+
+end
+
+hold off;
+
+end
\ No newline at end of file
diff --git a/algorithms/machine_learning/Logistic-Regression/runLogisticRegression.m b/algorithms/machine_learning/Logistic-Regression/runLogisticRegression.m
new file mode 100644
index 0000000..75034ca
--- /dev/null
+++ b/algorithms/machine_learning/Logistic-Regression/runLogisticRegression.m
@@ -0,0 +1,82 @@
+clear; close all; clc;
+
+Data = load('data.txt');
+x = Data(:, [1, 2]); Y = Data(:, 3);
+
+fprintf(['Plotting data with + indicating (Y = 1) examples and o ' ...
+ 'indicating (Y = 0) examples.\n']);
+
+plotdata(x, Y);
+
+hold on;
+
+xlabel('Exam 1 score');
+ylabel('Exam 2 score');
+
+legend('Admitted', 'Not admitted');
+hold off;
+
+fprintf('\nProgram paused, press enter to continue.\n');
+pause;
+
+[m, n] = size(x);
+
+X = [ones(m, 1) x];
+
+Initial_Theta = zeros(n + 1, 1);
+
+[Cost, Grad] = costfunction(Initial_Theta, X, Y);
+
+fprintf('Cost at initial theta (zeros): %f\n', Cost);
+fprintf('Expected cost (approx): 0.693\n');
+fprintf('Gradient at initial theta (zeros): \n');
+fprintf(' %f \n', Grad);
+fprintf('Expected gradients (approx):\n -0.1000\n -12.0092\n -11.2628\n');
+
+Test_Theta = [-24; 0.2; 0.2];
+[Cost, Grad] = costfunction(Test_Theta, X, Y);
+
+fprintf('\nCost at test theta: %f\n', Cost);
+fprintf('Expected cost (approx): 0.218\n');
+fprintf('Gradient at test theta: \n');
+fprintf(' %f \n', Grad);
+fprintf('Expected gradients (approx):\n 0.043\n 2.566\n 2.647\n');
+
+fprintf('\nProgram paused, press enter to continue.\n');
+pause;
+
+Options = optimset('GradObj', 'on', 'MaxIter', 400);
+
+[Theta, Cost] = ...
+ fminunc(@(t)(costfunction(t, X, Y)), Initial_Theta, Options);
+
+fprintf('Cost at theta found by fminunc: %f\n', Cost);
+fprintf('Expected cost (approx): 0.203\n');
+fprintf('theta: \n');
+fprintf(' %f \n', Theta);
+fprintf('Expected theta (approx):\n');
+fprintf(' -25.161\n 0.206\n 0.201\n');
+
+plotdecisionboundary(Theta, X, Y);
+
+hold on;
+
+xlabel('Exam 1 score');
+ylabel('Exam 2 score');
+
+legend('Admitted', 'Not admitted');
+hold off;
+
+fprintf('\nProgram paused, press enter to continue.\n');
+pause;
+
+Prob = Sigmoid([1 45 85] * Theta);
+fprintf(['For a student with scores 45 and 85, we predict an admission ' ...
+ 'probability of %f\n'], Prob);
+fprintf('Expected value: 0.775 +/- 0.002\n\n');
+
+P = Predict(Theta, X);
+
+fprintf('Train accuracy: %f\n', mean(double(P == Y)) * 100);
+fprintf('Expected accuracy (approx): 89.0\n');
+fprintf('\n');
\ No newline at end of file
diff --git a/algorithms/machine_learning/Nearest-Neighbor/brightness.m b/algorithms/machine_learning/Nearest-Neighbor/brightness.m
new file mode 100644
index 0000000..54e40be
--- /dev/null
+++ b/algorithms/machine_learning/Nearest-Neighbor/brightness.m
@@ -0,0 +1,49 @@
+function y = brightness(red, green, blue)
+ % brightness: returns 1 if the color is light otherwise 0
+ % INPUT: RGB-value of the color (red, green, blue)
+ % OUTPUT: 0 or 1 (0 dark, 1 light)
+ % The function used the nearest neighbor algorithm
+
+ % train set for various rgb-values and its brightness
+ % the set contains vectors with dimension 4x1
+ % [r, g, b, brightness]
+ train_set = [2, 99, 255, 1;
+ 37,44,58,0;
+ 139, 169, 229,1;
+ 14, 255, 10, 1;
+ 2, 28, 1, 0;
+ 20, 33, 20, 0;
+ 252, 227, 65,1;
+ 71, 65, 24, 0;
+ 168, 80, 80,1;
+ 119, 35, 90, 0;
+ 186, 13, 126, 1;];
+
+ function length = eulidean(v1, v2)
+ % eulidean: calculates the eulidean length between two vectors (3x1)
+ % The calculation contains only the RGB-values! (3x1)
+ % HELPER-FUNCTION
+ length = sqrt((v2(1)-v1(1))^2 + (v2(2)-v1(2))^2 + (v2(3)-v1(3))^2);
+ endfunction
+
+
+ rgb = [red green blue];
+ x1 = train_set(1,:);
+ x2 = x1(1:3);
+ min = eulidean(rgb,x2);
+ index = 1;
+
+ for i = 2:length(train_set)
+ x1 = train_set(i,:);
+ x2 = x1(1:3);
+ result = eulidean(rgb,x2);
+ if (result < min)
+ min = result;
+ index = i;
+ end
+ end
+
+ y = train_set(index,:)(4);
+
+
+endfunction
\ No newline at end of file
diff --git a/algorithms/machine_learning/kmeans/irisdataset.mat b/algorithms/machine_learning/kmeans/irisdataset.mat
new file mode 100644
index 0000000..53c5a40
Binary files /dev/null and b/algorithms/machine_learning/kmeans/irisdataset.mat differ
diff --git a/algorithms/machine_learning/kmeans/kmeans.m b/algorithms/machine_learning/kmeans/kmeans.m
new file mode 100644
index 0000000..f28549d
--- /dev/null
+++ b/algorithms/machine_learning/kmeans/kmeans.m
@@ -0,0 +1,100 @@
+%% clearing the workspace
+clc;close all;clear;
+
+%% What is K-Means?
+% K-Means is a clustering algorithm that aims to parition n points
+% into K clusters.
+
+%% Lets load up a dataset
+% We will use the iris dataset to demonstrate the power
+% of the k-means algorithm. The data set consists of 50 samples
+% from each of three species of Iris (Iris setosa,
+% Iris virginica and Iris versicolor).
+% It consists of four features the length and width of the sepals, petals
+% in centimeters.We will just use the last two features in this script.
+
+disp("Loading Iris dataset")
+
+load irisdataset
+iris_data = meas(:,3:4);
+
+%% Visualizing the dataset
+% lets plot the points
+disp("Visualizing data")
+figure(1)
+plot(iris_data(:,1),iris_data(:,2),'k*','MarkerSize',5);
+title 'Fisher''s Iris Data';
+xlabel 'Petal Lengths (cm)';
+ylabel 'Petal Widths (cm)';
+% close all;
+%% K-Means implementation
+
+% K is number of clusters
+K = 3;
+
+% First we randomly pick K centroids that will represent each cluster
+% rand_centroid_idx = randi(length(meas),K,1);
+rand_centroid_idx = [1,55,125];
+centroids = iris_data(rand_centroid_idx,:);
+
+max_iterations = 100;
+
+cluster_assigned = zeros(length(iris_data),1);
+
+% Make zero vectors to keep track of the sum of each sample
+% in the cluster.
+cluster_sum = zeros(K,2);
+cluster_samples = zeros(K,1);
+
+disp("Running k-means!")
+for iter = 1:max_iterations
+
+ %Assign each point to a cluster
+ for num_sample = 1:length(iris_data)
+
+ %Find the eulidean distance between a sample and the centroids
+ temp = iris_data(num_sample,:) - centroids;
+ euc_dist = vecnorm(temp,2,2);
+
+ % Get the index of centroid with the minimum distance.
+ % That will be the cluster we assign the sample to.
+ closest_cluster = find(euc_dist == min(euc_dist));
+
+ % Assign the sample to the cluster.
+ cluster_assigned(num_sample) = closest_cluster;
+
+ % Add the samples that belong to the same cluster.
+ cluster_sum(closest_cluster,:) = cluster_sum(closest_cluster,:) ...
+ + iris_data(num_sample,:);
+
+ % Track the number of samples in the cluster.
+ cluster_samples(closest_cluster) = cluster_samples(closest_cluster)+1;
+
+ end
+
+ % Update the centroids by the mean of all the points that belong to
+ % that cluster.
+ centroids = cluster_sum ./ cluster_samples;
+
+ % Reset to zeros for the next iteration
+ cluster_sum = zeros(K,2);
+ cluster_samples = zeros(K,1);
+end
+disp("Clustering finished!")
+
+%% Lets see how well K-Means it did!
+disp("Displaying Clusters")
+
+figure(2)
+for i=1:K
+ pts = iris_data(cluster_assigned==i,:);
+ plot(pts(:,1),pts(:,2),'.','color',rand(1,3),'MarkerSize',12); hold on;
+end
+
+plot(centroids(:,1),centroids(:,2),'r+','MarkerSize',12);
+title 'Fisher''s Iris Data';
+xlabel 'Petal Lengths (cm)';
+ylabel 'Petal Widths (cm)';
+legend('Cluster 1','Cluster 2','Cluster 3','Centroids',...
+ 'Location','northwest')
+
diff --git a/algorithms/maths/euclidean_distance.m b/algorithms/maths/euclidean_distance.m
new file mode 100644
index 0000000..91c9cb9
--- /dev/null
+++ b/algorithms/maths/euclidean_distance.m
@@ -0,0 +1,14 @@
+% This function takes two n-dimensional vectors as input and calculates the euclidean distance
+function distance = euclidean_distance(coordinate_1,coordinate_2)
+ if length(coordinate_1) ~= length(coordinate_2)
+ disp('Dimensions of vectors do not match!')
+ distance = NaN;
+ else
+ sum = 0;
+ for i=1:1:length(coordinate_1)
+ difference = (coordinate_2(i)-coordinate_1(i))^2;
+ sum = sum + difference;
+ end
+ distance = sqrt(sum);
+ end
+end
diff --git a/algorithms/maths/fibonacci_sequence.m b/algorithms/maths/fibonacci_sequence.m
new file mode 100644
index 0000000..4661834
--- /dev/null
+++ b/algorithms/maths/fibonacci_sequence.m
@@ -0,0 +1,12 @@
+%% Fibonacci Sequence
+function [f] = fibo(n);
+% n terms of Fibonacci sequence will be calculate and shown
+f = zeros(n,1); % vector with n arrays
+f(1) = 0;
+f(2) = 1;
+for k = 3:n
+ f(k) = f(k-1) + f(k-2);
+end
+disp([num2str(n), ' terms of Fibonacci sequence:']);
+disp(f(1:n));
+end
diff --git a/algorithms/maths/find_factorial.m b/algorithms/maths/find_factorial.m
new file mode 100644
index 0000000..3c1a1e6
--- /dev/null
+++ b/algorithms/maths/find_factorial.m
@@ -0,0 +1,17 @@
+%% Factorial
+function [f] = find_factorial(n)
+% calculate the factorial of a positive integer n
+% factorial(n)can be used directly as a default function of Matlab
+
+integerTest= ~mod(n,1); %it returns 0 if value is not an integer.
+if integerTest== 0 || n < 0; % checking n to be positive & integer
+ disp('Error! your number muss be positive and integer');
+else
+ f = 1;
+ for i = 1:n
+ f = f*i;
+ end
+ disp(['factorial of ',num2str(n),' is: ',num2str(f)]);
+end
+end
+
diff --git a/algorithms/maths/highest_common_factor.m b/algorithms/maths/highest_common_factor.m
new file mode 100644
index 0000000..28ad91b
--- /dev/null
+++ b/algorithms/maths/highest_common_factor.m
@@ -0,0 +1,16 @@
+function HCF = highest_common_factor (x, y)
+%This function searches for highest common factor
+%It first checks if any of the numbers equal to zero, if so the non zero number is the HCF
+%If the numbers are different, you minus the bigger number by the smaller one and this is done by recursion.
+ if x==0
+ HCF = y;
+ elseif y==0
+ HCF = x;
+ elseif (y == x)
+ HCF = x;
+ elseif (y>x)
+ HCF = highest_common_factor(y-x,x);
+ else
+ HCF = highest_common_factor(x-y,y);
+ end
+
diff --git a/algorithms/maths/is_armstrong.m b/algorithms/maths/is_armstrong.m
new file mode 100644
index 0000000..a229e5b
--- /dev/null
+++ b/algorithms/maths/is_armstrong.m
@@ -0,0 +1,18 @@
+%% Armstrong no
+
+function n= is_armstrong(num)
+if(num<0)
+ n=0; %as negative no can't be armstrong
+end
+sum=0;
+temp=num;
+while(temp>0)
+ sum=sum*10 + rem(temp,10);
+ temp=fix(temp/10);
+end
+if(sum==num)
+ n=1; % the no is armstrong
+else
+ n=0; % the no is not armstrong
+end
+end
diff --git a/algorithms/maths/jaccard_similarity.m b/algorithms/maths/jaccard_similarity.m
new file mode 100644
index 0000000..5fe1dff
--- /dev/null
+++ b/algorithms/maths/jaccard_similarity.m
@@ -0,0 +1,35 @@
+function p = jaccard_similarity(A,B)
+%% jaccard similarity
+% This function calculates jaccard similarity index of inputs arrays A and
+% B. The formula to find the Index is (number of entries in both sets) / (number of entries in either set) * 100
+% The higher the percentage, the more similar the two arrays.
+% For this, each of input arrays is modified by removing its same entries
+% (except on them), then number of common entries between two new arrays is
+% calculated by comparing them.
+
+modified_A = unique(A);
+modified_B = unique(B);
+
+length_mA = length(modified_A);
+length_mB = length(modified_B);
+common_number = 0; %initialize the number of common entries
+
+if length_mA <= length_mB
+ X = modified_A;
+ Y = modified_B;
+else
+ X = modified_B;
+ Y = modified_A;
+end
+
+for i = 1:length(X)
+ for j = 1:length(Y)
+ if X(i) == Y(j)
+ common_number = common_number + 1;
+ end
+ end
+end
+
+total_number = length_mA + length_mB - common_number;
+p = (common_number/total_number)*100;
+end
diff --git a/algorithms/maths/lcm.m b/algorithms/maths/lcm.m
new file mode 100644
index 0000000..58cb07d
--- /dev/null
+++ b/algorithms/maths/lcm.m
@@ -0,0 +1,11 @@
+% function to calculate lcm of two number a and b using gcd of two numbers.
+
+function [ret] = lcm(a, b)
+ if b == 0
+ re = a;
+ ret=(a*b)/re; % i.e zero
+
+ else
+ re = gcd(b, mod(a, b));
+ ret=(a*b)/re;
+ end
diff --git a/algorithms/maths/linear_diophantine_eqn.m b/algorithms/maths/linear_diophantine_eqn.m
new file mode 100644
index 0000000..12f5824
--- /dev/null
+++ b/algorithms/maths/linear_diophantine_eqn.m
@@ -0,0 +1,12 @@
+% Linear Diophantine Equation
+%Given three integers a, b, c representing a linear equation of the form : ax + by = c.
+%To find if the equation has a solution such that x and y are both integral values.
+%Used in programming to find the exact solution exists or not.
+
+function retval = linear_diophantine_eqn (a,b,c)
+ if mod(c,gcd(a,b))==0
+ retval=true; % 1 represent yes it exist
+ else
+ retval= false; % 0 represent no it doesn't exist
+
+end
diff --git a/algorithms/maths/prime_check.m b/algorithms/maths/prime_check.m
new file mode 100644
index 0000000..e0a0ed7
--- /dev/null
+++ b/algorithms/maths/prime_check.m
@@ -0,0 +1,37 @@
+function p = prime_check(n)
+%% Prime Check
+% Tis function checks wheather the input number is prime of not.
+% For this, it checks if the input number is dividable by numbers less than
+% its half+1.
+% If number is dividable by one of these numbers function displays "not
+% prime number" and returns 0 as output, otherwise it displays "prime
+% number" and returns 1 as output.
+
+if n <= 0
+ disp('input must be positive integer')
+else if floor(n)~= n
+ disp('input must be positive integer')
+ else if n == 2
+ disp([num2str(n), ' is prime number'])
+ p = 1;
+ else
+ half_n = floor(n/2)+1;
+ i = 2;
+ while i <= half_n
+ residual = mod(n,i);
+ if residual == 0
+ disp([num2str(n), ' is not prime number'])
+ p = 0;
+ break
+ else if i == half_n
+ disp([num2str(n), ' is prime number'])
+ p = 1;
+ break
+ else
+ i=i+1;
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/algorithms/maths/prime_factorial.m b/algorithms/maths/prime_factorial.m
new file mode 100644
index 0000000..94510ee
--- /dev/null
+++ b/algorithms/maths/prime_factorial.m
@@ -0,0 +1,51 @@
+clear all
+clc
+
+%% Prime Factors
+% This code gets user input number, calculates and displays its prime factors.
+% For this, first it determines prime numbers which are less than or equal to
+% user input number. Then if the input is dividable by that prime number,
+% it becomes one of input's prime factors.
+
+%% Request user input
+prompt = 'Input your number: ';
+n = input(prompt);
+
+%%
+counter = 0; % initialize number of prime factors
+
+if n <= 1
+ disp('input must be positive integer greater than 1')
+else if floor(n)~= n
+ disp('input must be positive integer')
+ else
+ for i = 2:1:n
+ if i == 2
+ isprime = 1;
+ else
+ half_i = floor(i/2)+1;
+ j = 2;
+ while j <= half_i %lines 16 to 30 check if i is prime or not.
+ residual = mod(i,j);
+ if residual == 0
+ isprime = 0;
+ break
+ else if j == half_i
+ isprime = 1;
+ break
+ else
+ j=j+1;
+ end
+ end
+ end
+ end
+ if isprime == 1 && mod(n,i) == 0
+ counter=counter+1;
+ f(counter) = i; % prime factors of n will be storing
+ end
+ end
+ end
+end
+
+disp('Prime factors of input number are: ')
+disp(f)
diff --git a/algorithms/maths/shreeDharacharyaFormula.m b/algorithms/maths/shreeDharacharyaFormula.m
new file mode 100644
index 0000000..919d28c
--- /dev/null
+++ b/algorithms/maths/shreeDharacharyaFormula.m
@@ -0,0 +1,16 @@
+%% Shree Dharacharya Formula
+% aX^2 + bX + c = 0
+function [x1,x2] = shreeDharacharyaFormula(a,b,c)
+ % calculates the roots of a quadratic equation.
+ d = b^2 - 4*a*c;
+
+ if d < 0
+ disp('Imaginary roots');
+
+ else
+ x1 = (-b + d^(1/2))/(2*a);
+
+ x2 = (-b - d^(1/2))/(2*a);
+ end
+
+end
diff --git a/algorithms/maths/sum_of_digits.m b/algorithms/maths/sum_of_digits.m
new file mode 100644
index 0000000..0ae6359
--- /dev/null
+++ b/algorithms/maths/sum_of_digits.m
@@ -0,0 +1,15 @@
+%% Sum of digits
+
+function sum = sum_of_digits(number)
+%if someone input a negative no then it will make it positive
+if(number<0)
+ number=(-1)*number;
+end %end of "if"
+sum=0;
+while(number>0)
+ sum=sum+rem(number,10);
+ number=fix(number/10);
+end % end for "while"
+end %end of
+
+
diff --git a/algorithms/maths/to_polar.m b/algorithms/maths/to_polar.m
new file mode 100644
index 0000000..3b8cb5c
--- /dev/null
+++ b/algorithms/maths/to_polar.m
@@ -0,0 +1,16 @@
+function [r, theta] = topolar(x,y)
+%% Converts cartesian coordinates to polar.
+r = sqrt(x^2 + y^2);
+
+if x >= 0
+ theta = atan(y/x);
+else
+ theta = atan(y/x) + pi;
+end
+
+ theta = theta*(180/pi);
+ disp('Hypotenus')
+ disp(r)
+ disp('theta')
+ disp(theta)
+end
diff --git a/algorithms/maths/twos_complement_of_binary.m b/algorithms/maths/twos_complement_of_binary.m
new file mode 100644
index 0000000..f8bc8c5
--- /dev/null
+++ b/algorithms/maths/twos_complement_of_binary.m
@@ -0,0 +1,35 @@
+%% 2's complement of binary no;
+
+function twos_comp = twos_complement_of_binary(bin)
+c=0;
+temp=bin;
+twos_comp=0;
+while(temp>0 && rem(temp,10)==0)
+ twos_comp=twos_comp*10 + rem(temp,10);
+ temp=fix(temp/10);
+ c=c+1;
+end
+if(temp>0)
+ twos_comp=twos_comp*10 + rem(temp,10);
+ temp=fix(temp/10);
+ c=c+1;
+end
+while(temp>0)
+ if(rem(temp,10)==1)
+ twos_comp=twos_comp*10 + 0;
+ else
+ twos_comp=twos_comp*10 + 1;
+ end
+ temp=fix(temp/10);
+ c=c+1;
+end
+
+temp=twos_comp;
+twos_comp=0;
+while(c>0) %reversing the order;
+ twos_comp=twos_comp*10 + rem(temp,10);
+ temp=fix(temp/10);
+ c=c-1;
+end
+end
+
diff --git a/algorithms/other/tic_tac_toe.m b/algorithms/other/tic_tac_toe.m
new file mode 100644
index 0000000..4cc0d30
--- /dev/null
+++ b/algorithms/other/tic_tac_toe.m
@@ -0,0 +1,92 @@
+% Author: Syed Haseeb Shah (QuantumNovice)
+%Simple Tic Tac Toe
+
+% Creates a row vector
+space = 1:9;
+
+% Converts it into matrix
+space = reshape(space,[3,3]);
+space = string(space);
+
+marker = 'O';
+reset = 0;
+changes = 0;
+
+for r = 1:3
+ disp( space(r,1) + " | " + space(r,2) + " | " +space(r,3) )
+ disp(' | |')
+ disp( '___________________')
+end
+
+while reset ~= 1
+
+ pos = input( char("Player ("+marker+")<< "));
+
+ if and(space(pos) ~= 'O', space(pos) ~= 'X')
+ space(pos) = marker;
+ changes = 1;
+ end
+ clc
+ % Win Check
+ for i = 1:3
+ % If rows are similaroz
+ if or(sum(space(i, :) == ["X","X","X"]) == 3, sum(space(i, :) == ["O","O","O"]) == 3)
+ disp("Player "+marker+" Wins")
+ reset = 1;
+ break
+ end
+ % If cols are similar
+ if or(sum(space(:, i) == ["X";"X";"X"]) == 3, sum(space(:, i) == ["O";"O";"O"]) == 3)
+ disp("Player "+marker+" Wins")
+ reset = 1;
+ break
+ end
+ % main diagonal
+ if and(space(1,1) == space(2,2), space(2,2) == space(3,3))
+ disp("Player "+marker+" Wins")
+ reset = 1;
+ break
+ end
+
+ % cross diagonal
+ if and(space(1,3) == space(2,2), space(2,2) == space(3,1))
+ disp("Player "+marker+" Wins")
+ reset = 1;
+ break
+ end
+
+ end
+
+ % Game Draw
+
+ count = 0;
+ for elm = 1:9
+ if or(space(elm) == "X", space(elm) == "O")
+ count = count + 1;
+ end
+ if count == 9
+ disp ("Game Draw")
+ reset = 1;
+ break
+ end
+
+ end
+
+ for r = 1:3
+ disp( space(r,1) + " | " + space(r,2) + " | " +space(r,3) )
+ disp(' | |')
+ disp( '___________________')
+ end
+
+ % Make sure previous positions are loocked
+ if changes == 1
+ switch marker
+ case "X"
+ marker = "O";
+ case "O"
+ marker = "X";
+ changes = 0;
+ end
+ end
+end
+
diff --git a/algorithms/sorting/bubble_sort.m b/algorithms/sorting/bubble_sort.m
new file mode 100644
index 0000000..2803141
--- /dev/null
+++ b/algorithms/sorting/bubble_sort.m
@@ -0,0 +1,20 @@
+%% Bubble sort algorithm:
+function list = bubble_sort(list)
+% function to sort vector 'list' with using the 'Bubble sort' algorithm
+% INPUT: 'list' array
+% OUTPUT: sorted array
+changed = true;
+count = numel(list);
+while(changed)
+ changed = false;
+ count = count - 1;
+ for index = (1:count)
+ if(list(index) > list(index+1))
+ list([index index+1]) = list([index+1 index]); %swap
+ changed = true;
+ end
+
+ end
+end
+end
+
diff --git a/algorithms/sorting/cocktail_sort.m b/algorithms/sorting/cocktail_sort.m
new file mode 100644
index 0000000..572a4fe
--- /dev/null
+++ b/algorithms/sorting/cocktail_sort.m
@@ -0,0 +1,30 @@
+function list = cocktailSort(list)
+
+ %since the do-while loop doesn't exist in MATLAB we will perform following steps
+ swapped = true;
+
+ while swapped
+
+ %Bubble sort down the list
+ swapped = false;
+ for i = (1:numel(list)-1)
+ if( list(i) > list(i+1) )
+ list([i i+1]) = list([i+1 i]); %swap
+ swapped = true;
+ end
+ end
+
+ if ~swapped
+ break
+ end
+
+ %Bubble sort up the list
+ swapped = false;
+ for i = (numel(list)-1:-1:1)
+ if( list(i) > list(i+1) )
+ list([i i+1]) = list([i+1 i]); %swap
+ swapped = true;
+ end %if
+ end %for
+ end %while
+end %cocktail sort
diff --git a/algorithms/sorting/comb_sort.m b/algorithms/sorting/comb_sort.m
new file mode 100644
index 0000000..c78330d
--- /dev/null
+++ b/algorithms/sorting/comb_sort.m
@@ -0,0 +1,32 @@
+%This function sorts the input array in ascending order using the Comb Sort algorithm
+%For details, refer https://en.wikipedia.org/wiki/Comb_sort
+
+function y = comb_sort(array)
+
+len = length(array);
+k = len;
+isSwapped = true;
+% value of shrink should be greater than 1
+shrink = 1.4;
+while ((k > 1) || (isSwapped == true))
+ k = max(floor(k / shrink),1);
+ % Bubble sort with given value of k
+ i = 1;
+ isSwapped = false;
+ while ((i + k) <= len)
+ if (array(i) > array(i + k))
+ array = swap(array,i,i + k);
+ isSwapped = true;
+ end
+ i = i + 1;
+ end
+end
+y = array;
+end
+
+function array = swap(array,i,j)
+value = array(i);
+array(i) = array(j);
+array(j) = value;
+% Note: In practice, array should be passed by reference
+end
diff --git a/algorithms/sorting/counting_sort.m b/algorithms/sorting/counting_sort.m
new file mode 100644
index 0000000..ad1428c
--- /dev/null
+++ b/algorithms/sorting/counting_sort.m
@@ -0,0 +1,26 @@
+function ans = counting_sort(arr, k)
+ % countingSort : implements the counting sort algorithm
+ % INPUT: array of integers between 1 and k
+ % OUTPUT: sorted array
+
+ ans = zeros(size(arr)); % result array (sorted array)
+
+
+ C = zeros(1,k); % array for counting
+
+ % counts the occurs of element i
+ for i = 1 : length(arr)
+ C(arr(i)) += 1;
+ endfor
+
+ % adress calculation
+ for j = 2 : k
+ C(j) += C(j-1);
+ endfor
+
+ for m = length(arr) : -1 : 1
+ ans( C( arr(m) ) ) = arr(m);
+ C(arr(m)) -= 1;
+ endfor
+
+endfunction
\ No newline at end of file
diff --git a/algorithms/sorting/gnome_sort.m b/algorithms/sorting/gnome_sort.m
new file mode 100644
index 0000000..d992b71
--- /dev/null
+++ b/algorithms/sorting/gnome_sort.m
@@ -0,0 +1,21 @@
+function list = gnomeSort(list)
+
+ i = 2;
+ j = 3;
+
+ while i <= numel(list)
+
+ if list(i-1) <= list(i)
+ i = j;
+ j = j+1;
+ else
+ list([i-1 i]) = list([i i-1]); %Swaping
+ i = i-1;
+ if i == 1
+ i = j;
+ j = j+1;
+ end
+ end %if
+
+ end %while
+end %gnomeSort
diff --git a/algorithms/sorting/heap_sort.m b/algorithms/sorting/heap_sort.m
new file mode 100644
index 0000000..df52e1e
--- /dev/null
+++ b/algorithms/sorting/heap_sort.m
@@ -0,0 +1,40 @@
+function list = heapSort(list)
+
+ function list = siftDown(list,root,theEnd)
+ while (root * 2) <= theEnd
+
+ child = root * 2;
+ if (child + 1 <= theEnd) && (list(child) < list(child+1))
+ child = child + 1;
+ end
+
+ if list(root) < list(child)
+ list([root child]) = list([child root]); %Swap
+ root = child;
+ else
+ return
+ end
+
+ end %while
+ end %siftDown
+
+ count = numel(list);
+
+ %Because heapify is called once in pseudo-code, it is inline here
+ start = floor(count/2);
+
+ while start >= 1
+ list = siftDown(list, start, count);
+ start = start - 1;
+ end
+ %End Heapify
+
+ while count > 1
+
+ list([count 1]) = list([1 count]); %Swap
+ count = count - 1;
+ list = siftDown(list,1,count);
+
+ end
+
+end
diff --git a/algorithms/sorting/insertion_sort.m b/algorithms/sorting/insertion_sort.m
new file mode 100644
index 0000000..16b4aca
--- /dev/null
+++ b/algorithms/sorting/insertion_sort.m
@@ -0,0 +1,27 @@
+%A MATLAB/Octave implementation of the insertion sort algorithm.
+%The basic premise is that the program checks whether two neighbouring elements
+%in an array are in order and sorts them. It does length(array) number of
+% passes. For further details and pseudocode, refer to
+%https://en.wikipedia.org/wiki/Insertion_sort
+%Note that this function differs slightly from the pseudocode because of
+%how MATLAB/Octave arrays start at index 1.
+%Note: this function is for educational purposes only.
+%You will want to use the built-in sort function for actual coding,
+%as it is much more efficent.
+function y = insertion_sort(array)
+ i = 1;
+ %Assigning the length to a variable should make the program slightly faster.
+ len = length(array);
+ while i < len + 1
+ j = i;
+ while j > 1 && array(j - 1) > array(j)
+ %Swapping array(j - 1) and array(j)
+ temp = array(j - 1);
+ array(j - 1) = array(j);
+ array(j) = temp;
+ j = j - 1;
+ endwhile
+ i = i + 1;
+ endwhile
+ y = array;
+endfunction
diff --git a/algorithms/sorting/merge_sort.m b/algorithms/sorting/merge_sort.m
new file mode 100644
index 0000000..2a4cb3c
--- /dev/null
+++ b/algorithms/sorting/merge_sort.m
@@ -0,0 +1,36 @@
+%% Merge sorting Algorithm:
+function y = merge_sort(x)
+% function to sort vector 'x' with using the merge sort algorithm
+% INPUT: 'x' array
+% OUTPUT: sorted array
+n = length(x);
+if n==1
+ y = x;
+else
+ m = floor(n/2);
+ left = merge_sort(x(1:m)) % sorting left part of vector
+ right = merge_sort(x(m+1:n)) % sorting right part of vector
+ y = merge(left,right) % with using 'merge' function, 2 part will be merged
+end
+
+%% Merge Algorithm:
+function z = merge(x,y)
+n = length(x); m = length(y); z = zeros(1,n+m);
+ix = 1;
+iy = 1;
+for iz=1:(n+m)
+ % Deteremin the iz-th value for the merged array.
+ if ix > n
+ % All done with x-values. Select the next y-value.
+ z(iz) = y(iy); iy = iy+1;
+ elseif iy > m
+ % All done with y-values. Select the next x-value.
+ z(iz) = x(ix); ix = ix + 1;
+ elseif x(ix) <= y(iy)
+ % The next x-value is less than or equal to the next y-value
+ z(iz) = x(ix); ix = ix + 1;
+ else
+ % The next y-value is less than the next x-value
+ z(iz) = y(iy); iy = iy + 1;
+ end
+end
diff --git a/algorithms/sorting/permutationSort.m b/algorithms/sorting/permutationSort.m
new file mode 100644
index 0000000..93531fa
--- /dev/null
+++ b/algorithms/sorting/permutationSort.m
@@ -0,0 +1,13 @@
+function list = permutationSort(list)
+
+ permutations = perms(1:numel(list)); %Generate all permutations of the item indicies
+
+ %Test every permutation of the indicies of the original list
+ for i = (1:size(permutations,1))
+ if issorted( list(permutations(i,:)) )
+ list = list(permutations(i,:));
+ return %Once the correct permutation of the original list is found break out of the program
+ end
+ end
+
+end
diff --git a/algorithms/sorting/quick_sort.m b/algorithms/sorting/quick_sort.m
new file mode 100644
index 0000000..010a383
--- /dev/null
+++ b/algorithms/sorting/quick_sort.m
@@ -0,0 +1,21 @@
+function sortedArray = quick_sort(array)
+
+ if numel(array) <= 1 %If the array has 1 element then it can't be sorted
+ sortedArray = array;
+ return
+ end
+
+ pivot = array(end);
+ array(end) = [];
+
+ %Create two new arrays which contain the elements that are less than or
+ %equal to the pivot called "less" and greater than the pivot called
+ %"greater"
+ less = array( array <= pivot );
+ greater = array( array > pivot );
+
+ %The sorted array is the concatenation of the sorted "less" array, the
+ %pivot and the sorted "greater" array in that order
+ sortedArray = [quick_sort(less) pivot quick_sort(greater)];
+
+end
\ No newline at end of file
diff --git a/algorithms/sorting/select_sort.m b/algorithms/sorting/select_sort.m
new file mode 100644
index 0000000..cbba08f
--- /dev/null
+++ b/algorithms/sorting/select_sort.m
@@ -0,0 +1,14 @@
+%% Octave implementation for selection sort
+function arrayToSort = select_sort(arrayToSort)
+ for i=1:length(arrayToSort)
+%%smallest element in the unsorted list
+ minimum_index=i;
+ for j=i+1:length(arrayToSort)
+ if (arrayToSort(j) < arrayToSort(minimum_index))
+ minimum_index=j;
+ endif
+ endfor
+%%replace the element with the minimum value of the unsorted array
+ arrayToSort([i minimum_index]) = arrayToSort([minimum_index i]);
+ endfor
+endfunction
\ No newline at end of file
diff --git a/algorithms/sorting/shell_sort.m b/algorithms/sorting/shell_sort.m
new file mode 100644
index 0000000..c588cb1
--- /dev/null
+++ b/algorithms/sorting/shell_sort.m
@@ -0,0 +1,26 @@
+function list = shellSort(list)
+
+ N = numel(list);
+ increment = round(N/2);
+
+ while increment > 0 %loop until increment becomes 0
+
+ for i = (increment+1:N)
+ temp = list(i);
+ j = i;
+ while (j >= increment+1) && (list(j-increment) > temp)
+ list(j) = list(j-increment);
+ j = j - increment;
+ end
+
+ list(j) = temp;
+
+ end %for
+
+ if increment == 2 %This case causes shell sort to become insertion sort
+ increment = 1;
+ else
+ increment = round(increment/2.2);
+ end
+ end %while
+end %shellSort
diff --git a/image-processing/Blob-detection-using-Matlab/BlobUsingVideo.m b/image-processing/Blob-detection-using-Matlab/BlobUsingVideo.m
new file mode 100644
index 0000000..c0464e5
--- /dev/null
+++ b/image-processing/Blob-detection-using-Matlab/BlobUsingVideo.m
@@ -0,0 +1,75 @@
+%% read the frame
+
+cap = vision.VideoFileReader('multiple_ball.avi');
+cap.VideoOutputDataType = 'double';
+
+%% reduce noise by using opening
+
+noise = strel('disk',3);
+
+%% blob analysis
+
+% to perform a blob analysis on the video frame we need to use step
+% function :- parameter => (blob analysis system object , input image i.e open)
+% function output 3 :- area , centroid , bounding box
+
+blob = vision.BlobAnalysis('MinimumBlobArea',200,...
+ 'MaximumBlobArea',5000);
+
+% Create VideoPlayer
+vidPlayer = vision.DeployableVideoPlayer;
+
+%% while True
+while ~isDone(cap)
+
+ % Read Frame
+ frame = step(cap);
+
+ % Convert RGB image to HSV
+ hsv = rgb2hsv(frame);
+
+ % Define thresholds for channel 1 based on histogram settings
+ channel1Min = 0.398;
+ channel1Max = 0.498;
+
+ % Define thresholds for channel 2 based on histogram settings
+ channel2Min = 0.355;
+ channel2Max = 1.000;
+
+ % Define thresholds for channel 3 based on histogram settings
+ channel3Min = 0.000;
+ channel3Max = 1.000;
+
+ % Create mask based on chosen histogram thresholds
+ Ibw = (hsv(:,:,1) >= channel1Min ) & (hsv(:,:,1) <= channel1Max) & ...
+ (hsv(:,:,2) >= channel2Min ) & (hsv(:,:,2) <= channel2Max) & ...
+ (hsv(:,:,3) >= channel3Min ) & (hsv(:,:,3) <= channel3Max);
+
+ % Use morphological operations to remove disturbances
+ opening = imopen(Ibw,noise);
+
+ % Extract the blobs from the frame
+ [object_area,object_centroid,bounding_box] = step(blob, opening);
+
+ % Draw a box around the detected objects
+ Ishape = insertShape(frame,'Rectangle',bounding_box);
+
+ % Insert a string of number of objects detected in the video frame.
+
+ numObj = length(object_area);
+
+ %Itext = step(hTextIns,Ishape,int32(numObj));
+
+ %Play in the video player
+ %step(vidPlayer, Itext);
+ step(vidPlayer, Ishape);
+
+
+end
+
+%% Clean
+
+release(cap)
+release(blob)
+%release(hTextIns)
+release(vidPlayer)
\ No newline at end of file
diff --git a/image-processing/Blob-detection-using-Matlab/Media2.gif b/image-processing/Blob-detection-using-Matlab/Media2.gif
new file mode 100644
index 0000000..e7529d3
Binary files /dev/null and b/image-processing/Blob-detection-using-Matlab/Media2.gif differ
diff --git a/image-processing/Blob-detection-using-Matlab/README.md b/image-processing/Blob-detection-using-Matlab/README.md
new file mode 100644
index 0000000..d89c12b
--- /dev/null
+++ b/image-processing/Blob-detection-using-Matlab/README.md
@@ -0,0 +1,89 @@
+## Blob detection and analysis using Matlab
+A Blob is a group of connected pixels in an image that share some common property ( E.g grayscale value ).
+
+### Steps includes for blob analysis on image
+
+ > ### Load sample frames
+
+ ```matlab
+
+ load sampleFrames.mat
+ subplot(1,3,1)
+ imshow(vidFrame1)
+ ```
+ > ### Threshold image
+ ```matlab
+ I = rgb2hsv(vidFrame1);
+
+ % Define thresholds for channel 1 based on histogram settings
+ channel1Min = 0.333;
+ channel1Max = 0.561;
+
+ % Define thresholds for channel 2 based on histogram settings
+ channel2Min = 0.327;
+ channel2Max = 1.000;
+
+ % Define thresholds for channel 3 based on histogram settings
+ channel3Min = 0.186;
+ channel3Max = 1.000;
+
+ % Create mask based on chosen histogram thresholds
+ sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
+ (I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
+ (I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
+ BW = sliderBW;
+
+ subplot(1,3,2)
+ imshow(BW)
+
+
+ ```
+ > ### Remove disturbances
+ ```matlab
+
+ noise = strel('disk' , 3);
+
+ open = imopen(BW, noise);
+ subplot(1,3,3);
+ imshow(open);
+
+ ```
+ > ### Blob Analysis
+
+ ```matlab
+ blob = vision.BlobAnalysis('MinimumBlobArea',200,...
+ 'MaximumBlobArea',5000);
+ % to perform a blob analysis on the video frame we need to use step
+ % function :- parameter => (blob analysis system object , input image i.e open)
+ % function output 3 :- area , centroid , bounding box
+
+ [objectArea , objCentroid , bboxout] = step(blob , open);
+
+
+ ```
+ > ### Annotate image
+ ```matlab
+
+ % now we get a bounding box cordinates of detected ball let apply contour
+ % over the detected ball using rectangle
+
+ rectangle = insertShape(vidFrame1 , 'rectangle',bboxout , 'Linewidth' , 4 , 'Color',...
+ [155 164 155]);
+
+ figure
+ subplot(1,2,1)
+ imshow(rectangle)
+
+
+ ```
+ > ### Clean up
+
+ ```matlab
+ release(blob)
+
+ ```
+
+### Result
+
+
+
diff --git a/image-processing/Blob-detection-using-Matlab/assets/Media2.mp4 b/image-processing/Blob-detection-using-Matlab/assets/Media2.mp4
new file mode 100644
index 0000000..d3ff961
Binary files /dev/null and b/image-processing/Blob-detection-using-Matlab/assets/Media2.mp4 differ
diff --git a/image-processing/Blob-detection-using-Matlab/assets/Screenshot (376).png b/image-processing/Blob-detection-using-Matlab/assets/Screenshot (376).png
new file mode 100644
index 0000000..2184efb
Binary files /dev/null and b/image-processing/Blob-detection-using-Matlab/assets/Screenshot (376).png differ
diff --git a/image-processing/Blob-detection-using-Matlab/assets/Screenshot (378).png b/image-processing/Blob-detection-using-Matlab/assets/Screenshot (378).png
new file mode 100644
index 0000000..d331495
Binary files /dev/null and b/image-processing/Blob-detection-using-Matlab/assets/Screenshot (378).png differ
diff --git a/image-processing/Blob-detection-using-Matlab/assets/Screenshot (379).png b/image-processing/Blob-detection-using-Matlab/assets/Screenshot (379).png
new file mode 100644
index 0000000..781ffda
Binary files /dev/null and b/image-processing/Blob-detection-using-Matlab/assets/Screenshot (379).png differ
diff --git a/image-processing/Blob-detection-using-Matlab/assets/Screenshot (380).png b/image-processing/Blob-detection-using-Matlab/assets/Screenshot (380).png
new file mode 100644
index 0000000..a981c0b
Binary files /dev/null and b/image-processing/Blob-detection-using-Matlab/assets/Screenshot (380).png differ
diff --git a/image-processing/Blob-detection-using-Matlab/assets/Screenshot (381).png b/image-processing/Blob-detection-using-Matlab/assets/Screenshot (381).png
new file mode 100644
index 0000000..28a74a3
Binary files /dev/null and b/image-processing/Blob-detection-using-Matlab/assets/Screenshot (381).png differ
diff --git a/image-processing/Blob-detection-using-Matlab/assets/Screenshot (382).png b/image-processing/Blob-detection-using-Matlab/assets/Screenshot (382).png
new file mode 100644
index 0000000..f093bb9
Binary files /dev/null and b/image-processing/Blob-detection-using-Matlab/assets/Screenshot (382).png differ
diff --git a/image-processing/Blob-detection-using-Matlab/assets/buoyRun.avi b/image-processing/Blob-detection-using-Matlab/assets/buoyRun.avi
new file mode 100644
index 0000000..408ad59
Binary files /dev/null and b/image-processing/Blob-detection-using-Matlab/assets/buoyRun.avi differ
diff --git a/image-processing/Blob-detection-using-Matlab/assets/multiple_ball.avi b/image-processing/Blob-detection-using-Matlab/assets/multiple_ball.avi
new file mode 100644
index 0000000..becc307
Binary files /dev/null and b/image-processing/Blob-detection-using-Matlab/assets/multiple_ball.avi differ
diff --git a/image-processing/Blob-detection-using-Matlab/assets/multiple_ball.mp4 b/image-processing/Blob-detection-using-Matlab/assets/multiple_ball.mp4
new file mode 100644
index 0000000..b38bdda
Binary files /dev/null and b/image-processing/Blob-detection-using-Matlab/assets/multiple_ball.mp4 differ
diff --git a/image-processing/Blob-detection-using-Matlab/assets/sampleFrames.mat b/image-processing/Blob-detection-using-Matlab/assets/sampleFrames.mat
new file mode 100644
index 0000000..b247c7b
Binary files /dev/null and b/image-processing/Blob-detection-using-Matlab/assets/sampleFrames.mat differ
diff --git a/image-processing/Blob-detection-using-Matlab/blob.slx b/image-processing/Blob-detection-using-Matlab/blob.slx
new file mode 100644
index 0000000..ba6be01
Binary files /dev/null and b/image-processing/Blob-detection-using-Matlab/blob.slx differ
diff --git a/image-processing/Blob-detection-using-Matlab/blobDetection.m b/image-processing/Blob-detection-using-Matlab/blobDetection.m
new file mode 100644
index 0000000..b5b8a3c
--- /dev/null
+++ b/image-processing/Blob-detection-using-Matlab/blobDetection.m
@@ -0,0 +1,57 @@
+% Copyright 2014-2015 The MathWorks, Inc.
+%% Load sample frames
+load sampleFrames.mat
+subplot(1,3,1)
+imshow(vidFrame1)
+
+%% Threshold image
+% Convert RGB image to chosen color space
+I = rgb2hsv(vidFrame1);
+
+% Define thresholds for channel 1 based on histogram settings
+channel1Min = 0.379;
+channel1Max = 0.496;
+
+% Define thresholds for channel 2 based on histogram settings
+channel2Min = 0.436;
+channel2Max = 1.000;
+
+% Define thresholds for channel 3 based on histogram settings
+channel3Min = 0.000;
+channel3Max = 1.000;
+
+% Create mask based on chosen histogram thresholds
+BW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
+ (I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
+ (I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
+
+subplot(1,3,2)
+imshow(BW)
+
+%% Remove disturbances
+diskElem = strel('disk',3);
+Ibwopen = imopen(BW,diskElem);
+subplot(1,3,3)
+imshow(Ibwopen)
+
+%% Blob Analysis
+hBlobAnalysis = vision.BlobAnalysis('MinimumBlobArea',200,...
+ 'MaximumBlobArea',5000);
+[objArea,objCentroid,bboxOut] = step(hBlobAnalysis,Ibwopen);
+
+%% Annotate image
+Ishape = insertShape(vidFrame1,'rectangle',bboxOut,'Linewidth',4);
+figure
+subplot(1,2,1)
+imshow(Ishape)
+
+numObj = numel(objArea);
+hTextIns = vision.TextInserter('%d','Location',[20 20],'Color',...
+ [255 255 0],'FontSize',30);
+Itext = step(hTextIns,Ishape,int32(numObj));
+subplot(1,2,2)
+imshow(Itext)
+
+%% Clean up
+release(hBlobAnalysis)
+release(hTextIns)
\ No newline at end of file
diff --git a/matlab_for_beginners/README.md b/matlab_for_beginners/README.md
new file mode 100644
index 0000000..b2265a2
--- /dev/null
+++ b/matlab_for_beginners/README.md
@@ -0,0 +1,10 @@
+
+
+The best way to learn matlab programming is to go through the basics problems along with the code.
+It allows us to understand the matlab language in a better way.
+
+This, matlab_for_beginners tutorial is divided into different parts. Just go one by one through each part.
+After completion of all parts you will have good basic knowledge of matlab.
+
+All The Best.
+
diff --git a/matlab_for_beginners/matlab_introduction.md b/matlab_for_beginners/matlab_introduction.md
new file mode 100644
index 0000000..edabd9f
--- /dev/null
+++ b/matlab_for_beginners/matlab_introduction.md
@@ -0,0 +1,45 @@
+author - Puneet Prakash Arya
+email - puneetarya66@gmail.com
+github - https://github.com/puneet-pr-arya
+
+
+
+
+"MATLAB" is a programming platform designed specifically for engineers and scientists.
+The heart of MATLAB is the MATLAB language, a matrix-based language allowing the most natural expression of computational mathematics.
+
+
+What can you do with MATLAB?
+
+Using MATLAB, you can:
+
+Analyze data
+Develop algorithms
+Create models and applications
+
+
+Matlab Advantages
+
+ (.) Implement and test your algorithms easily
+ (.) Develop the computational codes easily
+ (.) Debug easily
+ (.) Use a large database of built in algorithms
+ (.) Process still images and create simulation videos easily
+ (.) Symbolic computation can be easily done
+ (.) Call external libraries
+ (.) Perform extensive data analysis and visualization
+ (.) Develop application with graphics user interface
+
+
+Who uses MATLAB?
+
+Millions of engineers and scientists in industry and academia use MATLAB.
+You can use MATLAB for a range of applications, including deep learning and machine learning,
+signal processing and communications, image and video processing, control systems, test and measurement,
+computational finance, and computational biology.
+
+
+With these tutorials, i would like to give all of you a basic idea of matlab so that all of you got familiar with the platform
+and can work on it in future.
+
+Thank you and all the best.
\ No newline at end of file
diff --git a/matlab_for_beginners/part_1(learn_basic_programing)/README.md b/matlab_for_beginners/part_1(learn_basic_programing)/README.md
new file mode 100644
index 0000000..a9fabf9
--- /dev/null
+++ b/matlab_for_beginners/part_1(learn_basic_programing)/README.md
@@ -0,0 +1,21 @@
+
+
+This part-1 contains basics programs of matlab to make you familiar with the language.
+For better understanding the basics of the matlab programming,
+please go through the programs according the following
+sequence. Details of each the programs is given alongside:--
+
+1- add.m ( addition of numbers)
+2- equal.m ( The meaning of "a = b" )
+3- math.m ( Basic math operations )
+4- equal_add.m ( The meaning of "a = b", continued )
+5- print.m ( Formatted output )
+6- formatted_output.m ( Formatted output continued )
+7- array.m ( Simple addition of array )
+8- individual_eL_add.m ( Extracting an individual element of an array )
+9- comment.m ( The use of comment)
+10- continuation.m ( Continuation to next line )
+11- intr_math_fun.m ( Intrinsic math functions and constants )
+12- nam_var.m ( Naming a variable )
+13- Plot a graph ( for making a quick plot)
+
diff --git a/matlab_for_beginners/part_1(learn_basic_programing)/add.m b/matlab_for_beginners/part_1(learn_basic_programing)/add.m
new file mode 100644
index 0000000..f1d58d0
--- /dev/null
+++ b/matlab_for_beginners/part_1(learn_basic_programing)/add.m
@@ -0,0 +1,5 @@
+%%Addition
+a = 3;
+b = 5;
+c = a+b
+%%Output:8
diff --git a/matlab_for_beginners/part_1(learn_basic_programing)/array.m b/matlab_for_beginners/part_1(learn_basic_programing)/array.m
new file mode 100644
index 0000000..a09a1bc
--- /dev/null
+++ b/matlab_for_beginners/part_1(learn_basic_programing)/array.m
@@ -0,0 +1,9 @@
+%%Ex. 7 Arrays
+
+
+a = [3 6 7];
+b = [1 9 4];
+c = a + b
+
+
+%Output: 4 15 11
\ No newline at end of file
diff --git a/matlab_for_beginners/part_1(learn_basic_programing)/comment.m b/matlab_for_beginners/part_1(learn_basic_programing)/comment.m
new file mode 100644
index 0000000..caeb671
--- /dev/null
+++ b/matlab_for_beginners/part_1(learn_basic_programing)/comment.m
@@ -0,0 +1,15 @@
+%%Ex. 9 Comment
+%
+% This program demonstrates how to "comment out"
+% a segment of code
+
+A = 3;
+B = A*A;
+%
+% B = 2*B <--- This statement is not executed
+%
+C = A+B
+
+
+
+%Output: c = 12
\ No newline at end of file
diff --git a/matlab_for_beginners/part_1(learn_basic_programing)/continuation.m b/matlab_for_beginners/part_1(learn_basic_programing)/continuation.m
new file mode 100644
index 0000000..90d38d9
--- /dev/null
+++ b/matlab_for_beginners/part_1(learn_basic_programing)/continuation.m
@@ -0,0 +1,7 @@
+%%Ex. 10 Continuation to next line
+summation1 = 1 + 3 + 5 + 7 ...
+ + 9 + 11
+
+
+%Note: The three periods (...) allow continuation to the next line of commands. The two
+% lines in the above example are essentially one line of "summation1 = 1+3+5+7+9+11".
\ No newline at end of file
diff --git a/matlab_for_beginners/part_1(learn_basic_programing)/equal.m b/matlab_for_beginners/part_1(learn_basic_programing)/equal.m
new file mode 100644
index 0000000..d61f3b0
--- /dev/null
+++ b/matlab_for_beginners/part_1(learn_basic_programing)/equal.m
@@ -0,0 +1,11 @@
+%%Ex. 2 The meaning of "a = b"
+
+
+%In Matlab and in any programming language, the statement "a = b" does not mean
+%"a equals b". Instead, it prompts the action of replacing the content of a by the
+%content of b.
+a = 3;
+b = a;
+b
+
+%Output:3
diff --git a/matlab_for_beginners/part_1(learn_basic_programing)/equal_add.m b/matlab_for_beginners/part_1(learn_basic_programing)/equal_add.m
new file mode 100644
index 0000000..7dbf39f
--- /dev/null
+++ b/matlab_for_beginners/part_1(learn_basic_programing)/equal_add.m
@@ -0,0 +1,7 @@
+%%Ex. 4 The meaning of "a = b", continued
+a = 3;
+a = a+1;
+a
+
+%Output:4
+
diff --git a/matlab_for_beginners/part_1(learn_basic_programing)/formatted_output.m b/matlab_for_beginners/part_1(learn_basic_programing)/formatted_output.m
new file mode 100644
index 0000000..26c34a6
--- /dev/null
+++ b/matlab_for_beginners/part_1(learn_basic_programing)/formatted_output.m
@@ -0,0 +1,13 @@
+%%Ex. 6 Formatted output
+a = 3;
+b = a*a;
+c = a*a*a;
+d = sqrt(a);
+fprintf('%4u square equals %4u \r', a, b)
+fprintf('%4u cube equals %4u \r', a, c)
+fprintf('The square root of %2u is %6.4f \r', a, d)
+
+
+%Output: 3 square equals 9
+ % 3 cube equals 27
+ % The square root of 3 is 1.7321
\ No newline at end of file
diff --git a/matlab_for_beginners/part_1(learn_basic_programing)/individual_eL_add.m b/matlab_for_beginners/part_1(learn_basic_programing)/individual_eL_add.m
new file mode 100644
index 0000000..c5f4b86
--- /dev/null
+++ b/matlab_for_beginners/part_1(learn_basic_programing)/individual_eL_add.m
@@ -0,0 +1,9 @@
+%%Ex. 8 Extracting an individual element of an array
+
+
+a = [3 6 7];
+b = [1 9 4 5];
+c = a(2) + b(4)
+
+
+%Output: c = 11
\ No newline at end of file
diff --git a/matlab_for_beginners/part_1(learn_basic_programing)/intr_math_fun.m b/matlab_for_beginners/part_1(learn_basic_programing)/intr_math_fun.m
new file mode 100644
index 0000000..fc29b96
--- /dev/null
+++ b/matlab_for_beginners/part_1(learn_basic_programing)/intr_math_fun.m
@@ -0,0 +1,9 @@
+%%Ex. 11 Intrinsic math functions and constants
+x = pi;
+y = sin(pi/2)
+z = exp(-sin(pi/2))
+
+
+%Output:
+ % y = 1
+ % z = 0.3679
\ No newline at end of file
diff --git a/matlab_for_beginners/part_1(learn_basic_programing)/make_graph.m b/matlab_for_beginners/part_1(learn_basic_programing)/make_graph.m
new file mode 100644
index 0000000..ef26300
--- /dev/null
+++ b/matlab_for_beginners/part_1(learn_basic_programing)/make_graph.m
@@ -0,0 +1,17 @@
+%% Ex. 13 Making a quick plot
+x = [0:0.1:20];
+y = sin(x);
+plot(x,y)
+
+
+
+
+% remaks : Remarks: This only serves as a very quick example of what Matlab can do in making
+% plots.The first line is equivalent to x = [0 0.1 0.2 0.3 ... 19.8 19.9 20]. It
+% assigns the content of x which is an array of 201 elements. The "0:0.1:20" means the
+% 201 numbers are evenly spaced. They start from 0 and end at 20 with an increment of
+% 0.1. The second line gives the content of the new array, y, as
+ % y = [sin(x(1)) sin(x(2)) sin(x(3)) ... sin(x(200)) sin(x(201))] ,
+% or
+% y = [sin(0) sin(0.1) sin(0.2) ... sin(19.9) sin(20)] .
+% The 3rd line makes a plot of y vs. x.
\ No newline at end of file
diff --git a/matlab_for_beginners/part_1(learn_basic_programing)/math.m b/matlab_for_beginners/part_1(learn_basic_programing)/math.m
new file mode 100644
index 0000000..fcedfc7
--- /dev/null
+++ b/matlab_for_beginners/part_1(learn_basic_programing)/math.m
@@ -0,0 +1,7 @@
+%%Ex. 3 Basic math operations
+
+a = 3;
+b = 9;
+c = 2*a+b^2-a*b+b/a-10
+
+%Output:53
diff --git a/matlab_for_beginners/part_1(learn_basic_programing)/nam_var.m b/matlab_for_beginners/part_1(learn_basic_programing)/nam_var.m
new file mode 100644
index 0000000..9fc47c5
--- /dev/null
+++ b/matlab_for_beginners/part_1(learn_basic_programing)/nam_var.m
@@ -0,0 +1,9 @@
+%%Ex. 12 "Clear" a variable
+
+%Naming a variable
+
+%(i) Matlab variables are case sensitive. For example, "ASU" and "asu" are two different
+%variables. (ii) An underscore (_) or a number (0-9) can also be part of the name of a
+%variable. For example, "MAE_384" is a legitimate variable name. (iii) Some names are
+%reserved for special constants. For example (see Ex. 11), "pi" is an intrinsic constant
+%with a fixed value of 3.14159...
\ No newline at end of file
diff --git a/matlab_for_beginners/part_1(learn_basic_programing)/print.m b/matlab_for_beginners/part_1(learn_basic_programing)/print.m
new file mode 100644
index 0000000..bda8cbe
--- /dev/null
+++ b/matlab_for_beginners/part_1(learn_basic_programing)/print.m
@@ -0,0 +1,4 @@
+%%Ex. 5 Formatted output
+
+fprintf('Hello')
+%Output:Hello
diff --git a/matlab_for_beginners/part_2(basic_looping)/README.md b/matlab_for_beginners/part_2(basic_looping)/README.md
new file mode 100644
index 0000000..100b9ac
--- /dev/null
+++ b/matlab_for_beginners/part_2(basic_looping)/README.md
@@ -0,0 +1,26 @@
+
+
+This part-2 introduces the concept of loops in the matlab language.
+
+For understanding the concept of looping just go through the programs one by one.
+ After that u will be able to apply the loops.
+
+1 - program1 - ( Loop: Using for command )
+
+2- program2 - ( For loop: Utility of the dummy index )
+
+
+3 - program3 - ( For loop: More on the dummy index)
+
+4 - program4 - (Treatment of array within a loop)
+
+5 - program5 - ( Double loop )
+
+
+6 - program6 - ( another double lopp )
+
+
+7- program7 - ( More complicated use of loop and index )
+
+
+8- wh_loop - ( while loop )
\ No newline at end of file
diff --git a/matlab_for_beginners/part_2(basic_looping)/program1.m b/matlab_for_beginners/part_2(basic_looping)/program1.m
new file mode 100644
index 0000000..bc3db0f
--- /dev/null
+++ b/matlab_for_beginners/part_2(basic_looping)/program1.m
@@ -0,0 +1,18 @@
+%% The for loop
+%Ex. 1 Loop: Using for command
+b = 3;
+for k = 1:5
+ b
+end
+
+
+%Output:
+% 3
+% 3
+% 3
+% 3
+% 3
+
+%Remark: The blue-colored segment in lines 2-4 forms a "for-loop". The statement
+% sandwiched between "for k = 1:5" and "end" is repeated 5 times, with the "k" index
+% going from 1 to 5 step 1
\ No newline at end of file
diff --git a/matlab_for_beginners/part_2(basic_looping)/program2.m b/matlab_for_beginners/part_2(basic_looping)/program2.m
new file mode 100644
index 0000000..0bc9277
--- /dev/null
+++ b/matlab_for_beginners/part_2(basic_looping)/program2.m
@@ -0,0 +1,15 @@
+%% Ex. 2 For loop: Utility of the dummy index
+
+b = 3;
+for k = 1:5
+ b^k
+end
+%Output:
+% 3
+% 9
+% 27
+% 81
+% 243
+
+%Remark: The outputs are 3^1, 3^2, 3^3, 3^4, and 3^5. the value of "k" keeps changing as
+% we go through the loop
\ No newline at end of file
diff --git a/matlab_for_beginners/part_2(basic_looping)/program3.m b/matlab_for_beginners/part_2(basic_looping)/program3.m
new file mode 100644
index 0000000..5926930
--- /dev/null
+++ b/matlab_for_beginners/part_2(basic_looping)/program3.m
@@ -0,0 +1,10 @@
+%% Ex.3 For loop: More on the dummy index
+
+sum1 = 0;
+for k = 1:9
+ sum1 = sum1+k;
+end
+sum1
+%Output:
+% 45
+% Remark: this program performs the summation of 1+2+3+4+5+6+7+8+9 (= 45).
\ No newline at end of file
diff --git a/matlab_for_beginners/part_2(basic_looping)/program4.m b/matlab_for_beginners/part_2(basic_looping)/program4.m
new file mode 100644
index 0000000..ce6198c
--- /dev/null
+++ b/matlab_for_beginners/part_2(basic_looping)/program4.m
@@ -0,0 +1,16 @@
+%% Ex.4 Treatment of array within a loop
+
+
+b = [3 8 9 4 7 5];
+sum1 = 0;
+for k = 1:4
+ sum1 = sum1+b(k);
+end
+sum1
+
+
+%Output:
+ % 24
+
+ % Remark: This program performs the summation of sum1 = b(1)+b(2)+b(3)+b(4) =
+% 3+8+9+4 = 24
\ No newline at end of file
diff --git a/matlab_for_beginners/part_2(basic_looping)/program5.m b/matlab_for_beginners/part_2(basic_looping)/program5.m
new file mode 100644
index 0000000..809cf3b
--- /dev/null
+++ b/matlab_for_beginners/part_2(basic_looping)/program5.m
@@ -0,0 +1,15 @@
+%% Ex. 5 Double loop
+
+sum1 = 0;
+for n = 1:2
+ for m = 1:3
+ sum1 = sum1+n*m;
+ end
+end
+sum1
+
+
+%Output:
+ 18
+% Remark: this program performs the summation of
+% Sum1 = 1*1+1*2+1*3 +2*1+2*2+2*3 = 18
\ No newline at end of file
diff --git a/matlab_for_beginners/part_2(basic_looping)/program6.m b/matlab_for_beginners/part_2(basic_looping)/program6.m
new file mode 100644
index 0000000..19f40ff
--- /dev/null
+++ b/matlab_for_beginners/part_2(basic_looping)/program6.m
@@ -0,0 +1,16 @@
+%% Ex. 6 Double loop
+
+for n = 1:2
+ for m = 1:3
+ fprintf('n = %3u m = %3u \r', n, m)
+ end
+end
+
+
+%Output:
+% n = 1 m = 1
+% n = 1 m = 2
+% n = 1 m = 3
+% n = 2 m = 1
+% n = 2 m = 2
+% n = 2 m = 3
\ No newline at end of file
diff --git a/matlab_for_beginners/part_2(basic_looping)/program7.m b/matlab_for_beginners/part_2(basic_looping)/program7.m
new file mode 100644
index 0000000..6b1986c
--- /dev/null
+++ b/matlab_for_beginners/part_2(basic_looping)/program7.m
@@ -0,0 +1,17 @@
+%% Ex. 7 More complicated use of loop and index
+
+
+b = [2 5 7 4 9 8 3];
+c = [2 3 5 7];
+sum1 = 0;
+for k = 1:4
+ sum1 = sum1+b(c(k));
+end
+sum1
+%Output:
+% 24
+% Remark: This program performs the summation of
+% sum1 = b(c(1))+b(c(2))+b(c(3))+b(c(4))
+% = b(2)+b(3)+b(5)+b(7)
+% = 5+7+9+3
+% = 24
\ No newline at end of file
diff --git a/matlab_for_beginners/part_2(basic_looping)/wh_loop.m b/matlab_for_beginners/part_2(basic_looping)/wh_loop.m
new file mode 100644
index 0000000..c557f60
--- /dev/null
+++ b/matlab_for_beginners/part_2(basic_looping)/wh_loop.m
@@ -0,0 +1,16 @@
+%% The while loop
+
+
+x = 3;
+while (x < 100)
+ x = x*3;
+end
+x
+
+
+% Output:
+% x = 243
+% Remark: One can think of a while loop as a combination of a for loop and an if
+% statement. Here, the looping will keep going indefinitely as long as the condition,
+% (x < 100), is satisfied. Therefore, the value of x progresses from 3, 9, 27, 81, to 243
+% when the loop is terminated.
\ No newline at end of file
diff --git a/matlab_for_beginners/part_3(basic_branching)/README.md b/matlab_for_beginners/part_3(basic_branching)/README.md
new file mode 100644
index 0000000..a4a0e0f
--- /dev/null
+++ b/matlab_for_beginners/part_3(basic_branching)/README.md
@@ -0,0 +1,22 @@
+
+This part-3 makes you familiar with the basic branching concept which basically means using
+loops,if, if else and basics of matlab.
+
+Just go through the programs in the given sequence. All required Information about the question is given in the program itself.
+
+
+1 -program1 - (The if command)
+
+
+2- program2 - (if - elseif - else (This example is self-explanatory. Try to change the given value
+ of num1 and observe the outcome.)
+
+3- program3- (An application - determine whether a given year is a leap year (try to change the
+ given value of nyear and observe the outcome)
+
+
+4- program4- (Combine looping and branching)
+
+
+
+Thank you...
\ No newline at end of file
diff --git a/matlab_for_beginners/part_3(basic_branching)/program1.m b/matlab_for_beginners/part_3(basic_branching)/program1.m
new file mode 100644
index 0000000..6898df0
--- /dev/null
+++ b/matlab_for_beginners/part_3(basic_branching)/program1.m
@@ -0,0 +1,19 @@
+%%Ex. 1 The if command
+
+num1 = 7;
+if (num1 > 5)
+ fprintf('%4u is greater than 5 \r', num1)
+else
+ fprintf('%4u is less than or equal to 5 \r', num1)
+end
+
+
+%Output:
+% 7 is greater than 5
+% Same program, but change first line to "num1 = 3;"
+
+%Output:
+% 3 is less than or equal to 5
+% Remark: In this program, if (num1 > 5) (num1 is greater than 5) is true, the statement
+% "fprintf('%4u is greater than 5 \r', num1)" is executed. Otherwise, the statement
+% "fprintf('%4u is less than or equal to 5 \r', num1)" is executed.
\ No newline at end of file
diff --git a/matlab_for_beginners/part_3(basic_branching)/program2.m b/matlab_for_beginners/part_3(basic_branching)/program2.m
new file mode 100644
index 0000000..324dacc
--- /dev/null
+++ b/matlab_for_beginners/part_3(basic_branching)/program2.m
@@ -0,0 +1,17 @@
+%%Ex 2 if - elseif - else (This example is self-explanatory. Try to change the given value
+% of num1 and observe the outcome.)
+
+
+num1 = 4;
+if (num1 >= 5)
+ fprintf('%4i is greater than or equal to 5 \r', num1)
+elseif (num1 > 1)
+ fprintf('%4i is less than 5 but greater than 1 \r', num1)
+elseif (num1 == 1)
+ fprintf('%4i equals 1 \r', num1)
+elseif (num1 > -3)
+ fprintf('%4i is less than 1 but greater than -3 \r', num1)
+else
+ fprintf('%4i is less than or equal to -3 \r', num1)
+end
+
diff --git a/matlab_for_beginners/part_3(basic_branching)/program3.m b/matlab_for_beginners/part_3(basic_branching)/program3.m
new file mode 100644
index 0000000..30511f0
--- /dev/null
+++ b/matlab_for_beginners/part_3(basic_branching)/program3.m
@@ -0,0 +1,31 @@
+%% Ex 3 An application - determine whether a given year is a leap year (try to change the
+% given value of nyear and observe the outcome)
+
+
+nyear = 1975;
+if (mod(nyear, 400) == 0)
+ fprintf('%6u is a leap year', nyear)
+elseif (mod(nyear,4) == 0) & (mod(nyear,100) ~= 0)
+ fprintf('%6u is a leap year', nyear)
+else
+ fprintf('%6u is not a leap year', nyear)
+end
+
+% Output:
+ % 1975 is not a leap year
+% Remarks:
+% (1) In the elseif command (4th line), "&" means "AND". Both statements
+% "(mod(nyaer,4) == 0)" and "(mod(nyear,100) ~= 0)" have to be true for Matlab to
+% execute the command, "fprintf('%6u is a leap year', nyear)". Also commonly used in an
+% if statement is "|" (a vertical line), which means "OR".
+% (2) The symbols "~=" in line 4 means "NOT EQUAL TO". There are 6 commonly used
+% expressions to compare two numbers in an if command:
+% A > B A is greater than B
+% A < B A is less than B
+% A >= B A is greater than or equal to B
+% A <= B A is less than or equal to B
+% A == B A equals B
+% A ~= B A does not equal B
+%(3) The "mod(A,B)" function returns the remainder of A divided by B. For example,
+% mod(7,2) = 1, mod(10,4) = 2, and mod(25,5) = 0. If A is divisible by B, mod(A,B) = 0.
+% This is a very useful function in many applications related to numerical methods
\ No newline at end of file
diff --git a/matlab_for_beginners/part_3(basic_branching)/program4.m b/matlab_for_beginners/part_3(basic_branching)/program4.m
new file mode 100644
index 0000000..e22eb37
--- /dev/null
+++ b/matlab_for_beginners/part_3(basic_branching)/program4.m
@@ -0,0 +1,19 @@
+%%Ex 4 Combine looping and branching
+
+sum1 = 0;
+sum2 = 0;
+N = 9
+for k = 1:N
+ sum1 = sum1+k;
+ if (mod(k,3) == 0)
+ sum2 = sum2+k;
+ end
+end
+sum1
+sum2
+
+
+% Output:
+% sum1 = 45
+% sum2 = 18
+% Remark: Sum1 = 1+2+3+4+5+6+7+8+9, while sum2 = 3+6+9.
\ No newline at end of file
diff --git a/matlab_for_beginners/part_4(array_nd_matrix)/README.md b/matlab_for_beginners/part_4(array_nd_matrix)/README.md
new file mode 100644
index 0000000..fdf6947
--- /dev/null
+++ b/matlab_for_beginners/part_4(array_nd_matrix)/README.md
@@ -0,0 +1,36 @@
+
+
+
+This part-4 conatains array and matrix related problems.
+
+All the programs are arranged in the order just to give you the proper understanding of the array and matrix.
+
+Just Go through the programs.All the program's name and their work is specified inside the program itself.
+
+
+1 - program1 - ( Assign the content of an array/matrix; Basic operations )
+
+
+2 - program2 - ( Assign the content of a matrix; Addition of two matrices )
+
+3 - program3 - ( Multiplication involving a scalar and an array (or a matrix )
+
+4 - program4 - ( Element-by-element multiplication involving two 1-D arrays or two matrices of the same dimension )
+
+5 - program5 - ( Element-by-element multiplication of two matrices )
+
+6 - program6 - ( Direct (not element-by-element) multiplication of two matrices )
+
+7 - program7 - ( Elementary functions with a vectorial variable )
+
+8 - program8 - ( Another example of elementary functions with a vectorial variable )
+
+9 - program9 - ( An efficient way to assign the content of an array )
+
+10 - program10 - ( Extracting the individual element(s) of a matrix )
+
+11 - program11 - ( Another example for the usage of index for a matrix )
+
+12 - program12 - ( Solving a system of linear equation )
+
+Thank You...
\ No newline at end of file
diff --git a/matlab_for_beginners/part_4(array_nd_matrix)/program1.m b/matlab_for_beginners/part_4(array_nd_matrix)/program1.m
new file mode 100644
index 0000000..ae056c4
--- /dev/null
+++ b/matlab_for_beginners/part_4(array_nd_matrix)/program1.m
@@ -0,0 +1,11 @@
+%% 1. Assign the content of an array/matrix; Basic operations
+
+
+%Ex. 1 Assign the content of a (one-dimensional) array; Addition of two arrays
+
+
+a = [2 12 25];
+b = [3 7 4];
+c = a+b
+% Output:
+ % c = 5 19 29
\ No newline at end of file
diff --git a/matlab_for_beginners/part_4(array_nd_matrix)/program10.m b/matlab_for_beginners/part_4(array_nd_matrix)/program10.m
new file mode 100644
index 0000000..f09d29b
--- /dev/null
+++ b/matlab_for_beginners/part_4(array_nd_matrix)/program10.m
@@ -0,0 +1,10 @@
+%% Ex 10. Extracting the individual element(s) of a matrix
+
+
+A = [3 5; 2 4];
+c = A(2,2)+A(1,2)
+
+%Output:
+% c= 9
+% Remark: With the given A matrix, we have A(1,1) = 3, A(1,2) = 5, A(2,1) = 2, and
+% A(2,2) = 4.
\ No newline at end of file
diff --git a/matlab_for_beginners/part_4(array_nd_matrix)/program11.m b/matlab_for_beginners/part_4(array_nd_matrix)/program11.m
new file mode 100644
index 0000000..2a73fc9
--- /dev/null
+++ b/matlab_for_beginners/part_4(array_nd_matrix)/program11.m
@@ -0,0 +1,16 @@
+%% Ex. 11 Another example for the usage of index for a matrix
+
+
+A = [3 5; 2 4];
+norm1 = 0;
+for m = 1:2
+for n = 1:2
+ norm1 = norm1+A(m,n)^2;
+end
+end
+norm1 = sqrt(norm1)
+
+
+%Output:
+% norm1 = 7.348
+% Remark: This program calculates the Euclidean norm of the A matrix
\ No newline at end of file
diff --git a/matlab_for_beginners/part_4(array_nd_matrix)/program12.m b/matlab_for_beginners/part_4(array_nd_matrix)/program12.m
new file mode 100644
index 0000000..d511457
--- /dev/null
+++ b/matlab_for_beginners/part_4(array_nd_matrix)/program12.m
@@ -0,0 +1,20 @@
+%% Ex. 12 Solving a system of linear equation
+
+
+A = [4 1 2; 0 3 1; 0 1 2];
+b = [17 ; 19 ; 13];
+x = inv(A)*b
+
+
+%Output:
+% x = 1
+% 5
+% 4
+
+
+% An alternative to Ex. 12
+% A = [4 1 2; 0 3 1; 0 1 2];
+% b = [17 ; 19 ; 13];
+% x = A\b
+% The output is the same as Ex. 39. Here, A\b is essentially inv(A)*b. (The "\" is called
+% "back divide" in Matlab documentations.)
\ No newline at end of file
diff --git a/matlab_for_beginners/part_4(array_nd_matrix)/program2.m b/matlab_for_beginners/part_4(array_nd_matrix)/program2.m
new file mode 100644
index 0000000..bbfc477
--- /dev/null
+++ b/matlab_for_beginners/part_4(array_nd_matrix)/program2.m
@@ -0,0 +1,11 @@
+%% Ex. 2 Assign the content of a matrix; Addition of two matrices
+
+a = [3 4; 1 6];
+b = [5 2; 11 7];
+c = a+b
+
+%Output:
+% c = 8 6
+% 12 13
+
+
diff --git a/matlab_for_beginners/part_4(array_nd_matrix)/program3.m b/matlab_for_beginners/part_4(array_nd_matrix)/program3.m
new file mode 100644
index 0000000..d17b2e1
--- /dev/null
+++ b/matlab_for_beginners/part_4(array_nd_matrix)/program3.m
@@ -0,0 +1,9 @@
+%% Ex. 3 Multiplication involving a scalar and an array (or a matrix)
+
+a = [3 5; 1 4];
+b = 2*a
+
+
+%Output:
+% b = 6 10
+% 2 8
\ No newline at end of file
diff --git a/matlab_for_beginners/part_4(array_nd_matrix)/program4.m b/matlab_for_beginners/part_4(array_nd_matrix)/program4.m
new file mode 100644
index 0000000..962ab68
--- /dev/null
+++ b/matlab_for_beginners/part_4(array_nd_matrix)/program4.m
@@ -0,0 +1,15 @@
+%% Ex.4 Element-by-element multiplication involving two 1-D arrays or two matrices of the same dimension
+
+
+a = [2 3 5];
+b = [2 4 9];
+c = a.*b
+
+
+%Output:
+% c = 4 12 45
+
+% Remark: The period preceding the mathematical operation, "*", indicates that the
+% operation will be performed element-by-element. In this case, the content of c is
+% c = [a(1)*b(1) a(2)*b(2) a(3)*b(3)]
+% Also, c is automatically assigned as a 1-D array with 3 elements
\ No newline at end of file
diff --git a/matlab_for_beginners/part_4(array_nd_matrix)/program5.m b/matlab_for_beginners/part_4(array_nd_matrix)/program5.m
new file mode 100644
index 0000000..2611be5
--- /dev/null
+++ b/matlab_for_beginners/part_4(array_nd_matrix)/program5.m
@@ -0,0 +1,10 @@
+%% Ex. 5 Element-by-element multiplication of two matrices
+
+a = [2 3; 1 4];
+b = [5 1; 7 2];
+c = a.*b
+
+
+%Output:
+% c = 10 3
+% 7 8
\ No newline at end of file
diff --git a/matlab_for_beginners/part_4(array_nd_matrix)/program6.m b/matlab_for_beginners/part_4(array_nd_matrix)/program6.m
new file mode 100644
index 0000000..aa7af0d
--- /dev/null
+++ b/matlab_for_beginners/part_4(array_nd_matrix)/program6.m
@@ -0,0 +1,12 @@
+%% Ex.6 Direct (not element-by-element) multiplication of two matrices
+
+
+a = [2 3; 1 4];
+b = [5 1; 7 2];
+c = a*b
+% Output:
+% c = 31 8
+ % 33 9
+
+
+ %Remark: Observe how the outcome of this example differs from Ex. 32.
\ No newline at end of file
diff --git a/matlab_for_beginners/part_4(array_nd_matrix)/program7.m b/matlab_for_beginners/part_4(array_nd_matrix)/program7.m
new file mode 100644
index 0000000..e2fcdfa
--- /dev/null
+++ b/matlab_for_beginners/part_4(array_nd_matrix)/program7.m
@@ -0,0 +1,9 @@
+%% Ex. 7 Elementary functions with a vectorial variable
+
+a = [2 3 5];
+b = sin(a)
+% Output:
+% b = 0.9092 0.1411 -0.9589
+
+
+%Remark: The content of b is [sin(2) sin(3) sin(5)].
\ No newline at end of file
diff --git a/matlab_for_beginners/part_4(array_nd_matrix)/program8.m b/matlab_for_beginners/part_4(array_nd_matrix)/program8.m
new file mode 100644
index 0000000..015e34e
--- /dev/null
+++ b/matlab_for_beginners/part_4(array_nd_matrix)/program8.m
@@ -0,0 +1,10 @@
+%% Ex. 8 Another example of elementary functions with a vectorial variable
+
+a = [2 3 5];
+b = 2*a.^2+3*a+4
+
+
+%Output:
+% b = 18 31 69
+% Remark: The content of b is
+% b = [2*(a(1))^2+3*a(1)+4 2*(a(2))^2+3*a(2)+4 2*(a(3))^2+3*a(3)+4].
\ No newline at end of file
diff --git a/matlab_for_beginners/part_4(array_nd_matrix)/program9.m b/matlab_for_beginners/part_4(array_nd_matrix)/program9.m
new file mode 100644
index 0000000..12c7590
--- /dev/null
+++ b/matlab_for_beginners/part_4(array_nd_matrix)/program9.m
@@ -0,0 +1,8 @@
+%% Ex. 9 An efficient way to assign the content of an array
+
+
+a = [0:0.5:4];
+a
+
+%Output:
+% a = 0 0.5 1 1.5 2 2.5 3 3.5 4
\ No newline at end of file
diff --git a/project-euler/Problem3/isPrime.m b/project-euler/Problem3/isPrime.m
deleted file mode 100644
index ffd26ca..0000000
--- a/project-euler/Problem3/isPrime.m
+++ /dev/null
@@ -1,17 +0,0 @@
-% isPrime: returns true if number is prime otherwise false.
-% assumes: number is positive
-function y = isPrime(n)
- assert(n >= 0,'n must be >= 0')
- y = true;
- for divisor = 2 : 1 : sqrt(n)
- if (mod(n,divisor) == 0)
- y = false;
- break
- endif
- endfor
-
- % make sure the function recognizes number 0 and 1
- if (n == 0 || n == 1)
- y = false;
- endif
-endfunction
\ No newline at end of file
diff --git a/project-euler/Problem3/pfz.m b/project-euler/Problem3/pfz.m
index 0bdd1ca..7dbcc71 100644
--- a/project-euler/Problem3/pfz.m
+++ b/project-euler/Problem3/pfz.m
@@ -1,17 +1,17 @@
% pfz: returns the prime factorization of that number.
% assumes: number is positive
-% uses: function isPrime
function y = pfz(number)
assert(number >= 0,'number must be positive')
y = []; % collects all prime factors
- tmp = number; % saves temporary the argument
- for divisor = 2 : 1 : sqrt(number)
- if (isPrime(divisor))
- while (mod(number,divisor) == 0)
- y = [y divisor];
- number = idivide(number,divisor); % integer division
- endwhile
- number = tmp;
- endif
- endfor
+ divisor = 2;
+ while (divisor <= sqrt(number))
+ while (mod(number,divisor) == 0)
+ y = [y divisor];
+ number /= divisor; % integer division
+ endwhile
+ divisor += 1;
+ endwhile
+ if (number > 1)
+ y = [y number];
+ endif
endfunction
\ No newline at end of file
diff --git a/project-euler/Problem4/solv.m b/project-euler/Problem4/solv.m
index 5fcec7d..c23c0c0 100644
--- a/project-euler/Problem4/solv.m
+++ b/project-euler/Problem4/solv.m
@@ -5,10 +5,8 @@
product = number1 * number2; % builds the new product
% make sure product is a palindrome number.
- if (isPalindromeNumber(product))
- if (product > maxPalindrome)
- maxPalindrome = product;
- endif
+ if (product > maxPalindrome && isPalindromeNumber(product))
+ maxPalindrome = product;
endif
endfor
endfor