<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: sofaki000</title>
    <description>The latest articles on DEV Community by sofaki000 (@sofaki000).</description>
    <link>https://dev.to/sofaki000</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F511829%2Fc2ae0d99-0c3f-43cb-977c-05f915534a2a.png</url>
      <title>DEV Community: sofaki000</title>
      <link>https://dev.to/sofaki000</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sofaki000"/>
    <language>en</language>
    <item>
      <title>Run envoy proxy with docker</title>
      <dc:creator>sofaki000</dc:creator>
      <pubDate>Fri, 07 Feb 2025 12:52:22 +0000</pubDate>
      <link>https://dev.to/sofaki000/run-envoy-proxy-with-docker-fj3</link>
      <guid>https://dev.to/sofaki000/run-envoy-proxy-with-docker-fj3</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.tourl"&gt;&lt;/a&gt;Hey friends, today we will do a short introduction how to run envoy proxy with docker. We will work with the basic blocks of envoy, which are listeners, clusters and filters.&lt;/p&gt;

&lt;h2&gt;Prerequisites&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;download docker&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;Run envoy with docker&lt;/h2&gt;



&lt;p&gt;&lt;code&gt;docker run --name=proxy-with-admin -d -p 9901:9901 -p 10000:10000 envoyproxy/envoy:v1.25.6&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Why adding -p 9901:9901? &lt;br&gt;
This exposes the 9901 container image to your host. This way you can access the admin portal in &lt;a href="http://localhost:9901/" rel="noopener noreferrer"&gt;http://localhost:9901/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyoc1owmc1je0etf18m49.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyoc1owmc1je0etf18m49.png" alt="Image description" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From docker desktop, you can see in envoy.yaml which contains the configuration of your envoy, that admin portal is exposed on 9901 port on your container. &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9shpbry2ccjhtx9rdj9w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9shpbry2ccjhtx9rdj9w.png" alt="Image description" width="800" height="554"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Send request to envoy&lt;/h2&gt;

&lt;p&gt;Envoy uses listeners to accept client requests. These requests are then forwarded to clusters, which represent your backend services.&lt;/p&gt;

&lt;p&gt;In the envoy.yaml, we see the following configuration for listeners:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  listeners:
  - name: listener_0
    address:
      socket_address:
        protocol: TCP
        address: 0.0.0.0
        port_value: 10000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means that your listener is on port 10000. We have exposed this port with the Docker command: -p 10000:10000.&lt;/p&gt;

&lt;p&gt;Therefore when you hit &lt;a href="http://localhost:10000/" rel="noopener noreferrer"&gt;http://localhost:10000/&lt;/a&gt; on your local machine, you reach the Envoy listener.  When an Envoy listener receives a request, the Envoy filters execute.&lt;/p&gt;

&lt;p&gt;In the filters section of our envoy.yaml we see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          scheme_header_transformation:
            scheme_to_overwrite: https
          stat_prefix: ingress_http
          route_config:
            name: local_route
            virtual_hosts:
            - name: local_service
              domains: ["*"]
              routes:
              - match:
                  prefix: "/"
                route:
                  host_rewrite_literal: www.envoyproxy.io
                  cluster: service_envoyproxy_io
          http_filters:
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the           "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager&lt;br&gt;
we see the type of filter we have applied, which is a HTTP connection manager &lt;a href="https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/http/http_connection_management" rel="noopener noreferrer"&gt;more here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your cluster (aka your backend) is service_envoyproxy_io.&lt;/p&gt;

&lt;h2&gt;Using Your Own envoy.yaml Configuration&lt;/h2&gt;

&lt;p&gt;If you want to use your own envoy.yaml configuration, you need to have an envoy.yaml file and provide it in the container image you are running.&lt;/p&gt;

&lt;p&gt;Run this command in the folder where you have your envoy.yaml:&lt;/p&gt;

&lt;p&gt;docker run --name=proxy-with-admin -d -p 9901:9901 -p 10000:10000 -v envoy.yaml:/etc/envoy/envoy.yaml envoyproxy/envoy:v1.25.6&lt;br&gt;
The command -v .envoy.yaml:/etc/envoy/envoy.yaml is used to mount a file or directory from your local machine into a container. In this case, it mounts the local file .envoy.yaml to the path /etc/envoy/envoy.yaml inside the container. This ensures that the container uses the configuration file from your local environment.&lt;/p&gt;

&lt;h2&gt;References&lt;/h2&gt;

&lt;h2&gt;
  
  
  - &lt;a href="https://iceburn.medium.com/i-tried-getting-started-with-envoy-d6680f69bc3" rel="noopener noreferrer"&gt;https://iceburn.medium.com/i-tried-getting-started-with-envoy-d6680f69bc3&lt;/a&gt;
&lt;/h2&gt;

