Sunday, June 27, 2021

Engineering Economy with Octave in real world

โดย ผศ.สราวุฎฐ์ วรสุมันต์ , ประยุทธ พันธุลาภ

Background


1) โรงงานแปรรูปไก่ขนาดใหญ่ที่ลดพนักงาน [video click]

2) โรงงานแปรรูปไก่ขนาดใหญ่ที่ใช้พนักงานค่อนข้างมาก [video click]

3) แปรรูปไก่ที่ใช้อุปกรณ์ไม่ซับซ้อน กำลังผลิตไม่มาก [video click]

"การลดจำนวนแรงงานต่างชาติ เป็นปัญหาใหญ่ที่เกิดใน ยุโรปมานานแล้ว จนในที่สุดต้องออกแบบเครื่องจักรอัตโนมัติมาทำงานแทน ในปัจจุบันโรคระบาดเป็นปัจจัยสำคัญที่ต้องนำมาใช้วิเคราะห์ในการลงทุนด้วย ซึ่งมีหลายประเด็นใน ศตวรรษที่ 21 วิชา Engineering Economy ในสมัยก่อนไม่ได้คำนึงถึงในโลกความจริง ทำให้นำวิชานี้ไปใช้ในโลกความจริงไม่ได้ผล"


Octave Online

website rextester

Lessons

Lesson 0 : About students
Lesson 1 : Equivalence & Interest
Lesson 2 : Cash Flows & Compound Interest
Lesson 3 : Multiple Cash Flows
Lesson 4 : Payback Period
Lesson 5 : Present - Worth Comparisons
Lesson 6 : Future - Worth & Equivalent Annual Worth Comparisons
Lesson 7 : Rate of Return Analysis
Lesson 8 : Rate Of Return Comparisons
Lesson 9 : Benefit / Cost Ratios
Lesson 10 : Comparison & Review Bonds
Lesson 11 : Basic Depreciation
Lesson 12 : MACRS Depreciation & Capital Gains
Lesson 13 : After Tax Cash Flow
Lesson 14 : Replacement Analysis
Lesson 15 : Inflation


Formulas

   A is a uniform series of equal payments at each compounding period;
   P is a present single sum of money at the time zero;
   F is a future sum of money at the end of period n. And i is the compound interest rate.
   i is the compound interest rate
   n is the period.



Introduction

Compound and Discount Concept

Compounding

In order to compare different alternatives in an economic evaluation, they should have the same base (equivalent base). 

Compound interest is a method that can help applying the time value of money. 

For example, assume you have 100 dollars now and you put it in a bank for interest rate of 3% per year. 

After one year, the bank will pay you 100+100*0.03 =$103. Then, you will put the 103 dollars in the bank again for another year. 

One year later, you will have 103+103*0.03 =$106.09. 

   P: Present single sum of money.
   F: A future single sum of money at some designated future date.
   n: The number of periods in the project evaluation life (can be year, quarter or month).
   i: The discount rate (interest rate).

F = P(1+i)n


Example 1-1:

Assume you put 20,000 dollars (principal) in a bank for the interest rate of 4%. 

How much money will the bank give you after 10 years?

F=P(1+i)n =20,000*(1+0.04)10=20,000*1.48024=29604.8


Discounting

In economic evaluations, “discounted” is equivalent to “present value” or “present worth” of money.
P = F(1+i)-n

   P: Present single sum of money.
   F: A future single sum of money at some designated future date.
   n: The number of periods in the project evaluation life (can be year, quarter or month).
   i: The discount rate (interest rate).

  
Example 1-2:

Assuming the discount rate of 10 %, present value of 100 dollars
which will be received in 5 years from now can be calculated as:
F = 100 dollars n = 5 i = 0.1 P = F[(1 + i)-n] = 100[(1 + 0.1)-5] = 62.1 You can see how time and discount rate can affect the value of money in the future. 62.1 dollars is the equivalent present sum that has the same value of 100 dollars in five years under the discount rate of 10%

Formulas in Octave

Octave Code

%============== copy Formulas =============
%============== start of library ==========
%%====================================
%% Engineering Economy Formula
%%====================================


function v = npv (r, p, i)

  if (nargin < 2 || nargin > 3)
    print_usage ();
  endif

  if (! (isvector (p)))
    error ("npv: p has to be a vector");
  else
    n = length (p);
    p = reshape (p, 1, n);
  endif

  if (any (any (r <= -1)))
    error ("npv: all interest rates must be > -1");
  endif
  if (isscalar (r))
    d = 1 ./ (1 + r) .^ (0 : n);
  elseif (isvector (r) && (length (r) == n))
    d = [1, (1 ./ cumprod (reshape (1 + r, 1, n)))];
  else
    error ("npv: r must be a scalar or a vector of the same length as p");
  endif

  if (nargin == 3)
    if (! isscalar (i))
      error ("npv: I_0 must be a scalar");
    endif
  else
    i = 0;
  endif

  p = [i, p];
  v = sum (d .* p);

endfunction


function r = irr (p, i = 0)
  ## Check input
  if (nargin != 1 && nargin != 2)
    print_usage ();
  elseif (! (isvector (p)))
    error ("irr: p must be a vector");
  elseif (! isscalar (i))
    error ("irr: i must be a scalar");
  endif

  ## Solve system
  f = @(x) npv (x, p) - i;
  r = fsolve (f, 0);

