function BS_speculative_1248 (i_p, first, mult) % Copyright 2004, J.E. Akin. All rights reserved. % ------------------------------------------------------ % Black-Scholes Speculative Value plots % Matlab carpet plot of i_p-th component value, at mesh node % locations for 4 geometric step progressions: % steps 1, 2, 4, 8 or first, 2*first, 4*first, 8*first % or first, mult*first, mult^2*first, mult^3*first % If i_p = 0, show RMS value % If first == 0, show initial condition only % ------------------------------------------------------ %? global az el ? these are not changing with new view % c_x = x coordinates of nod_per_el line polygon % c_y = y coordinates of nod_per_el line polygon % msh_typ_nodes = connectivity list for elements, nt x nod_per_el % loop = corners for nod_per_el line polygon % nod_per_el = Nodes per element % np = Number of Points % nt = Number of elements % pre_e = Element items before connectivity list pre_e = 0 ; % pre_p = Nodal items before coordinates pre_p = 1; % msh_bc_xyz = Nodal coordinates (with preceeding data) % t_x = x coordinates of nod_per_el corners % t_y = y coordinates of nod_per_el corners clear fid_1 fid_2 fid_3 fid_4 if ( nargin == 0 ) i_p = 0 ; first = 1 ; mult = 2; elseif ( nargin == 1 ) first = 1 ; mult = 2; elseif ( nargin == 2 ) mult = 2; end % if no arguments step_1 = first ; step_2 = step_1 * mult ; step_3 = step_2 * mult ; step_4 = step_3 * mult ; fprintf ('Step progression: %g, %g, %g, %g \n', step_1,step_2,step_3,step_4) % Read coordinate file and connectivity file % integer bc code, real xy pairs for np points (pre_p = 1) load msh_bc_xyz.tmp ; % Set control data: number of points np = size (msh_bc_xyz,1) ; % number of nodal points fprintf ('Read %g mesh coordinate pairs \n', np) ns = size (msh_bc_xyz,2) - pre_p ; % space dimension if ( ns < 2 ) error ('This is not a 2D mesh') end % if not 2D data % Set control data: number elements load msh_typ_nodes.tmp ; % nod_per_el nodes per element nt = size (msh_typ_nodes,1) ; % number of elements in mesh nod_per_el = size (msh_typ_nodes,2) - pre_e -1 ; % nodes per elem % fprintf ('Read %g elements connections \n', nt) % ==================== 4 files ==================== if ( step_1 < 10 ) file_1 = ['node_results_00', int2str(step_1)]; elseif ( step_1 < 100 ) file_1 = ['node_results_0', int2str(step_1)]; else file_1 = ['node_results_', int2str(step_1)]; end % if filename_1 = [file_1, '.tmp']; fid_1= fopen(filename_1, 'r') ; % load the file array Result_1 = fscanf (fid_1, '%g \n', [inf]) ; NP = size (Result_1, 1) ; if ( NP == 0 ) error ('Error missing file ', file_1, '.tmp') end % if error if ( NP ~= np ) fprintf ('Read %g nodal solution values \n', NP) error ('Error, incompatible mesh file size') end % if max_p = size (Result_1, 2) ; % fprintf (' with %g components each \n', max_p) if ( i_p > max_p ) error ('i_p > available data') end % if error %b if ( first > 0 ) % then more plots if ( step_2 < 10 ) file_2 = ['node_results_00', int2str(step_2)]; elseif ( step_2 < 100 ) file_2 = ['node_results_0', int2str(step_2)]; else file_2 = ['node_results_', int2str(step_2)]; end % if filename_2 = [file_2, '.tmp']; fid_2= fopen(filename_2, 'r') ; % load the file array Result_2 = fscanf (fid_2, '%g \n', [inf]) ; NP = size (Result_2, 1) ; if ( NP == 0 ) error ('Error missing file ', file_2, '.tmp') end % if error if ( NP ~= np ) fprintf ('Read %g nodal solution values \n', NP) error ('Error, incompatible mesh file size') end % if max_p = size (Result_2, 2) ; % fprintf (' with %g components each \n', max_p) if ( i_p > max_p ) error ('i_p > available data') end % if error if ( step_3 < 10 ) file_3 = ['node_results_00', int2str(step_3)]; elseif ( step_3 < 100 ) file_3 = ['node_results_0', int2str(step_3)]; else file_3 = ['node_results_', int2str(step_3)]; end % if filename_3 = [file_3, '.tmp']; fid_3= fopen(filename_3, 'r') ; % load the file array Result_3 = fscanf (fid_3, '%g \n', [inf]) ; NP = size (Result_3, 1) ; if ( NP == 0 ) error ('Error missing file ', file_3, '.tmp') end % if error if ( NP ~= np ) fprintf ('Read %g nodal solution values \n', NP) error ('Error, incompatible mesh file size') end % if max_p = size (Result_3, 2) ; % fprintf (' with %g components each \n', max_p) if ( i_p > max_p ) error ('i_p > available data') end % if error if ( step_4 < 10 ) file_4 = ['node_results_00', int2str(step_4)]; elseif ( step_4 < 100 ) file_4 = ['node_results_0', int2str(step_4)]; else file_4 = ['node_results_', int2str(step_4)]; end % if filename_4 = [file_4, '.tmp']; fid_4= fopen(filename_4, 'r') ; % load the file array Result_4 = fscanf (fid_4, '%g \n', [inf]) ; NP = size (Result_4, 1) ; if ( NP == 0 ) error ('Error missing file ', file_4, '.tmp') end % if error if ( NP ~= np ) fprintf ('Read %g nodal solution values \n', NP) error ('Error, incompatible mesh file size') end % if max_p = size (Result_4, 2) ; % fprintf (' with %g components each \n', max_p) if ( i_p > max_p ) error ('i_p > available data') end % if error %b end % if initial condition only (first == 0) % Get IC values to subtract file_5 = ['node_results_000']; filename_5 = [file_5, '.tmp']; fid_5= fopen(filename_5, 'r') ; % load the file array Result_5 = fscanf (fid_5, '%g \n', [inf]) ; NP = size (Result_5, 1) ; if ( NP == 0 ) error ('Error missing file ', file_5, '.tmp') end % if error if ( NP ~= np ) fprintf ('Read %g nodal solution values \n', NP) error ('Error, incompatible mesh file size') end % if max_p = size (Result_5, 2) ; % fprintf (' with %g components each \n', max_p) if ( i_p > max_p ) error ('i_p > available data') end % if error % ==================== end 4 files ==================== x (np) = 0. ; % pre-allocate array x y (np) = 0. ; % pre-allocate array y z (np) = 0. ; % pre-allocate array z t_nodes (nod_per_el) = 0 ; % Optional pre-allocation t_x (nod_per_el) = 0 ; % Optional pre-allocation t_y (nod_per_el) = 0 ; % Optional pre-allocation c_x (nod_per_el + 1) = 0 ; % Optional pre-allocation c_y (nod_per_el + 1) = 0 ; % Optional pre-allocation loop (nod_per_el + 1) = 0 ; % Optional pre-allocation % set constants [loop] = get_El_Loop (nod_per_el) ; % msh_bc_xyz has: pre_p items then: x, y x = msh_bc_xyz (1:np, (pre_p+1)) ; % extract x column y = msh_bc_xyz (1:np, (pre_p+2)) ; % extract y column z_1 = Result_1(:, i_p) ; z_2 = Result_2(:, i_p) ; z_3 = Result_3(:, i_p) ; z_4 = Result_4(:, i_p) ; z_5 = Result_5(:, i_p) ; z_1 = z_1 - z_5 ; z_2 = z_2 - z_5 ; z_3 = z_3 - z_5 ; z_4 = z_4 - z_5 ; %bb if ( i_p >= 1 ) %bb z_1 = Result_1(:, i_p) ; %b if ( first > 0 ) %bb z_2 = Result_2(:, i_p) ; %bb z_3 = Result_3(:, i_p) ; %bb z_4 = Result_4(:, i_p) ; %b else %b z_2 = z_1 ; %b z_3 = z_1 ; %b z_4 = z_1 ; %b end % if %bb else % i_p = 0, get root mean sq %bb for k = 1:np %bb z_1 (k) = sqrt ( sum (Result_1 (k, 1:max_p).^2)) ; %bb %b if ( first > 0 ) %bb z_2 (k) = sqrt ( sum (Result_2 (k, 1:max_p).^2)) ; %bb z_3 (k) = sqrt ( sum (Result_3 (k, 1:max_p).^2)) ; %bb z_4 (k) = sqrt ( sum (Result_4 (k, 1:max_p).^2)) ; %bb %b else %bb %b z_2 (k)= z_1 (k); %bb %b z_3 (k)= z_1 (k); %bb %b z_4 (k)= z_1 (k); %bb %b end % if %bb end % for k %bb end % if get RMS value % Cite max, min values %b [V_X, L_X] = max (z_1) ; %b [V_N, L_N] = min (z_1) ; %b fprintf ('Max value is %g at node %g \n', V_X, L_X) %b fprintf ('Min value is %g at node %g \n', V_N, L_N) % Initialize plots xmax = max (x) ; xmin = min (x) ; ymax = max (y) ; ymin = min (y) ; z_1X = max (z_1) ; z_1N = min (z_1) ; z_2X = max (z_2) ; z_2N = min (z_2) ; z_3X = max (z_3) ; z_3N = min (z_3) ; z_4X = max (z_4) ; z_4N = min (z_4) ; zmax = max ([z_1X, z_2X, z_3X, z_4X]) ; zmin = min ([z_1N, z_2N, z_3N, z_4N]) ; clf % clear graphics axis ([xmin, xmax, ymin, ymax, zmin, zmax]) % set axes % view([52.5,30]) hold on % hold image for plots xlabel ('S\_1') % add label ylabel ('S\_2') % add label %bb if ( i_p >= 1 ) zlabel (['Value (max = ', num2str(zmax), ... ', min = ', num2str(zmin), ' dollars )']) %bb if ( first > 0 ) % then multiple plots title(['Steps ', int2str(step_1), ', ', int2str(step_2), ... ', ', int2str(step_3), ', ', int2str(step_4), ... ' Speculative Value: ', int2str(nt),' Elements, ', ... int2str(np), ' Nodes, (', int2str(nod_per_el), ... ' per Element)']) %bb else %bb title(['Initial Condition Values for Component\_', ... %bb int2str(i_p),': ', int2str(nt),' Elements, ', ... %bb int2str(np), ' Nodes, (', int2str(nod_per_el), ... %bb ' per Element)']) %bb end % if IC only %bb else % i_p = 0, get root mean sq %bb % zlabel (['RMS Value (max = ', num2str(zmax), ... %bb % ', min = ', num2str(zmin), ')']) %bb if ( first > 0 ) % then multiple plots %bb title(['Steps ', int2str(step), ' to ', int2str(step_4), ... %bb ' RMS Value: ', ... %bb int2str(nt),' Elements, ', int2str(np), ... %bb ' Nodes, (', int2str(nod_per_el), ' per Element)']) %bb else %bb title(['Initial Condition RMS of Component\_', ... %bb int2str(i_p),': ', ... %bb int2str(nt),' Elements, ', int2str(np), ... %bb ' Nodes, (', int2str(nod_per_el), ' per Element)']) %bb end % if IC only %bb zlabel ('RMS Value') %bb end % if get RMS value % Loop over all elements n1 = pre_e+2 ; n2 = nod_per_el+pre_e+1 ; for it = 1:nt ; % Extract corner connectivity %b t_nodes = msh_typ_nodes (it, (pre_e+2):(nod_per_el+pre_e+1)); t_nodes = msh_typ_nodes (it, n1:n2) ; if ( all ( t_nodes > 0 ) ) %B % Extract corner coordinates t_x = x (t_nodes) ; % x at those nodes, only t_y = y (t_nodes) ; % y at those nodes, only c_x = t_x (loop) ; % x for nod_per_el line polygon c_y = t_y (loop) ; % y for nod_per_el line polygon % Plot this polygon t_z = z_1 (t_nodes) ; % z at those nodes, only c_z = t_z (loop) ; fill3 (c_x, c_y, c_z, 'b' ) % plot nod_per_el lines t_z = z_2 (t_nodes) ; % z at those nodes, only c_z = t_z (loop) ; fill3 (c_x, c_y, c_z, 'y' ) % plot nod_per_el lines t_z = z_3 (t_nodes) ; % z at those nodes, only c_z = t_z (loop) ; fill3 (c_x, c_y, c_z, 'g' ) % plot nod_per_el lines t_z = z_4 (t_nodes) ; % z at those nodes, only c_z = t_z (loop) ; fill3 (c_x, c_y, c_z, 'w' ) % plot nod_per_el lines end % if all end % for over all elements grid %% label max min points % v_text = sprintf ('------min') ; % text (x(L_N), y(L_N), V_N, v_text) ; % v_text = sprintf ('------max') ; % text (x(L_X), y(L_X), V_X, [v_text]) ; ; % end % if show labels % -depsc -tiff % for an eps version % print ('-dpsc', ['hidden_result_', int2str(i_p), '_time_1248']) hold off % v_text = ['Created hidden_result_', int2str(i_p), '_time_1248.ps'] ; % fprintf (1,'%s', v_text) ; fprintf (1, ' \n' ) % end of BS_speculative_1248