</description>
    </item>
    <item>
      <title>3 CDK best practises</title>
      <dc:creator>sofaki000</dc:creator>
      <pubDate>Sat, 13 May 2023 19:14:29 +0000</pubDate>
      <link>https://dev.to/sofaki000/3-cdk-best-practises-mdo</link>
      <guid>https://dev.to/sofaki000/3-cdk-best-practises-mdo</guid>
      <description>&lt;p&gt;Let's explore some best practises for getting started. As always, feedback on the content is always welcomed :D&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Avoid editting the physical and logical names of your constructs.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Physical name of a resource is what you see on AWS console. Logical name of a resource is the resource name in AWS Cloudformation template. The logical name is the construct id we provided with an extra suffix added by the CDK. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;const bucket = new s3.Bucket(this, 'thisIsTheConstructId', {&lt;br&gt;
  bucketName: 'thePhysicalName',&lt;br&gt;
});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can edit the physical name of a construct by overriding the name property of the construct (for s3 buckets, the bucketName prop). Assigning physical names to resources has some disadvantages in AWS CloudFormation. Most importantly, any changes to deployed resources that require a resource replacement, such as changes to a resource's properties that are immutable after creation, will fail if a resource has a physical name assigned. If you end up in that state, the only solution is to delete the AWS CloudFormation stack, then deploy the AWS CDK app again. See the AWS CloudFormation documentation for details.&lt;/p&gt;

&lt;p&gt;When it is required to add a physical name? In some cases, like when creating an AWS CDK app with cross-environment references.&lt;/p&gt;

&lt;p&gt;You should also avoid changing the logical ID of a resource after it has been created. AWS CloudFormation identifies resources by their logical ID. Therefore, if you change the logical ID of a resource, AWS CloudFormation creates a new resource with the new logical ID, then deletes the existing one. Depending on the type of resource, this might cause service interruption, data loss, or both.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Use grant methods to assign privileges&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AWS constructs make least-privilege permissions achievable by offering APIs to express permission requirements.&lt;br&gt;
Try to avoid to manually create IAM permission statements when a grant method fits your use case.&lt;/p&gt;

&lt;p&gt;The following example creates the permissions to allow a Lambda function's execution role to read and write objects to a particular Amazon S3 bucket. If the Amazon S3 bucket is encrypted with an AWS KMS key, this method also grants permissions to the Lambda function's execution role to decrypt with the key.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;bucket.grantReadWrite(lambdaFun)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If a specific grant method isn't available for the particular use case, you can use a generic grant method to define a new grant with a specified list of actions.&lt;/p&gt;

&lt;p&gt;The following example shows how to grant a Lambda function access to the Amazon DynamoDB CreateBackup action.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;table.grant(func, 'dynamodb:CreateBackup');&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Don't forget to define removal policies&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Resources that maintain persistent data, such as databases, Amazon S3 buckets, and Amazon ECR registries, have a removal policy. The removal policy indicates whether to delete persistent objects when the AWS CDK stack that contains them is destroyed. The values specifying the removal policy are available through the RemovalPolicy enumeration in the AWS CDK core module.&lt;/p&gt;

&lt;p&gt;Resources besides those that store data persistently might also have a removalPolicy that is used for a different purpose. For example, a Lambda function version uses a removalPolicy attribute to determine whether a given version is retained when a new version is deployed. These have different meanings and defaults compared to the removal policy on an Amazon S3 bucket or DynamoDB table.&lt;/p&gt;

&lt;p&gt;RemovalPolicy.RETAIN (DEFAULT) = Keep the contents of the resource when destroying the stack. The resource is orphaned from the stack and must be deleted manually. If you attempt to re-deploy the stack while the resource still exists, you will receive an error message due to a name conflict.&lt;br&gt;
RemovalPolicy.DESTROY = The resource will be destroyed along with the stack.&lt;/p&gt;

&lt;p&gt;Just be careful with S3: even if removal policy of a bucket is set to DESTROY, AWS CloudFormation does not remove Amazon S3 buckets that contain files. Attempting to do so is an AWS CloudFormation error. To have the AWS CDK delete all files from the bucket before destroying it, set the bucket's autoDeleteObjects property to true.&lt;/p&gt;

&lt;p&gt;Happy coding folks!&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
If you would like to explore more CDK best practises, AWS docs are an excellent place. You can find the basic concepts &lt;a href="https://docs.aws.amazon.com/cdk/v2/guide/constructs.html"&gt;here&lt;/a&gt; and some best practises &lt;a href="https://docs.aws.amazon.com/cdk/v2/guide/best-practices.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Heap and Stack in JS basics</title>
      <dc:creator>sofaki000</dc:creator>
      <pubDate>Sun, 01 May 2022 13:08:15 +0000</pubDate>
      <link>https://dev.to/sofaki000/heap-and-stack-in-js-basics-2ppk</link>
      <guid>https://dev.to/sofaki000/heap-and-stack-in-js-basics-2ppk</guid>
      <description>&lt;p&gt;Javascript knows two types of memories: Stack and Heap&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Stack&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;easy-to-access memory &lt;/li&gt;
&lt;li&gt;Only items for which the size is known in advance can go onto the stack&lt;/li&gt;
&lt;li&gt;Numbers,strings,booleans go to the stack&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Heap&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;For items of which the exact size and structure can't be pre-determined.
&lt;/li&gt;
&lt;li&gt;Objects and arrays can be changed at runtime, therefore they go to heap&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For each heap item, the exact address is stored in a pointer which points at the item in the heap. This pointer in turn is stored on the stack.&lt;br&gt;
For reference types, only pointers are stored on the stack.&lt;/p&gt;

&lt;p&gt;Example 1&lt;br&gt;
So for example, if you have the variable:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var person={name:"Sofia"}&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Only a pointer to the person object is stored in that variable&lt;/p&gt;