endfunction


function p = pmt (r, n, a, l, m)

  if (nargin < 3 || nargin > 5)
    print_usage ();
  endif

  if (! (isscalar (r) && r > -1))
    error ("pmt: rate must be a scalar > -1");
  elseif (! (isscalar (n) && n > 0))
    error ("pmt: n must be a positive scalar");
  elseif (! (isscalar (a) && a > 0))
    error ("pmt: a must be a positive scalar");
  endif

  if (nargin == 5)
    if (! ischar (m))
      error ("pmt: `method' must be a string");
    endif
  elseif (nargin == 4)
    if (ischar (l))
      m = l;
      l = 0;
    else
      m = "e";
    endif
  else
    l = 0;
    m = "e";
  endif

  p = r * (a - l * (1 + r)^(-n)) / (1 - (1 + r)^(-n));

  if (strcmp (m, "b"))
    p = p / (1 + r);
  endif

endfunction



function v = pv (r, n, p, l, m)

  if (nargin < 3 || nargin > 5)
    print_usage ();
  endif

  if (! (isscalar (r) && r > -1))
    error ("pv: r must be a scalar > -1");
  elseif (! (isscalar (n) && n > 0))
    error ("pv: n must be a positive scalar");
  elseif (! isscalar (p))
    error ("pv: p must be a scalar");
  endif

  if (r != 0)
    v = p * (1 - (1 + r)^(-n)) / r;
  else
    v = p * n;
  endif

  if (nargin > 3)
    if (nargin == 5)
      if (! ischar (m))
        error ("pv: `method' must be a string");
      endif
    elseif (ischar (l))
      m = l;
      l = 0;
    else
      m = "e";
    endif
    if (strcmp (m, "b"))
      v = v * (1 + r);
    endif
    if (isscalar (l))
      v = v + pvl (r, n, l);
    else
      error ("pv: l must be a scalar");
    endif
  endif

endfunction

function v = npv (r, p, i)

  if (nargin < 2 || nargin > 3)
    print_usage ();
  endif

  if (! (isvector (p)))
    error ("npv: p has to be a vector");
  else
    n = length (p);
    p = reshape (p, 1, n);
  endif

  if (any (any (r <= -1)))
    error ("npv: all interest rates must be > -1");
  endif
  if (isscalar (r))
    d = 1 ./ (1 + r) .^ (0 : n);
  elseif (isvector (r) && (length (r) == n))
    d = [1, (1 ./ cumprod (reshape (1 + r, 1, n)))];
  else
    error ("npv: r must be a scalar or a vector of the same length as p");
  endif

  if (nargin == 3)
    if (! isscalar (i))
      error ("npv: I_0 must be a scalar");
    endif
  else
    i = 0;
  endif

  p = [i, p];
  v = sum (d .* p);

endfunction


function v = fv (r, n, p, l, m)

  if (nargin < 3 || nargin > 5)
    print_usage ();
  endif

  if (! (isscalar (r) && r > -1))
    error ("fv: r must be a scalar > -1");
  elseif (! (isscalar (n) && n > 0))
    error ("fv: n must be a positive scalar");
  elseif (! isscalar (p))
    error ("fv: p must be a scalar");
  endif

  if (r != 0)
    v = p * ((1 + r)^n - 1) / r;
  else
    v = p * n;
  endif

  if (nargin > 3)
    if (nargin == 5)
      if (! ischar (m))
        error ("fv: `method' must be a string");
      endif
    elseif ischar (l)
      m = l;
      l = 0;
    else
      m = "e";
    endif
    if strcmp (m, "b")
      v = v * (1 + r);
    endif
    if isscalar (l)
      v = v + fvl (r, n, l);
    else
      error ("fv: l must be a scalar");
    endif
  endif

endfunction

%%====================================
%% Engineering Economy Basic Formulas
%%====================================
%P/F
function p = f_p(i ,n)
   p = ((1 + i)^n );
endfunction

%F/P
function f = p_f(i ,n)
   f = ((1 + i)^-n );
endfunction

%F/A
function f = f_a(i ,n)
   v = ((1 + i)^n );
   f = (v - 1) / i;
endfunction

%A/F
function a = a_f(i ,n)
   a = 1 / f_a(i ,n);
endfunction


%P/A
function v = p_a(i ,n)
   v = ((1 + i)^n );
   v = (v - 1) / i;
   v = v / ((1 + i)^n );
endfunction

%A/P
function a = a_p(i ,n)
   a = 1 / p_a(i ,n);
endfunction


%============== end of library ==========

%========================================




Week#1

