Category Archives: Programming

Numerical Jacobian matrix calculation method with matlab code

In this post, I share a numerical Jacobian matrix calculation method with matlab code.

Actually there is a function in Matlab inherently, but it is very complex. ( look at the function, NumJac ), So I made a very simple version. I wish this can help you.

You can download from here.

The attachment file includes 

1. NumJacob.m : main file it generates jacobian matrix. 

2. Demo.m : demo file

3. test_func.m : test function to show its demo

 

The below is a simple example.

>> NumJacob(@cos,1)

ans =

-0.8415

 

>> x0=[0;1]; other_param=[1;2];
>> df=NumJacob(@test_func,x0,other_param)

df =

1.0000 0
0 2.0000

 

 

Because the code is very easy, probably you can easily understand the codes.

Then, good luck ^^

if you have any question, please leave me a comment below.

 

Added on Feb 07. 2014

I am uploading another demo file to give a solution of Mahmudul’s request (for detail, see the comment).

This demo file is to get a numerical Jacobian for the below function

y1′ = y2*y3; y1(0) = 0
y2′ = -y1*y3; y2(0) = 1
y3′ = -0.51*y1*y3; y3(0) =1

Download this demo file. 

 

Added on Mar/21 2015

If you are interested in calculating numerical Jocobian matrix for a complex number, please read this post.

http://youngmok.com/matlab-code-for-numerical-calculation-of-jacobian-matrix-for-a-complex-number/

 

—————————————————————————————————

I am Youngmok Yun, and writing about robotics theories and my research.

My main site is http://youngmok.com, and Korean ver. is  http://yunyoungmok.tistory.com.

—————————————————————————————————

 

 

 

Parallel computation with Matlab, SPMD. Explanation with simple example code

Today I’d like to introduce a parallel computation skill in Matlab.

I also heard that the use of parallel computation in Matlab is very easy. But it was better than my expectation. Wonderful!! Smile

You need to know the usage of SPMD. It is pretty easy.

First let’s the code, you can also download this file in the attachment, click <here>.
parallel_computation_spmd

 

The result is the below

Starting matlabpool using the ‘local’ configuration … connected to 4 labs.
Elapsed time is 120.482356 seconds.
Sending a stop signal to all the labs … stopped.
Elapsed time is 167.796932 seconds.

Because, I did many other works in the calculation time, Its result is not very fast, The slowest CPU core determined the final computation time. But its performance is really good if you have more than 4 multi cpu cores.

I wish this post can help your understanding about the use of SPMD in Matlab.

if you have any question, please leave me a comment below.

—————————————————————————————————

I am Youngmok Yun, and writing about robotics theories and my research.

My main site is http://youngmok.com, and Korean ver. is  http://yunyoungmok.tistory.com.

—————————————————————————————————