&lt;p&gt;Example 2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var person = { name: 'Sofia' }
var newPerson = person
newPerson.name = 'John'
console.log(person.name)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will print "John", becasue we never copied the person object itself to newPerson. We only copied the pointer, which still points at the same address in memory! Hence changing newPerson.name also changes person.name because newPerson points at the exactly same object!&lt;br&gt;
You're pointing at the same object, you didn't copy the object.&lt;/p&gt;

&lt;p&gt;How you copy the actual value? The spread operator comes to the rescue&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var person = { name: 'Max' }
var copiedPerson = { ...person }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>stack</category>
      <category>heap</category>
      <category>reference</category>
    </item>
    <item>
      <title>Getting started with pthreads</title>
      <dc:creator>sofaki000</dc:creator>
      <pubDate>Sun, 13 Mar 2022 07:49:22 +0000</pubDate>
      <link>https://dev.to/sofaki000/pthreads-introduction-ngh</link>
      <guid>https://dev.to/sofaki000/pthreads-introduction-ngh</guid>
      <description>&lt;ol&gt;
&lt;li&gt;Installing pthreads library&lt;/li&gt;
&lt;li&gt;Compiling pthread programs&lt;/li&gt;
&lt;li&gt;
Pthreads API &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Installation &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Installing pthreads library on linux:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt-get install libpthread-stubs0-dev&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;




&lt;h2&gt;
  
  
  Compilation  &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;You can compile threaded programms with gnu compiler with the following command:&lt;/p&gt;

&lt;p&gt;1)&lt;br&gt;
&lt;br&gt;
  &lt;code&gt;gcc -pthread file.c&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;or &lt;/p&gt;

&lt;p&gt;2)&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;gcc -pthread file.c -o thread -lpthread&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;where:&lt;br&gt;
-lpthread command will tell the compiler to execute the program with pthread.h library. &lt;br&gt;
gcc is the compiler command.&lt;br&gt;
file.c is the name of c program source file.&lt;br&gt;
-o is option to make object file.&lt;br&gt;
thread is the name of object file.&lt;/p&gt;




&lt;h2&gt;
  
  
  Pthreads API &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;All identifiers in the threads library begin with pthread_.&lt;/p&gt;

&lt;p&gt;Some frequently used methods are:&lt;/p&gt;

&lt;p&gt;1) pthread_ = Threads themselves and miscellaneous subroutines &lt;br&gt;
2) pthread_attr_ = Thread attributes objects&lt;br&gt;
3) pthread_mutex_ = Mutexes&lt;br&gt;
4) pthread_mutexattr_ = Mutex attributes objects.&lt;/p&gt;

&lt;p&gt;Also the pthread.h header file should be included in each source file using the Pthreads library.&lt;/p&gt;

</description>
      <category>c</category>
      <category>pthreads</category>
      <category>threads</category>
      <category>programming</category>
    </item>
    <item>
      <title>Hypothesis Testing with matlab</title>
      <dc:creator>sofaki000</dc:creator>
      <pubDate>Sun, 21 Nov 2021 14:08:52 +0000</pubDate>
      <link>https://dev.to/sofaki000/hypothesis-testing-with-matlab-d9d</link>
      <guid>https://dev.to/sofaki000/hypothesis-testing-with-matlab-d9d</guid>
      <description>&lt;p&gt;Introduction&lt;/p&gt;

&lt;p&gt;In this article we will explore some matlab functions for hypothesis testing in data analysis.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;ttest&lt;/strong&gt; = One-sample and paired-sample t-test&lt;/p&gt;

&lt;p&gt;h = ttest(x) returns a test decision for the null hypothesis that the data in x comes from a normal distribution with mean equal to zero and unknown variance, using the one-sample t-test. The alternative hypothesis is that the population distribution does not have a mean equal to zero. The result h is 1 if the test rejects the null hypothesis at the 5% significance level, and 0 otherwise.&lt;/p&gt;

&lt;p&gt;example&lt;br&gt;
h = ttest(x,y) returns a test decision for the null hypothesis that the data in x – y comes from a normal distribution with mean equal to zero and unknown variance, using the paired-sample t-test.&lt;/p&gt;

&lt;p&gt;example&lt;br&gt;
h = ttest(x,y,Name,Value) returns a test decision for the paired-sample t-test with additional options specified by one or more name-value pair arguments. For example, you can change the significance level or conduct a one-sided test.&lt;/p&gt;

&lt;p&gt;example&lt;br&gt;
h = ttest(x,m) returns a test decision for the null hypothesis that the data in x comes from a normal distribution with mean m and unknown variance. The alternative hypothesis is that the mean is not m.&lt;/p&gt;



&lt;p&gt;Example: Test the null hypothesis from sample data A with mean equal to zero at the 1% significance level and calculate confidence interval of mean.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;clear;
clc; 
A  = [41 46 47 47 48 50 50 50 50 50 50 50 48 50 50 50 50 50 50 50 52 52 53 55 50 50 50 50 52 52 53 53 53 53 53 57 52 52 53 53 53 53 53 53 54 54 55 68]; 
alpha = 0.01; 
[h,p,ci] = ttest(A,0,'Alpha',0.01)
fprintf('CI for mean(A)=[%2.3f,%2.3f] \n', ci(1),ci(2)); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
CI for mean(A)=[50.017,52.817] &lt;/p&gt;