%%==================================== %% Engineering Economy Basic Formulas %%==================================== %P/F function p = f_p(i ,n) p = ((1 + i)^n ); endfunction %F/P function f = p_f(i ,n) f = ((1 + i)^-n ); endfunction %F/A function f = f_a(i ,n) v = ((1 + i)^n ); f = (v - 1) / i; endfunction %A/F function a = a_f(i ,n) a = 1 / f_a(i ,n); endfunction %P/A function v = p_a(i ,n) v = ((1 + i)^n ); v = (v - 1) / i; v = v / ((1 + i)^n ); endfunction %A/P function a = a_p(i ,n) a = 1 / p_a(i ,n); endfunction %============start of Examples=========== %=========Example#1====================== %%https://www.e-education.psu.edu/eme460/node/654 % A is a uniform series of equal payments at each compounding period; % P is a present single sum of money at the time zero; % F is a future sum of money at the end of period n. And i is the compound interest rate. % i is the compound interest rate % n is the period. disp("=========Example 1-1=========") %Assume you put 20,000 dollars (principal) in a bank for the interest rate of 4%. %How much money will the bank give you after 10 years? n = 10 i = 4/100 p = 20000 f = p * f_p(i ,n); printf("F = %10.2f\n",f) %disp("===================") disp("=========Example 1-2=========") % Assuming the discount rate of 10 %, present value of 100 dollars
% which will be received in 5 years from now can be calculated as: n = 5 i = 10/100 f = 100 p = f * p_f(i ,n); printf("P = %10.2f\n",p) %disp("===================") disp("=========Example 1-2-1=========") % Assuming the interest rate of 10 %, present value of 10,000 dollars % How many years from now it will be double in value: i = 10/100 p = 10000 for n = 1:10 f = p * f_p(i ,n); printf("n= %d : F = %10.2f\n",n,f) if f > (2*p) break endif endfor %disp("===================") disp("=========Example 1-3=========") n = 20 i = 6/100 a = 4000 f = a * f_a(i ,n); printf("F = %10.2f\n",f) %disp("===================") disp("=========Example 1-4=========") n = 20 i = 6/100 f = 200000 a = f * a_f(i ,n); printf("A = %10.2f\n",a) %disp("===================") disp("=========Example 1-5=========") n = 10 i = 12/100 a = 2000 p = a * p_a(i ,n); printf("P = %10.2f\n",p) %disp("===================") disp("=========Example 1-6=========") p = 25000 i =4/100 n = 5 A = p * a_p(i,n); printf("A = %10.2f\n",A) %disp("===================") disp("=========Example 1-7=========") i = 8/100 P = 1000 * p_f(i,1)+ 1500 * p_f(i,2)+ 1800 * p_f(i,3)+ 1200 * p_f(i,4)+ 2000 * p_f(i,5) disp("===================")

Free Sofwares for SME

by ประยุทธ พันธุลาภ

WPS Office Personal

WPS Office Personal is available in Free, Premium, and Professional versions, along with versions for Android and iOS. The free version provides basic features and supports Microsoft Office file formats. Some features, such as printing and mail-merge, can be temporarily accessed only after viewing an advertisement, which WPS Office refers to as sponsored access
  

Libre Office

LibreOffice is offered in a free and open source "Community" version officially intended for personal use. This is the full suite, not a cut-down version. Enterprise-supported versions of LibreOffice can also be obtained from TDF's corporate partners.
  

NanoCAD

Free version nanoCAD 5.0 32bit for CAD 2D
Videos Tutorial
NanoCAD free download and install
Part 1
Part 2
Part 3
nanoCAD india channel
  

Paint.net

Paint.net is a freeware raster graphics editor program for Microsoft Windows, alternative for Photoshop developed on the .NET Framework.

Plugins
BoltBait's Plugin Pack
dpys Plugin Pack

All Plugin Packs
All plugins

Videos Tutorial
Tutorials
  

Project Libre

Free and simple Project Gantt Chart
Videos Tutorial
ProjectLibre Tutorial Channel
  

imagetopdf

On-line convert image files to PDF file
  

PDF Fill FREE Basic Version

Free PDF Tools
  

Inkscape

Inkscape is a free and open-source vector graphics editor used to create vector images, primarily in Scalable Vector Graphics (SVG) format. Other formats can be imported and exported.
  

Photo Scape

Everything you need to edit photos.
PhotoScape X is an all-in-one photo editing software which provides photo-related features such as Photo Viewer, Editor, Cut Out, Batch, Collage, Combine, Create GIF, Color Picker, Screen Capture, RAW images and More.
  

GIMP

The Free & Open Source Image Editor.
GIMP is a high quality framework for scripted image manipulation, with multi-language support such as C, C++, Perl, Python, Scheme, and more!

Flexsim Express

The Free 3D Simulation Assembly Line Process
FlexSim Express is available for anybody to use. It’s a 100% free evaluation version of our simulation software, allowing you to model a system with 30 or fewer objects. There are no time restrictions, but it can only be used to evaluate and test FlexSim’s capabilities.

Sketchup Make 2017

Currently SketchUp is the best software for 3D modelling which is equipped with loads of features which are unavailable in alternative software. And requiring low performance while working very smooth is great. Some complications will occur if you do complex designs but for general purposes this is the best. Can be used even by a beginner without facing issues.

Saturday, June 6, 2020

Ruby API for Civil Engineer

โดย ผศ.สราวุฎฐ์ วรสุมันต์ , ประยุทธ พันธุลาภ

Please Click on QR code to register for the class MIDTERM Examination

QR Code for JotForm form


Week 10

 

Week 7


*******************************
Midterm Examination
Download 2 files
week51.rb
offset.rb
--------------------------------------
and save into folder C:\QTOOLS\API
Run Sketchup
in Ruby console
load "C:\\QTOOLS\\API\\week51.rb" *******************************

