You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: ex_piezoelectric1.m
    path of file: ./repos/featool-multiphysics/examples
    
    the code of the file until where you have to start completion: function [ fea, out ] = ex_piezoelectric1( varargin )
%EX_PIEZOELECTRIC1 Piezoelectric bending of a beam example.
%
%   [ FEA, OUT ] = EX_PIEZOELECTRIC1( VARARGIN ) Example for piezoelectric bending of a beam.
%
%   References:
%
%   [1] V. Pierfort, Finite Element Modeling of Piezoelectric Active
%   Structures, ULB, Faculty of Applied Sciences, 2000.
%
%   [2] W-S. Hwang, H.C. Park, Finite Element Modeling of Piezoelectric
%   Sensors and Actuators, AIAA Journal, Vol. 31, No. 5, May 1993.
%
%   [3] C-I. Tseng, Electromechanical Dynamics of a Coupled
%   Piezo-electric/Mechanical System Applied to Vibration Control and
%   Distributed Sensing, Univ. of Kentucky, Lexington, July 1989.
%
%   Accepts the following property/value pairs.
%
%       Input       Value/{Default}        Description
%       -----------------------------------------------------------------------------------
%       l           scalar {0.12}          Length of beam
%       h           scalar {2e-3}          Height (thickness) of beam
%       delV        scalar {200}           Potential difference
%       igrid       scalar 1/{0}           Cell type (0=quadrilaterals, 1=triangles)
%       hmax        scalar {20}            Cell resolution
%       sfund       string {sflag1}        Shape function for
    
function for displacements
%       sfunp       string {sflag1}        Shape function for potential
%       iplot       scalar 0/{1}           Plot solution (=1)
%                                                                                         .
%       Output      Value/(Size)           Description
%       -----------------------------------------------------------------------------------
%       fea         struct                 Problem definition struct
%       out         struct                 Output struct

% Copyright 2013-2023 Precise Simulation, Ltd.


cOptDef = { ...
  'l',        0.12; ...
  'h',        2e-3; ...
  'delV',     100; ...
  'igrid',    0; ...
  'hmax',     20; ...
  'sfund',    'sflag2'; ...
  'sfunp',    'sflag1'; ...
  'iplot',    1; ...
  'fid',      1 };
[got,opt] = parseopt( cOptDef, varargin{:} );
fid       = opt.fid;
i_impl    = 1;

% Geometry definition.
fea.sdim = { 'x' 'y' };   % Names of space coordinates.
gobj1    = gobj_rectangle( 0, opt.l,  0,       opt.h/2, 'R1' );
gobj2    = gobj_rectangle( 0, opt.l, -opt.h/2, 0,       'R2' );
fea.geom.objects = { gobj1 gobj2 };


% Grid generation.
switch opt.igrid
  case -1
    fea.grid = rectgrid( opt.hmax, opt.hmax, [ 0 opt.l; -opt.h/2 opt.h/2] );
    fea.grid = quad2tri( fea.grid );
  case 0
    fea.grid = rectgrid( opt.hmax, opt.hmax, [ 0 opt.l; -opt.h/2 opt.h/2] );
    fea.grid.s( selcells( fea, 'y<=0' ) ) = 2;
  case 1
    fea.grid = gridgen( fea, 'hmax', opt.h/(opt.hmax/4.6), 'fid', fid );
    fea.grid.s(:) = 1;
end