&lt;p&gt;&lt;strong&gt;vartest&lt;/strong&gt; = chi-square variance test&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;h = vartest(x,v)&lt;/strong&gt; returns a test decision for the null hypothesis that the data in vector x comes from a normal distribution with variance v, using the chi-square variance test. The alternative hypothesis is that x comes from a normal distribution with a different variance. The result h is 1 if the test rejects the null hypothesis at the 5% significance level, and 0 otherwise.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;h = vartest(x,v,Name,Value)&lt;/strong&gt; performs the chi-square variance test with additional options specified by one or more name-value pair arguments. For example, you can change the significance level or conduct a one-sided test.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Input arguments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- x — Sample data (vector | matrix | multidimensional array)
- v — Hypothesized variance (scalar value)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Name-Value Arguments&lt;/p&gt;

&lt;p&gt;Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- Alpha — Significance level (0.05 (default) | scalar value in the range (0,1))
- Dim — Dimension,first nonsingleton dimension (default) | positive integer value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output arguments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- h — Hypothesis test result 1 | 0
If h = 1, this indicates the rejection of the null hypothesis at the Alpha significance level.

If h = 0, this indicates a failure to reject the null hypothesis at the Alpha significance level.

- p — p-value
p-value of the test, returned as a scalar value in the range [0,1]. p is the probability of observing a test statistic as extreme as, or more extreme than, the observed value under the null hypothesis. Small values of p cast doubt on the validity of the null hypothesis.

- ci — Confidence interval
Confidence interval for the true variance, returned as a two-element vector containing the lower and upper boundaries of the 100 × (1 – Alpha)% confidence interval.


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example Program to calculate confidence interval of variance&lt;br&gt;
and standard deviation of a matrix using vartest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; A  = [41 46 47 47 48 50 50 50 50 50 50 50 48 50 50 50 50 50 50 50 52 52 53 55 50 50 50 50 52 52 53 53 53 53 53 57 52 52 53 53 53 53 53 53 54 54 55 68]; 
alpha = 0.05; 
variance = var(A)
[h,pvar,civarV]= vartest(A ,variance, alpha);
fprintf('CI for var(A)=[%2.3f,%2.3f] \n', civarV(1),civarV(2));
fprintf('CI for sigma(A)=[%2.3f,%2.3f] \n',sqrt(civarV(1)),sqrt(civarV(2)));

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;Some theory&lt;/u&gt;:&lt;br&gt;
Chi-Square Variance Test&lt;br&gt;
The chi-square variance test is used to test whether the variance of a population is equal to a hypothesized value.&lt;/p&gt;

&lt;p&gt;The test statistic is&lt;/p&gt;

&lt;p&gt;T=(n−1)[(s/ σ)^2]&lt;/p&gt;

&lt;p&gt;where n is the sample size, s is the sample standard deviation, and σ is the hypothesized standard deviation. The denominator is the ratio of the sample standard deviation to the hypothesized &lt;/p&gt;

&lt;p&gt;standard deviation. The further this ratio deviates from 1, the more likely you are to reject the null hypothesis. The test statistic T has a chi-square distribution with n – 1 degrees of freedom under the null hypothesis.&lt;/p&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;chi2gof&lt;/strong&gt; = Chi-square goodness-of-fit test&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;Some theory&lt;/u&gt;:&lt;br&gt;
The Chi-square goodness of fit test is a statistical hypothesis test used to determine whether a variable is likely to come from a specified distribution or not. It is often used to evaluate whether sample data is representative of the full population.&lt;/p&gt;

&lt;p&gt;Description:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;h = chi2gof(x) returns a test decision for the null hypothesis that the data in vector x comes from a normal distribution with a mean and variance estimated from x, using the chi-square goodness-of-fit test. The alternative hypothesis is that the data does not come from such a distribution. The result h is 1 if the test rejects the null hypothesis at the 5% significance level, and 0 otherwise.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;h = chi2gof(x,Name,Value) returns a test decision for the chi-square goodness-of-fit test with additional options specified by one or more name-value pair arguments. For example, you can test for a distribution other than normal, or change the significance level of the test.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;clear;
clc; 

binomialdist = makedist('Binomial'); 
normaldist = makedist('Normal');
b = random(binomialdist,100,1);
n = random(normaldist,100,1);

%Returns a test decision for the null hypothesis that the data in 
%vector comes from a normal distribution with a mean and variance
 %estimated from the vector
h1 = chi2gof(b);
h2 = chi2gof(n) 
%returns a test decision for the chi-square goodness-of-fit test for a
%binomial distribution
h3 = chi2gof(b,'CDF',binomialdist);

fprintf("h1 = %d\n",h1); % false
fprintf("h2 = %d\n",h2); % true
fprintf("h3 = %d\n",h3); % true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
h1 = 1&lt;br&gt;
h2 = 0&lt;br&gt;
h3 = 0&lt;/p&gt;

</description>
      <category>dataanalysis</category>
      <category>matlab</category>
      <category>datascience</category>
      <category>hypothesistesting</category>
    </item>
    <item>
      <title>Data analysis with Matlab: distributions</title>
      <dc:creator>sofaki000</dc:creator>
      <pubDate>Sat, 20 Nov 2021 19:31:14 +0000</pubDate>
      <link>https://dev.to/sofaki000/data-analysis-with-matlab-distributions-3974</link>
      <guid>https://dev.to/sofaki000/data-analysis-with-matlab-distributions-3974</guid>
      <description>&lt;p&gt;Introduction:&lt;/p&gt;