Midterm Question


From menu choose Create building use parameters of yours from above table

Show/Hide Layer for my_column and beam

Delete guides after create building

BOQ mmenu

Please Click on QR code to register for the class MIDTERM Examination

QR Code for JotForm form

Notepad++ v.5.5

  1. Create folder C:\QTOOLS\API\ to store all learning materials
  2. Link download API
  3. Unnzip into folder above


  4. Goto folder C:\QTOOLS\API\SketchupAPI\npp55\

    Run file C:\QTOOLS\API\SketchupAPI\npp55\npp.5.5.Installer.exe

    Copy file C:\QTOOLS\API\SketchupAPI\ruby.xml
    into folder C:\Program Files (x86)\Notepad++\plugins\APIs\


Ruby Language References

Link to web site

Week 4

# load "C:\\QTOOLS\\API\\week4.rb"
#load others rb files
load "C:\\QTOOLS\\API\\week2.rb"
load "C:\\QTOOLS\\API\\week3.rb"

def test
  p "week4"

end

def add_point
 pt = Geom::Point3d.new(10.m,0,0) #create new point
 model = Sketchup.active_model
 model.entities.add_cpoint(pt) #add into model
end

def add_line
 pt1 = Geom::Point3d.new(0,0,0)
 pt2 = Geom::Point3d.new(10.m,20.m,4.m)
 model = Sketchup.active_model
 model.entities.add_line pt1,pt2

end


def add_face
 pt1 = Geom::Point3d.new(0,0,0)
 pt2 = Geom::Point3d.new(10.m,20.m,0)
 pt3 = Geom::Point3d.new(0,20.m,0)
 
 model = Sketchup.active_model
 model.entities.add_face(pt1, pt2, pt3)

end


def add_room
 pt1 = Geom::Point3d.new(0,0,0)
 pt2 = Geom::Point3d.new(4.m,0,0)
 pt3 = Geom::Point3d.new(4.m,5.m,0)
 pt4 = Geom::Point3d.new(0,5.m,0)
 model = Sketchup.active_model
 face = model.entities.add_face(pt1, pt2, pt3, pt4)
 face.pushpull 10.cm
end

def group_add_room
 pt1 = Geom::Point3d.new(0,0,0)
 pt2 = Geom::Point3d.new(4.m,0,0)
 pt3 = Geom::Point3d.new(4.m,5.m,0)
 pt4 = Geom::Point3d.new(0,5.m,0)
 model = Sketchup.active_model
 group = model.entities.add_group
 face = group.entities.add_face(pt1, pt2, pt3, pt4)
 face.pushpull 10.cm
end



def rotate1
 model = Sketchup.active_model; selection = model.selection; entity = selection[0];
 angle = 45.degrees #radians
 vector = Geom::Vector3d.new(0,0,1) #Z axis
 point = Geom::Point3d.new(0,0,0) #origin
 tr_rotate = Geom::Transformation.rotation point, vector, angle
 entity.transform!(tr_rotate)
end

def move1
 model = Sketchup.active_model; selection = model.selection; entity = selection[0];
 #tr_vector = Geom::Vector3d.new(10.m,2.m,0)
 tr_vector = Geom::Point3d.new(4.m,0,0) - Geom::Point3d.new(0,0,0)
 tr_move = Geom::Transformation.translation tr_vector
 entity.transform!(tr_move)
end

def scale1
 model = Sketchup.active_model; selection = model.selection; entity = selection[0];
 xscale = 2
 yscale = 2 
 zscale = 1
 point = Geom::Point3d.new(1.m,0,0) #change ref. point
 tr_scale = Geom::Transformation.scaling point, xscale, yscale, zscale
 entity.transform!(tr_scale)

end


def grid1
 arr_x = [3,4,5]
 arr_y = [6,7]
 point = Geom::Point3d.new(0,0,0)
 ix = 0 
 iy = 0
 arr_x.each{|dx| 
  puts dx; 
  p "======"
 }#arr_x
end

def grid11
 arr_x = [3,4,5]
 arr_y = [6,7]
 point = Geom::Point3d.new(0,0,0)
 ix = 0 
 iy = 0
 arr_x.each{|dx| 
  puts dx; 
  p "======"
  arr_y.each{|dy|
   puts dy; 
   p "*****"
  }#arr_y
 }#arr_x
end

def grid12
 arr_x = [3,4,5]
 arr_y = [6,7]
 point = Geom::Point3d.new(0,0,0)
 ix = 0 
 iy = 0
 point_row = point #ref. point
 model = Sketchup.active_model
 arr_x.each{|dx| 
  puts dx; 
  p "======"
  pt2 = point_row.offset Geom::Vector3d.new(dx.m,0,0)
  model.entities.add_cpoint(pt2) #add cpoint
  point_row  = pt2 #change ref. point to pt2
  
 } #arr_x
end

def grid13
 arr_x = [0,3,4,5]
 arr_y = [0,6,7]
 point_ver = Geom::Point3d.new(10.m,20.m,0)
 ix = 0 
 iy = 0
 point_row = point_ver #ref. point
 model = Sketchup.active_model
 arr_y.each{|dy|
  point_ver = point_ver.offset Geom::Vector3d.new(0,-dy.m,0)
  point_row = point_ver #ref. point
  arr_x.each{|dx| 
   puts dx; 
   p "======"
   pt2 = point_row.offset Geom::Vector3d.new(dx.m,0,0)
   model.entities.add_cpoint(pt2) #add cpoint
   point_row  = pt2 #change ref. point to pt2
   
  }#arr_x

 } #arr_y 
end

def grid14
 arr_x = [0,3,4,5]
 arr_y = [0,6,7]
 point_ver = Geom::Point3d.new(10.m,20.m,0)
 ix = 0 
 iy = 0
 point_row = point_ver #ref. point
 model = Sketchup.active_model
 #model.start_operation( "Make Grid" , true)
 arr_y.each{|dy|
  point_ver = point_ver.offset Geom::Vector3d.new(0,-dy.m,0)
  point_row = point_ver #ref. point
  arr_x.each{|dx| 
   puts dx; 
   p "======"
   pt2 = point_row.offset Geom::Vector3d.new(dx.m,0,0)
   
   make_column1(pt2) #add column
   
   model.entities.add_cpoint(pt2) #add cpoint
   point_row  = pt2 #change ref. point to pt2
   
  }#arr_x

 } #arr_y 
 #model.commit_operation
end


def make_column1(pt) #parameters
 #dimension of Column
 dx = 0.4.m
 dy = 0.3.m
 dz = 3.m
 #create points
 #pt1 = pt
 pt1 = pt.offset Geom::Vector3d.new((dx * -0.5) ,(dy * -0.5),0)  #adjust center point of column
 pt2 = pt1.offset Geom::Vector3d.new(dx,0,0)
 pt3 = pt2.offset Geom::Vector3d.new(0,dy,0)
 pt4 = pt1.offset Geom::Vector3d.new(0,dy,0)
 #create object column
 model = Sketchup.active_model
 group = model.entities.add_group
 face = group.entities.add_face(pt1, pt2, pt3, pt4)
 face.pushpull -dz
 #add layer  
 layer = model.layers.add "my_column"
 #change layer of group 
 group.layer = layer 

end


def count_group
 model = Sketchup.active_model;   
 selection = model.selection;   
 arr = [];   
 selection.each{|entity| arr.push entity } 
 count = 0
 arr.each{|entity| 
  if (entity.class == Sketchup::Group);  
   group = entity; 
   count = count + 1
  end
 }
 p "group count =" + count.to_s
 p ""

end










Week 3

%Steel in building parts
Steel in Column
# load "C:\\QTOOLS\\API\\week3.rb"

def test
  p "week3"

end


def make_column
 #dimension of Column
 dx = 0.4.m
 dy = 0.3.m
 dz = 3.m
 #create points
 pt1 = Geom::Point3d.new(0,0,0)
 pt2 = pt1.offset Geom::Vector3d.new(dx,0,0)
 pt3 = pt2.offset Geom::Vector3d.new(0,dy,0)
 pt4 = pt1.offset Geom::Vector3d.new(0,dy,0)
 #create object column
 model = Sketchup.active_model
 group = model.entities.add_group
 face = group.entities.add_face(pt1, pt2, pt3, pt4)
 face.pushpull -dz
 #add layer  
 layer = model.layers.add "my_column"
 #change layer of group 
 group.layer = layer 

end


def make_beam 
 #dimension of Column
 dx = 4.m
 dy = 0.2.m
 dz = 0.4.m
 angle = 0.degrees #rotation angle
 #create points
 pt1 = Geom::Point3d.new(0,0,0)
 pt2 = pt1.offset Geom::Vector3d.new(dx,0,0)
 pt3 = pt2.offset Geom::Vector3d.new(0,dy,0)
 pt4 = pt1.offset Geom::Vector3d.new(0,dy,0)
 #create object column
 model = Sketchup.active_model
 group = model.entities.add_group
 face = group.entities.add_face(pt1, pt2, pt3, pt4)
 face.pushpull dz
 tr_rotate = Geom::Transformation.rotation pt1, Geom::Vector3d.new(0,0,1), angle
 group.transform!(tr_rotate)
 #add layer 
 layer = model.layers.add "my_beam"
 #change layer of group
 group.layer = layer

end

def move_object
 #parameters from user
 prompts = ["dx [m.]" , "dy [m.]" , "dz [m.]"];  
 defaults = ["1" , "1" , "1"]; 
 input = UI.inputbox prompts, defaults,  "Enter dx,dy,dz." #return as array
  #distance of be move
  dx = input[0].to_f.m
  dy = input[1].to_f.m
  dz = input[2].to_f.m
 model = Sketchup.active_model; selection = model.selection; entity = selection[0];
 tr_vector = Geom::Vector3d.new(dx,dy,dz)
 tr_move = Geom::Transformation.translation tr_vector
 entity.transform!(tr_move)
end






Week 2

Download file boq1.skp and save in folder C:\QTOOLS\API\


Week 1:Basic Sketchup And Ruby API

Objectives:
1.Understand Sketchup's basic model concept edge , face, group, component
2.Understand relation between Sketchup model and Ruby API
3.How to count objects ,edges , faces, groups, components, in model with its properties such as length , area
# load "C:\\QTOOLS\\API\\week1.rb"