&lt;p&gt;Explore different distributions (normal, poisson, student,exponential) using matlab.&lt;/p&gt;




&lt;h3&gt;
  
  
  Normal distribution
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;normrnd&lt;/strong&gt; = Normal random numbers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;r = normrnd(mu,sigma) generates a random number from the normal distribution with mean parameter mu and standard deviation parameter sigma.&lt;/p&gt;

&lt;p&gt;r = normrnd(mu,sigma,sz1,...,szN) generates an array of normal random numbers, where sz1,...,szN indicates the size of each dimension.&lt;/p&gt;

&lt;p&gt;Arguments:&lt;br&gt;
mu — Mean&lt;br&gt;
sigma — Standard deviation&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More on normal distribution on a separate article &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Poisson distribution
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;poissrnd&lt;/strong&gt; = generates random numbers from Poisson distribution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;r = poissrnd(lambda) generates random numbers from the Poisson distribution specified by the rate parameter lambda.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;lambda can be a scalar, vector, matrix, or multidimensional array.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;r = poissrnd(lambda,sz1,...,szN) generates an array of random numbers from the Poisson distribution with the scalar rate parameter lambda, where sz1,...,szN indicates the size of each dimension.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;p&gt;1)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;r_scalar = poissrnd(20)
r_scalar = 9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2)&lt;br&gt;
Generate a 2-by-3 array of random numbers from the same distribution by specifying the required array dimensions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lambda = 20
r_array = poissrnd(lambda ,2,3)
r_array = 2×3

    13    14    18
    26    16    21

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lambda = 10:2:20
lambda = 1×6

    10    12    14    16    18    20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Generate random numbers from the Poisson distributions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;r = poissrnd(lambda)
r = 1×6

    14    13    14     9    14    31
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;poisspdf&lt;/strong&gt;= Poisson probability density function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Parameters:&lt;/p&gt;

&lt;p&gt;x — Values at which to evaluate Poisson pdf&lt;br&gt;
lambda — Rate parameters&lt;/p&gt;

&lt;p&gt;Compute the Poisson probability density function values at each value from 0 to 10. These values correspond to the probabilities that a disk has 0, 1, 2, .., 10 flaws.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;p&gt;1)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flaws = 0:10;
y = poisspdf(flaws,2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tV = [0:100]';
lambda = 10; 
pois = poisspdf(tV,lambda);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Student's distribution
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;tcdf&lt;/strong&gt; = Student's t cumulative distribution function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;p = tcdf(x,nu) returns the cumulative distribution function (cdf) of the Student's t distribution with nu degrees of freedom, evaluated at the values in x.&lt;/p&gt;

&lt;p&gt;Arguments:&lt;br&gt;
x — Values at which to evaluate cdf&lt;br&gt;
nu — Degrees of freedom&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;tinv&lt;/strong&gt; = Student's t inverse cumulative distribution function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;p&gt;1)&lt;br&gt;
Find the 95th percentile of the Student's t distribution with 50 degrees of freedom.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p = .95;   
nu = 50;   
x = tinv(p,nu)
x = 1.6759
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Exponential distribution
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;exprnd&lt;/strong&gt; = calculates exponential random numbers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;p&gt;1)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;r = exprnd(mu)
r = exprnd(mu) generates a random number from the exponential distribution with mean mu.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;r = exprnd(mu,sz1,...,szN)
 generates an array of random numbers from the exponential distribution, where sz1,...,szN indicates the size of each dimension.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;exppdf&lt;/strong&gt; = Exponential probability density function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;1) y = exppdf(x) returns the probability density function (pdf) of the standard exponential distribution, evaluated at the values in x.&lt;/p&gt;

&lt;p&gt;Compute the density of the value 5 in the standard exponential distribution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;y1 = exppdf(5) 
y1 = 0.0067
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) y = exppdf(x,mu) returns the pdf of the exponential distribution with mean mu, evaluated at the values in x.&lt;/p&gt;

&lt;p&gt;Compute the density of the value 5 in the exponential distributions specified by means 1 through 5.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;y2 = exppdf(5,1:5)
y2 = 1×5

    0.0067    0.0410    0.0630    0.0716    0.0736
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Arguments:&lt;/p&gt;

&lt;p&gt;x — Values at which to evaluate pdf&lt;br&gt;
mu — mean&lt;/p&gt;
&lt;h3&gt;
  
  
  Histograms
&lt;/h3&gt;

&lt;p&gt;1) &lt;strong&gt;&lt;em&gt;histogram&lt;/em&gt;&lt;/strong&gt; = Histogram plot&lt;/p&gt;

&lt;p&gt;2) &lt;strong&gt;histfit&lt;/strong&gt; = Histogram with a distribution fit&lt;/p&gt;

&lt;p&gt;histfit(data) plots a histogram of values in data using the number of bins equal to the square root of the number of elements in data and fits a normal density function.&lt;/p&gt;

&lt;p&gt;Construct a histogram with a normal distribution fit.&lt;br&gt;
(bins are the number of bars you will see in your hist)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;r = normrnd(10,1,100,1); 
histfit(r)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;example&lt;br&gt;
histfit(data,nbins) plots a histogram using nbins bins and fits a normal density function.&lt;br&gt;
Construct a histogram using six bins with a normal distribution fit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;r = normrnd(10,1,100,1);
histfit(r,6)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Clearing environment
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;clc&lt;/strong&gt; = clears command window&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;clear&lt;/strong&gt; = Remove items from workspace, freeing up system memory&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  General Useful Commands
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;mean&lt;/strong&gt; = calculates average or mean value of array&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;nargin&lt;/strong&gt; = returns the number of function input arguments &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ttest&lt;/strong&gt; = One-sample and paired-sample t-test&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  More on ttest
&lt;/h4&gt;