def count_object
 model = Sketchup.active_model; selection = model.selection; entity = selection[0];
 if (entity.class == Sketchup::Edge);  
  edge = entity; 
  p edge
 end
 if (entity.class == Sketchup::Face);  
  face = entity;  
  p face
 end
 if (entity.class == Sketchup::Group);  
  group = entity; 
  p group
 end
 if (entity.class == Sketchup::ComponentInstance); 
  component = entity;  
  p component
 end
end


End of Week 1

Sunday, September 8, 2019

C and Octave Programming

151-xxx Programming Mechanical Engineer

โดย ผศ.สราวุฎฐ์ วรสุมันต์ , ประยุทธ พันธุลาภ

Heat Transfer

Thermal conductivity of some selected gases, insulation products, aluminum, asphalt, brass, copper, steel and other common materials

Viscosity of Water

Viscosity of Water

Advance Topics

Numerical solutions with GNU OCTAVE

Octave and C compiler on-line

Click here to run -> rextester.com

Loop Flow Chart

ข้อสอบ กว


%Example 1

t = 0:0.1:6.3;
plot (t, cos(t), "-;cos(t);", t, sin(t*0.5), "-b;sin(t);");
print -dpng some_name.png;


%Example 2
x=1:0.1:10;
plot(x, sin(x));
print -dpng some_name.png;


%Example 3
A = [3,12; 4,2;]
C = [15; 6;]
x = inv(A)*C

%Example 4 Hydro static
rho = 1000 %kg/cu.m.
g = 9.81 %m/s2

h = 20 %m

p = rho * g * h %N/sq.m





ข้อสอบ กว



Example 05

%*****Reaction at simple beam

printf("Student No.2\n")
printf("**************\n")

F1 = 150  %KN
L = 6 %m
L1 = 1 %m  
L2 = L - L1
A = [1,1; L, 0;]
F = [F1; (L2*F1);]

R = inv(A)*F

printf("R1 = %6.3f\n",R(1))
printf("R2 = %6.3f\n",R(2))



Example 06

%****Cantiliver Beam

printf("Student No.1\n")
printf("**************\n")

F1 = 300  %KN
L = 2 %m
A = [1,0; 0, 1;]
F = [F1; (L*F1);]

R = inv(A)*F

printf("RY = %6.3f  KN\n",R(1))
printf("MA = %6.3f  KN.m\n",R(2))


Example 07 -->

%*****Reaction at simple beam F1 F2

printf("Student No.2\n")
printf("**************\n")

F1 = 100  %KN
F2 = 50 %KN
L = 6 %m
L1 = 1 %m  
L2 = 1.2 %m
FT = F1 + F2   %total force
MT = (L1*F1) + ((L1+L2)*F2)   %total moment
A = [1,1; 0, L;]
F = [FT; MT;]

R = inv(A)*F

printf("R1 = %6.3f\n",R(1))
printf("R2 = %6.3f\n",R(2))


Example 08

%*****Reaction at Cantilever Beam F1 F2

printf("Student No.2\n")
printf("**************\n")

F1 = 100  %KN
F2 = 50 %KN
L = 6 %m
L1 = 1 %m  

FT = F1 + F2   %total force
MT = (L*F1) + (L1*F2)   %total moment
A = [1,0; 0,1;]
F = [FT; MT;]

R = inv(A)*F

printf("RY = %6.3f\n",R(1))
printf("MA = %6.3f\n",R(2))


Example 09
%****Ex 9. Solve Matrix

printf("Student No.2\n")
printf("**************\n")
printf("**Solve Matrix***\n")
printf("**************\n")

A = [
-4, -11, 5, -5;
-11, -8, 10, -9;
-5, -5, 8, -7;
-2, -3, 8, -4;
]
F = [
-165;
-258;
-149;
-69;
]
disp "***********************"

R = inv(A)*F

printf("a = %6.3f \n",R(1))
printf("b = %6.3f \n",R(2))
printf("c = %6.3f \n",R(3))
printf("d = %6.3f \n",R(4))




#include <stdio.h>

int main()
{
    int number;
   
    printf("Enter an integer: ");  
    
    // reads and stores input
    scanf("%d", &number);
    // displays output
    printf("You entered: %d", number);
    
    return 0;
}



  • -โครงสร้างของคอมพิวเตอร์ ->Link
  • -ประวัติความเป็นมาของคอมพิวเตอร์ ->Link1| ->Link2
  • -หลักการทำงานเบื้องต้นของระบบคอมพิวเตอร์ ->Link
  • ->Bill Gates
    ->Link2

พื้นฐานการเขียนโปรแกรมคอมพิวเตอร์
(Programming Fundamentals)

Programming Fundamentals


การเขียนโปรแกรมคอมพิวเตอร์ C

Link->ข้อสอบ Computer Programming

https://www.onlinegdb.com/online_c_compiler

*****Open C Online*****

***C Examples***

Android Text Editor for Copy/Paste codes


Link-> Play Store Editor








C Keywords

***Link->C Keywords***

ความแตกต่างระหว่าง Error กับ Warning

การใช้ Comment

// นำหน้า หมายถึง compiler จะไม่สนใจตั้งแต่ // จนสิ้นสุดบรรทัดนั้น
/* */ คลุม หมายถึง compiler จะไม่สนใจตั้งแต่ /* จนถึง */


Link->Data Types



















Link->C-input-output
Link->C-String



/* Example 1 */


#include <stdio.h>

int main()
{
    printf ("Hello world!");
    
    return 0;
}


/* Example 2 */


    #include <stdio.h>
    int main() {   
        int number;
       
        printf("Enter an integer: ");  
        
        // reads and stores input
        scanf("%d", &number);
        // displays output
        printf("You entered: %d", number);
        
        return 0;
    }



295

296

เอกสารประกอบการสอน if else, while, do while



*****Link->PDF*****


Relational Operator



























Home Work#2



#include <stdio.h>
#include <string.h>

int main()
{
    int i, found = 0;
	char size[6]; //inch
	char sv[20];
	float dia = 0; //m.
	float r = 0; //m.
	float flow = 0; //cu.m./s
	float v = 2; // m/s
 
    char pipe_size[5][20] = {
                                  "1","2","3","4","6"
                              }, name[10];
 
     char pipe_diam[5][20] = {
                                  "28.0","51.4", "76.2", "97.8", "141.6"
                              }, data[10];

    printf("Enter Size [inch]: ");
    scanf("%s",size);
    
    printf("Enter Velocity [m/s]: ");
    scanf("%s",sv);
    
    for(i = 0; i < 5; i++)
    {
        if(strcmp(size, pipe_size[i]) == 0 )
        {
            found = 1;
			//printf("data = %s" ,pipe_diam[i] );
			sscanf(pipe_diam[i] , "%f", &dia); //convert string to float
			sscanf(sv , "%f", &v); //convert string to float
			r = (dia * 0.5) / 1000.0; //mm
			flow = v * (3.14159 * r * r) * 1000; //liter/s
			printf("flow [liter/s] = %f" , flow);
            break; //out of for loop
        }
    }
 
    return 0;
}
 



Home Work#1


#include <stdio.h>
int main()
{
    int cpucore = 8;
    int camera = 3;
    int ram = 64;
	
    
    if (camera<2)
    {
        printf("Camera NOT Pass\n");
    }

    else
    {
        printf("Camera Pass\n");
    }
    
    if (cpucore>4)
    {
        printf("CPU CORE Pass\n");
    }

    else
    {
        printf("CPU CORE NOT pass\n");
    }
	
	
    if (ram>32)
    {
        printf("RAM Pass\n");
    }

    else
    {
        printf("RAM NOT pass\n");
    }	

    return 0;
}




การใช้ if else



//***Example if 1***


#include <stdio.h>
int main()
{
    int x = 20;
    int y = 22;
    if (x<y)
    {
        printf("Variable x is less than y");
    }
    return 0;
}



//***Example if else***


#include <stdio.h>
int main()
{
    int x = 20;
    int y = 22;
    if (x<y)
    {
        printf("Variable x is less than y");
    }

    else
    {
        printf("Variable x is NOT less than y");
    }

    return 0;
}



การใช้ for loop


#include <stdio.h>


int main()
{
    int age = 18;
    int height = 155;
    int weight = 42;
    
    if (height<=150)
    {
        printf("height NOT Pass\n");
    }

    else
    {
        printf("height Pass\n");
    }
    
    if (age<=20)
    {
        printf("age Pass\n");
    }

    else
    {
        printf("age NOT pass\n");
    }
    
    if (weight<=80)
    {
        printf("weight Pass\n");
    }

    else
    {
        printf("weight NOT pass\n");
    }

    return 0;
}




//***Example Loop 1***


#include <stdio.h>
 
int main () {

   int a;
   int b;
	b = 1;
   /* for loop execution */
   for( a = 5; a > 0; a = a - 1 ){
        b = b + 2;            
      printf("value of a: %d   b: %d\n ", a ,b);
      //printf("value of b: %d\n", b);
   }
 
   return 0;
}


//***Example for loop sum***

#include <stdio.h>
int main()
{
   int i;
   int sum;
   sum = 0;

   for (i=1; i<=3; i++)
   {
        sum = sum + i;
       printf("%d\n", sum);
   }
   return 0;
}


//***Example for loop average***

#include <stdio.h>
int main()
{   
   int i;   
   float sum;   
   float avg;   
   sum = 0;  
   for (i=1; i<=6; i++)   
   {        
      sum = sum + i;      
      printf("i=%d , sum=%f\n", i,sum);   
    }   
    printf("i=%d \n",i);   
    //reduce i by 1   
    i = i - 1;   
    printf("***i=%d*** \n",i);
    avg = sum / (float)i;   
    printf("%6.3f\n", avg);   
    return 0;
}



//***Example for loop array***


#include <stdio.h>
 
int main () {

   int n[4][4]; /* n is an array of 3X3 integers */
   int i,j;
    for ( i = 0; i < 4; i++ ) {
        for ( j = 0; j < 4; j++ ) {
            n[j][i] = i; /* set element at location n[j][i] = i */
            printf("n[%d][%d] = %d\n", i,j,n[j][i]);
        }    
   }
   
   return 0;
}

การใช้ while loop


//***Example While Loop 1***


#include <stdio.h>
int main()
{
   int count=1;
   while (count <= 4)
   {
	printf("%d ", count);
	count++;
   }
   return 0;
}