&lt;p&gt;The one-sample t-test is a parametric test of the location parameter when the population standard deviation is unknown.&lt;/p&gt;

&lt;p&gt;The test statistic is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;t= (x−μ)/(s/squar(n))  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where x is the sample mean, μ is the hypothesized population mean, s is the sample standard deviation, and n is the sample size. Under the null hypothesis, the test statistic has Student’s t distribution with n – 1 degrees of freedom.&lt;/p&gt;

&lt;p&gt;Arguments of ttest:&lt;/p&gt;

&lt;p&gt;1)&lt;/p&gt;

&lt;h6&gt;
  
  
  Alpha — Significance level
&lt;/h6&gt;

&lt;p&gt;0.05 (default) | scalar value in the range (0,1)&lt;/p&gt;

&lt;p&gt;2)&lt;/p&gt;

&lt;h6&gt;
  
  
  Dim — Dimension
&lt;/h6&gt;

&lt;p&gt;first nonsingleton dimension (default) | positive integer value&lt;br&gt;
Dimension of the input matrix along which to test the means consisting of 'Dim' and a positive integer value. For example, specifying 'Dim',1 tests the column means, while 'Dim',2 tests the row means.&lt;br&gt;
3)&lt;/p&gt;

&lt;h6&gt;
  
  
  Tail — Type of alternative hypothesis
&lt;/h6&gt;

&lt;p&gt;'both' (default) | 'right' | 'left'&lt;br&gt;
Type of alternative hypothesis to evaluate, specified as the comma-separated pair consisting of 'Tail' and one of:&lt;/p&gt;

&lt;p&gt;'both' — Test against the alternative hypothesis that the population mean is not m.&lt;/p&gt;

&lt;p&gt;'right' — Test against the alternative hypothesis that the population mean is greater than m.&lt;/p&gt;

&lt;p&gt;'left' — Test against the alternative hypothesis that the population mean is less than m.&lt;/p&gt;

&lt;p&gt;Output Arguments of ttest:&lt;/p&gt;

&lt;p&gt;1)&lt;/p&gt;

&lt;h6&gt;
  
  
  Hypothesis test result
&lt;/h6&gt;

&lt;p&gt;Hypothesis test result, returned as 1 or 0.&lt;/p&gt;

&lt;p&gt;If h = 1, this indicates the rejection of the null hypothesis at the Alpha significance level.&lt;/p&gt;

&lt;p&gt;If h = 0, this indicates a failure to reject the null hypothesis at the Alpha significance level.&lt;/p&gt;

&lt;p&gt;2)&lt;/p&gt;

&lt;h6&gt;
  
  
  p — p-value,scalar value in the range [0,1]
&lt;/h6&gt;

&lt;p&gt;p-value of the test, returned as a scalar value in the range [0,1]. p is the probability of observing a test statistic as extreme as, or more extreme than, the observed value under the null hypothesis. Small values of p cast doubt on the validity of the null hypothesis.&lt;/p&gt;

&lt;p&gt;3)&lt;/p&gt;

&lt;h6&gt;
  
  
  ci — Confidence interval
&lt;/h6&gt;

&lt;p&gt;vector&lt;br&gt;
Confidence interval for the true population mean, returned as a two-element vector containing the lower and upper boundaries of the 100 × (1 – Alpha)% confidence interval.&lt;/p&gt;

&lt;p&gt;4)&lt;/p&gt;

&lt;h6&gt;
  
  
  stats — Test statistics
&lt;/h6&gt;

&lt;p&gt;structure&lt;br&gt;
Test statistics, returned as a structure containing the following:&lt;/p&gt;

&lt;p&gt;tstat — Value of the test statistic.&lt;/p&gt;

&lt;p&gt;df — Degrees of freedom of the test.&lt;/p&gt;

&lt;p&gt;sd — Estimated population standard deviation. For a paired t-test, sd is the standard deviation of x – y.&lt;/p&gt;

</description>
      <category>matlab</category>
      <category>computerscience</category>
      <category>datascience</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Matlab plots tutorial</title>
      <dc:creator>sofaki000</dc:creator>
      <pubDate>Sat, 20 Nov 2021 11:17:05 +0000</pubDate>
      <link>https://dev.to/sofaki000/matlab-plots-tutorial-93g</link>
      <guid>https://dev.to/sofaki000/matlab-plots-tutorial-93g</guid>
      <description>&lt;p&gt;Introduction&lt;/p&gt;

&lt;p&gt;In this tutorial we will look at some basic functionalities of matlab figures. We will see some examples and understand how to use functions such as plot and stem.&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;figure&lt;/strong&gt; creates a new figure window using default property values. The resulting figure is the current figure.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;figure(Name,Value) modifies properties of the figure using one or more name-value pair arguments. For example, figure('Color','Red') sets the background color to red (same as figure('Color','r')&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Creating one discrete and one 2D line plot in the same figure
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;figure("Color", "c"); %adds cyan color at the background of matlab % figure 
%Creates a vector of 100 evenly spaced points in the interval 
%[-5,5].
Y = linspace(-5,5,50);
plot(Y, "r:") % plots Y against an implicit set of x-coordinates.
% adds red color to line (from r) and makes it dotted (from :)
hold on % use hold on to add a second plot
stem(Y, "c") % plott discrete sequence data
% c makes line have cyan color
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7aHQYG8N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rfi4ih5w7f8m4eoxw49j.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7aHQYG8N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rfi4ih5w7f8m4eoxw49j.jpg" alt="Image description" width="700" height="525"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Adding grid to your figures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;grid&lt;/strong&gt;= Display or hide axes grid lines&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;1) grid on = displays the major grid lines for the current axes &lt;/p&gt;

&lt;p&gt;2) grid off = removes all grid lines from the current axes or chart.&lt;/p&gt;

&lt;p&gt;3) grid minor = Display the minor grid lines.&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;scatter&lt;/strong&gt; = Scatter plot&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;tiledlayout&lt;/strong&gt; = Create tiled chart layout&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;tiledlayout(m,n)&lt;/strong&gt; = creates a tiled chart layout for displaying multiple plots in the current figure. The layout has a fixed m-by-n tile arrangement that can display up to m*n plots.   &lt;/p&gt;




&lt;p&gt;Example no 2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;clc;
clear; 
figure("Color", "c"); 
x = linspace(0,3*pi,200); %Create a vector of 100 points in the interval [0,3π,200].
y = cos(x) + rand(1,200);
t = tiledlayout(2,2); 

title(t,'Title of our figure') % add title
xlabel(t,'X label')% add x label
ylabel(t,'Y label')% add y label
t.TileSpacing = 'compact'; %Decrease the amount of space between the tiles by setting the TileSpacing property to 'compact'
t.Padding = 'compact'; %decrease the space between the edges of the layout and the edges of the figure by setting the Padding property to 'compact'.

% add your plots in the same figure:
ax1 = nexttile;
ax1.XColor = [1 1 1];
ax1.YColor = [1 0 0];
scatter(ax1,x,y);
grid on
title('Sample 1');

ax2 = nexttile;
scatter(ax2,x,y,'filled','d');
title('Sample 2');

nexttile(t);
bar([10 22 31 43 52])
title('Sample 3');

nexttile(t);

x = linspace(-10,10,200); %Create x as 200 linearly spaced values between -10 and 10.
y = cos(x); % Create y as the cosine of x.
plot(x,y)
%Change the tick value locations along the x-axis and y-axis. 
%Specify the locations as a vector of increasing values. The values do not need to be evenly spaced.
xticks([-3*pi -2*pi -pi 0 pi 2*pi 3*pi])
xticklabels({'-3\pi','-2\pi','-\pi','0','\pi','2\pi','3\pi'}) %Also, change the labels associated with each tick value along the x-axis. To include special characters or Greek letters in the labels, use TeX markup, such as \pi for the π symbol
yticks([-1 -0.8 -0.2 0 0.2 0.8 1])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kPt3NZLY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmbxwwbvpbxr8bm22fv6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kPt3NZLY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmbxwwbvpbxr8bm22fv6.png" alt="Image description" width="691" height="588"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>matlab</category>
      <category>computerscience</category>
      <category>tutorial</category>
      <category>plots</category>
    </item>
    <item>
      <title>Matlab matrix-basics cheatsheet</title>
      <dc:creator>sofaki000</dc:creator>
      <pubDate>Sat, 20 Nov 2021 09:26:22 +0000</pubDate>
      <link>https://dev.to/sofaki000/matlab-basics-cheatsheet-5774</link>
      <guid>https://dev.to/sofaki000/matlab-basics-cheatsheet-5774</guid>
      <description>&lt;h3&gt;
  
  
  Matlab basics
&lt;/h3&gt;

&lt;p&gt;MATLAB is an abbreviation for "matrix laboratory." While other programming languages mostly work with numbers one at a time, MATLAB is designed to operate primarily on whole matrices and arrays.&lt;/p&gt;

&lt;p&gt;All MATLAB variables are &lt;em&gt;multidimensional arrays&lt;/em&gt;, no matter what type of data. A matrix is a &lt;em&gt;two-dimensional array&lt;/em&gt; often used for linear algebra.&lt;/p&gt;

&lt;p&gt;To create an array with four elements in a single row, separate the elements with either a comma (,) or a space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = [1 2 3 4]
result:
a = 1×4

     1     2     3     4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To create a matrix that has multiple rows, separate the rows with semicolons.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = [1 3 5; 2 4 6; 7 8 10]
a = 3×3

     1     3     5
     2     4     6
     7     8    10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another way to create a matrix is to use a function, such as ones, zeros, or rand. For example, create a 5-by-1 column vector of zeros.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;z = zeros(5,1)

z = 5×1

     0
     0
     0
     0
     0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The matrix operators for multiplication, division, and power each have a corresponding array operator that operates element-wise. For example, raise each element of a to the third power:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a.^3
ans = 3×3

           1          27         125
           8          64         216
         343         512        1000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dot (.) is used to access each individual element of the matrix.&lt;/p&gt;

&lt;p&gt;ex: a.^3 -&amp;gt; take each element of a matrix and raise it to the third power.&lt;/p&gt;