//***Example While Loop 2***


#include <stdio.h>
int main()
{
   int x;
   int y;
   x = 5;
   y = 2;

   while (x > 0)
   {
        x = x - 1;
        y = y * x;
	printf("y = %d \n ", y);
   }
   return 0;
}


//***Example While Loop 3***


#include <stdio.h>
int main()
{
   int i;
   int j;
   i = 1;
   j = 0;

   for ( i = 1; i <= 4; i++ ) {
       if ((i-1)/2 == 0) 
       {
	 printf("i = %d \n ", i);
         j = i +1;
       }
   }
   return 0;
}

การใช้ do while loop


//***Example Do While Loop 1***

#include <stdio.h>
int main()
{
	int j=0;
	do
	{
		printf("Value of variable j is: %d\n", j);
		j++;
	}while (j<=3);
	return 0;
}




/* Example 3.1 */



#include <stdio.h>     
int main() {
  short a;
  long b;
  long long c;
  long double d;
  printf("size of short = %d bytes\n", sizeof(a));
  printf("size of long = %d bytes\n", sizeof(b));
  printf("size of long long = %d bytes\n", sizeof(c));
  printf("size of long double= %d bytes\n", sizeof(d));
  return 0;
}




/* Example 3.2 */

#include <stdio.h>     
int main() {
  short a;
  long b;
  long long c;
  long double d;
  printf("size of short = %d bytes\n", (int)sizeof(a));
  printf("size of long = %d bytes\n", (int)sizeof(b));
  printf("size of long long = %d bytes\n", (int)sizeof(c));
  printf("size of long double= %d bytes\n", (int)sizeof(d));
  return 0;
}



/* Example 4 */


#include <stdio.h> 
int main(){
    char chr = 'a';    
    printf("character = %c.", chr);  
    return 0;
} 



/* Example 5 */



#include <stdio.h>


int main() {

char first[100], last[100];

	int i;

	printf("nEnter your first name:");

	scanf("%s", first );

	printf("nEnter your last name:");

	scanf("%s", last );

	printf("nYour full name is: %s %sn", first, last );

	printf("First name is: ");

	for( i=0; i<100; i++ ){
        if ((first[i] > 32) && (first[i] < 123)){
	        printf("%c ",first[i]);
        }

	}

	printf("nLast name is: ");

	for( i=0; i<100; i++ ){

	   printf("%c ",last[i]);

	}

	printf("n");

    return 0;
} 



การเขียนโปรแกรมคอมพิวเตอร์ Octave

https://octave-online.net/

*****Open Octave Online*****
  • Run Octave
  • หน้าจอของโปรแกรม Octave
  • Command Window
  • Editor

Octave แก้ระบบสมการ

ระบบสมการ ->Link1

A = [1,1,1; 0,2,5; 2,5,-1;]
C = [6;-4;27;]
x = inv(A) * C
x

Introduction to Octave

#
i = 2 * 4
i

#
x = 0 : 0.1 : 1;
x

y = [ 0 : 0.1 : 1];
y

#แก้ระบบสมการ

A = [1,1,1; 0,2,5; 2,5,-1;]
C = [6;-4;27;]
x = inv(A) * C
x


######plot1###############


x = 1:5;  y = 1:5;
plot (x,y,"g");
title ("plot() of green line at 45 degrees");


######plot2###############


x = 1:5;  y = 1:5;
plot (x,y,"g*");
title ("plot() of green stars along a line at 45 degrees"); 


###### plot function 1 #########


x = -10:0.1:10;
plot (x, sin (x)); 


###### plot function 2 #########


x = -10:0.1:10;
y = sin(x);
plot (x, y); 
 

###### plot function 3 #########


x1 = 1:5;  y1 = 1:5;
x2 = 5:9; y2 = 5:-1:1;
plot (x1,y1,"bo-", x2,y2,"rs-");
axis ("tight");
title ({"plot() of blue circles ascending and red squares descending";
         "connecting lines drawn"}); 
 

###### plot function 4 #########


x = [0:10]';
y = [sin(x), cos(x)]
h = stem (x, y);
set (h(2), "color", "g");
set (h(1), "basevalue", -1)


###### Histogram 1 #########


 hist (randn (10000, 1), 30);


###### Histogram 2 #########


h = bar (rand (5, 10));
set (h(1), "basevalue", 0.5); 


###### Histogram 3 #########


h = bar (rand (10, 3));
set (h(1), "facecolor", "r")
set (h(2), "facecolor", "g")
set (h(3), "facecolor", "b") 


###### Rose Map #########


[th, r] = rose ([2*randn(1e5,1), pi + 2*randn(1e5,1)]);
polar (th, r);


###### Contour 1 #########


x = 0:2;
y = x;
z = x' * y;
contour (x, y, z, 2:3) 


###### Contour 2 #########


[x, y, z] = peaks (50);
contourf (x, y, z, -7:9)
 


***********************************
Sheet
*******************************************
<.p>

แก้ระบบสมการ

->Link1

A = [1,1,1; 0,2,5; 2,5,-1;]
C = [6;-4;27;]
x = inv(A) * C
x


Assignment 1/2019

***เลยกำหนดส่ง 5 ม.ค. 2563***