&lt;h3&gt;
  
  
  Accessing elements in the array
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]
A = 4×4

     1     2     3     4
     5     6     7     8
     9    10    11    12
    13    14    15    16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are two ways to refer to a particular element in an array. The most common way is to specify row and column subscripts, such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A(4,2)= 14
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Less common, but sometimes useful, is to use a single subscript that traverses down each column in order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A(8) = 14
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To refer to multiple elements of an array, use the &lt;em&gt;colon operator&lt;/em&gt;, which allows you to specify a range of the form start:end. For example, list the elements in the first three rows and the second column of A:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A(1:3,2)
ans = 3×1

     2
     6
    10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The colon alone, without start or end values, specifies all of the elements in that dimension. For example, select all the columns in the third row of A:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A(3,:)
ans = 1×5

     9    10    11    12     0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Clearing environment
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;clc&lt;/strong&gt; = clears command window&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;clear&lt;/strong&gt; = Remove items from workspace, freeing up system memory&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  For reproducibility
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;rng default&lt;/strong&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
When Matlab generates random numbers, they're not truly random; they are based on a pseudo-random number generating algorithm. The rng command controls the seed, or starting point, for this value. The "default" values resets it to the original value that MATLAB starts with; this evolves over time.&lt;br&gt;
You can see this behaviour if you do something like called rand(10,1), then calling rng('default') then repeating the rand command. It will generate exactly the same "random" numbers.&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

</description>
      <category>matlab</category>
      <category>computerscience</category>
      <category>cheatsheet</category>
    </item>
    <item>
      <title>OpenCilk tutorial</title>
      <dc:creator>sofaki000</dc:creator>
      <pubDate>Mon, 15 Nov 2021 11:41:53 +0000</pubDate>
      <link>https://dev.to/sofaki000/opencilk-tutorial-4ich</link>
      <guid>https://dev.to/sofaki000/opencilk-tutorial-4ich</guid>
      <description>&lt;p&gt;What is Parallel Programming?&lt;/p&gt;

&lt;p&gt;In very simple terms, it is the use of multiple resources, in this case, processors, to solve a problem. This type of programming takes a problem, breaks it down into a series of smaller steps, delivers instructions, and processors execute the solutions at the same time.It is also a form of programming that offers the same results as concurrent programming but in less time and with more efficiency.&lt;/p&gt;

&lt;p&gt;OpenCilk tutorial&lt;/p&gt;

&lt;p&gt;Be aware that opencilk doesn't work for windows.&lt;br&gt;
First we will download the docker image:&lt;/p&gt;

&lt;p&gt;1)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://github.com/OpenCilk/opencilk-project/releases/download/opencilk%2Fv1.0/docker-opencilk-v1.0.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then load the image :(which loads the image from a tar archive. It restores both images and tags.)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker load &amp;lt; docker-opencilk-v1.0.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Run a simple c program to confirm opencilk is installed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#define cilk_spawn _Cilk_spawn // the includes neccessary for openCilk
#define cilk_sync  _Cilk_sync
#define cilk_for   _Cilk_for

int main(){
printf("Hello world");
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3)Quick overview:&lt;br&gt;
Cilk extends C and C++ with three keywords: cilk_spawn, cilk_sync, and cilk_for&lt;/p&gt;

&lt;p&gt;cilk_spawn and cilk_sync:&lt;/p&gt;

&lt;p&gt;example 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int64_t fib(int64_t n) {
  if (n &amp;lt; 2) return n;
  int x, y;
  x = cilk_spawn fib(n - 1);
  y = fib(n - 2);
  cilk_sync;
  return x + y;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the usage of cilk_spawn, parallel work is created when cilk_spawn precedes the invocation of a function, thereby causing the function to be spawned.The code immediately following the spawn — is allowed to execute in parallel with the child, instead of waiting for the child to complete as is done in C/C++.&lt;br&gt;
In the example fib function, the cilk_spawn spawns the recursive invocation of fib(n-1), allowing it to execute in parallel with its continuation, which calls fib(n-2).&lt;br&gt;
The cilk_sync is a local "barrier," not a global one as. In fib, the cilk_sync prevents the execution of fib from continuing past the cilk_sync until the spawned invocation of fib(n-1) has returned.&lt;/p&gt;

&lt;p&gt;cilk_for:&lt;br&gt;
example 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void daxpy(int n, double a, double *x, double *y) {
 cilk_for (int i = 0; i &amp;lt; n; ++i) {
    y[i] = a * x[i] + y[i];
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cilk_for parallel-loop construct indicates that all iterations of the loop are allowed to execute in parallel. At runtime, these iterations can execute in any order, at the discretion of the runtime scheduler.&lt;/p&gt;

&lt;p&gt;example 2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void mm(const double *restrict A,
        const double *restrict B,
        double *restrict C,
        int64_t n) {
  cilk_for (int64_t i = 0; i &amp;lt; n; ++i) {
    cilk_for (int64_t j = 0; j &amp;lt; n; ++j) {
      for (int64_t k = 0; k &amp;lt; n; ++k) {
        C[i*n + j] += A[i*n + k] * B[k*n + j];
      }
    }
  }
}
```



To sum up, a good start would be using cilk_for to replace all the for in your synchronous code. Also using cilk_spawn and cilk_sync
for all your recursive calls.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>opencilk</category>
      <category>tutorial</category>
      <category>parallelprogramming</category>
      <category>threads</category>
    </item>
  </channel>
</rss>
