{"text": "function points = getSpacedPoints(X1, X2, N, spacing)\n%GETSPACEDPOINTS Create vector of log or linear spaced points.\n%\n% DESCRIPTION:\n% getSpacedPoints generates a row vector of either logarithmically\n% or linearly spaced points between X1 and X2. When spacing is set to\n% 'linear', the function is identical to the inbuilt linspace\n% function. When spacing is set to 'log', the function is similar to\n% the inbuilt logspace function, except that X1 and X2 define the\n% start and end numbers, not decades. For logarithmically spaced\n% points, X1 must be > 0. If N < 2, X2 is returned. \n%\n% USAGE:\n% points = getSpacedPoints(X1, X2)\n% points = getSpacedPoints(X1, X2, N)\n% points = getSpacedPoints(X1, X2, N, spacing)\n%\n% INPUTS:\n% X1 - starting points value\n% X2 - ending points value (where X2 > X1)\n%\n% OPTIONAL INPUTS:\n% N - number of points in the vector (default = 100)\n% spacing - 'log' or 'linear' spaced values (default = 'linear')\n%\n% OUTPUTS:\n% points - row vector of equally spaced points\n%\n% ABOUT:\n% author - Bradley E. Treeby\n% date - 14th July 2005\n% last update - 1st December 2012\n%\n% This function is part of the k-Wave Toolbox (http://www.k-wave.org)\n% Copyright (C) 2009-2014 Bradley Treeby and Ben Cox\n\n% This file is part of k-Wave. k-Wave is free software: you can\n% redistribute it and/or modify it under the terms of the GNU Lesser\n% General Public License as published by the Free Software Foundation,\n% either version 3 of the License, or (at your option) any later version.\n% \n% k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY\n% WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for\n% more details. \n% \n% You should have received a copy of the GNU Lesser General Public License\n% along with k-Wave. If not, see .\n\n% check for number of points input\nif nargin < 3\n N = 100;\nend\n\n% check for spacing input\nif nargin < 4\n spacing = 'linear';\nend\n\n% check if the end point is larger than the start point\nif X2 <= X1\n error('X2 must be larger than X1');\nend\n\n% force N to be an integer\nN = round(N);\n\nif (N < 2)\n % return the end point if N < 2\n points = X2;\nelseif (N == 2)\n % return the start and end points if N = 2\n points(1) = X1;\n points(2) = X2;\nelse\n\n % update X1 and X2 values for log spaced variables\n if (strcmp(spacing, 'log'))\n \n % check that X1 is greater than 0\n if X1 <= 0\n error('X1 must be > 0 for log spaced points');\n end\n \n X1 = log10(X1);\n X2 = log10(X2);\n end\n \n % create step variable and points range\n step = (X2 - X1)/(N - 1);\n points = X1:step:X2;\n \n % update log spaced points\n if (strcmp(spacing, 'log'))\n points = 10.^(points);\n end\nend", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/K-wave/k-Wave/getSpacedPoints.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.8856314798554444, "lm_q1q2_score": 0.7999857850280055}}
{"text": "%\n% This is the main script to finds a (near) optimal solution to the Traveling\n% Salesman Problem (TSP), by setting up a Simulated Annealing (SA) to search \n% for the shortest route (least distance for the salesman to travel to each \n% city exactly once and return to the starting city).\n%\n\nclear;clc;\n\nload china; % geographic information\nplotcities(province, border, city); % draw the map of China\n\nnumberofcities = length(city); % number of cities\n% distance matrix: dis(i,j) is the distance between city i and j.\ndis = distancematrix(city); \n\nglobal h;\ntemperature = 1000; % Initialize the temperature.\ncooling_rate = 0.94; % cooling rate\niterations = 1; % Initialize the iteration number.\n\n% Initialize random number generator with \"seed\". \nrand('seed',0); \n\n% Initialize the route by generate a sequence of random\nroute = randperm(numberofcities);\n% This is objective function, the total distance for the routes.\nprevious_distance = totaldistance(route,dis);\n\n% This is a flag used to cool the current temperature after 100 iterations\ntemperature_iterations = 1;\n% This is a flag used to plot the current route after 200 iterations\nplot_iterations = 1;\n\n% plot the current route\nplotroute(city, route, previous_distance, temperature);\n\nwhile 1.0 < temperature\n % generate randomly a neighbouring solution\n temp_route = perturb(route,'reverse');\n % compute total distance of the temp_route\n current_distance = totaldistance(temp_route, dis);\n % compute change of distance\n diff = current_distance - previous_distance;\n \n % Metropolis Algorithm\n if (diff < 0) || (rand < exp(-diff/(temperature)))\n route = temp_route; %accept new route\n previous_distance = current_distance;\n \n % update iterations\n temperature_iterations = temperature_iterations + 1;\n plot_iterations = plot_iterations + 1;\n iterations = iterations + 1;\n end\n \n % reduce the temperature every 100 iterations\n if temperature_iterations >= 100\n temperature = cooling_rate*temperature;\n temperature_iterations = 0;\n end\n \n % plot the current route every 200 iterations\n if plot_iterations >= 200\n plotroute(city, route, previous_distance, temperature);\n plot_iterations = 0;\n end\nend\n\n% plot and output final solution\nplotroute(city, route, previous_distance, temperature);\n% sth. wrong with function fpdfprinter\nfpdfprinter('Final Solution')\n", "meta": {"author": "HuangCongQing", "repo": "Algorithms_MathModels", "sha": "e15b0e9053b11f08b5ce1e3492c4acb444409c8b", "save_path": "github-repos/MATLAB/HuangCongQing-Algorithms_MathModels", "path": "github-repos/MATLAB/HuangCongQing-Algorithms_MathModels/Algorithms_MathModels-e15b0e9053b11f08b5ce1e3492c4acb444409c8b/HeuristicAlgorithm(补分启发式算法,包括神经网络、模拟退火、遗传算法)/模拟退火算法/TSP(SA)/main.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.943347579470196, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7999283341466931}}
{"text": "function [mu ul ll] = circ_mean(alpha, w, dim)\n%\n% mu = circ_mean(alpha, w)\n% Computes the mean direction for circular data.\n%\n% Input:\n% alpha\tsample of angles in radians\n% [w\t\tweightings in case of binned angle data]\n% [dim compute along this dimension, default is 1]\n%\n% If dim argument is specified, all other optional arguments can be\n% left empty: circ_mean(alpha, [], dim)\n%\n% Output:\n% mu\t\tmean direction\n% ul upper 95% confidence limit\n% ll lower 95% confidence limit \n%\n% PHB 7/6/2008\n%\n% References:\n% Statistical analysis of circular data, N. I. Fisher\n% Topics in circular statistics, S. R. Jammalamadaka et al. \n% Biostatistical Analysis, J. H. Zar\n%\n% Circular Statistics Toolbox for Matlab\n\n% By Philipp Berens, 2009\n% berens@tuebingen.mpg.de - www.kyb.mpg.de/~berens/circStat.html\n\nif nargin < 3\n dim = 1;\nend\n\nif nargin < 2 || isempty(w)\n % if no specific weighting has been specified\n % assume no binning has taken place\n\tw = ones(size(alpha));\nelse\n if size(w,2) ~= size(alpha,2) || size(w,1) ~= size(alpha,1) \n error('Input dimensions do not match');\n end \nend\n\n% compute weighted sum of cos and sin of angles\nr = sum(w.*exp(1i*alpha),dim);\n\n% obtain mean by\nmu = angle(r);\n\n% confidence limits if desired\nif nargout > 1\n t = circ_confmean(alpha,0.05,w,[],dim);\n ul = mu + t;\n ll = mu - t;\nend", "meta": {"author": "brainstorm-tools", "repo": "brainstorm3", "sha": "a892cfaabde1eaa2f9a3ac015c05b73f3739433a", "save_path": "github-repos/MATLAB/brainstorm-tools-brainstorm3", "path": "github-repos/MATLAB/brainstorm-tools-brainstorm3/brainstorm3-a892cfaabde1eaa2f9a3ac015c05b73f3739433a/external/CircStat2012a/circ_mean.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993028, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.7999283251199748}}
{"text": "function y = r8vec_sct ( n, x )\n\n%*****************************************************************************80\n%\n%% R8VEC_SCT computes a \"slow\" cosine transform of an R8VEC.\n%\n% Discussion:\n%\n% This routine is provided for illustration and testing. It is inefficient\n% relative to optimized routines that use fast Fourier techniques.\n%\n% Y(1) = Sum ( 1 <= J <= N ) X(J)\n%\n% For 2 <= I <= N-1:\n%\n% Y(I) = 2 * Sum ( 1 <= J <= N ) X(J)\n% * cos ( PI * ( I - 1 ) * ( J - 1 ) / ( N - 1 ) )\n%\n% Y(N) = Sum ( X(1:N:2) ) - Sum ( X(2:N:2) )\n%\n% Applying the routine twice in succession should yield the original data,\n% multiplied by 2 * ( N + 1 ). This is a good check for correctness\n% and accuracy.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 27 February 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of data values.\n%\n% Input, real X(N), the data sequence.\n%\n% Output, real Y(N), the transformed data.\n%\n for i = 1 : n\n\n y(i) = x(1) / 2.0;\n\n for j = 2 : n - 1\n angle = pi * mod ( ( i - 1 ) * ( j - 1 ), 2 * ( n - 1 ) ) / ( n - 1 );\n y(i) = y(i) + x(j) * cos ( angle );\n end\n\n j = n;\n\n angle = pi * mod ( ( i - 1 ) * ( j - 1 ), 2 * ( n - 1 ) ) / ( n - 1 );\n\n y(i) = y(i) + x(n) * cos ( angle ) / 2.0;\n\n end\n\n y(1:n) = 2.0 * y(1:n) * sqrt ( n / ( n - 1 ) );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/sftpack/r8vec_sct.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941718, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7998812386291044}}
{"text": "function [ess,m] = spm_mci_ess (x,p)\n% Compute Effective Sample Size\n% FORMAT [ess,m] = spm_mci_ess (x,p)\n%\n% x Univariate time series\n% p Maximum lag for autocovariance estimation\n%\n% ess Effective Sample Size\n% m Number of lags used in ESS estimate\n%\n% This routine is based on the Initial Positive Sequence estimate\n% proposed in C. Geyer (1992) Practical Markov Chain Monte Carlo, \n% Statistical Science, 7(4):473-511.\n%__________________________________________________________________________\n% Copyright (C) 2015 Wellcome Trust Centre for Neuroimaging\n\n% Will Penny\n% $Id: spm_mci_ess.m 6697 2016-01-27 14:57:28Z spm $\n\nN=length(x);\n\ntry, pmax=p; catch, pmax=min(ceil(N/10),256); end\n\nfor i=1:pmax,\n y(:,i)=x(pmax-i+1:end-i);\nend\nC=cov(y);\nc=C(1,:);\ngamma=c(2:end);\ngamma0=c(1);\nr=gamma/gamma0;\n\nG=[];\nfor j=1:floor(pmax/2)-1,\n % Sum of adjacent pairs of autocovariances\n G(j)=gamma(2*j)+gamma(2*j+1);\nend\n\nif ~isempty(G)\n % Find minimum j such that all G's up to j are positive\n Gneg=find(G<0);\n if isempty(Gneg)\n m=length(G);\n else\n m1=min(Gneg);\n m=m1-1;\n end\nelse\n m=0;\nend\n\ness=N/(1+2*sum(r(1:2*m)));\n\n% figure;\n% plot(c);\n% title('Autocovariance');\n% \n% figure\n% plot(G);\n% title('Sum of adjacent covariances');", "meta": {"author": "spm", "repo": "spm12", "sha": "3085dac00ac804adb190a7e82c6ef11866c8af02", "save_path": "github-repos/MATLAB/spm-spm12", "path": "github-repos/MATLAB/spm-spm12/spm12-3085dac00ac804adb190a7e82c6ef11866c8af02/toolbox/mci/inference/spm_mci_ess.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.8615382094310355, "lm_q1q2_score": 0.799859659063691}}
{"text": "function v = haar_1d_inverse ( n, u )\n\n%*****************************************************************************80\n%\n%% HAAR_1D_INVERSE inverts the Haar transform of a vector.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 March 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the length of the vector.\n% N must be a power of 2.\n%\n% Input, real U(N,1), the vector to be transformed.\n%\n% Output, real V(N,1), the transformed vector.\n%\n v = u(:);\n\n s = sqrt ( 2.0 );\n\n w = zeros ( n, 1 );\n\n m = 1;\n\n while ( m * 2 <= n )\n\n w(1:2:2*m-1) = ( v(1:m) + v(1+m:m+m) ) / s;\n w(2:2:2*m) = ( v(1:m) - v(1+m:m+m) ) / s;\n\n v(1:2*m) = w(1:2*m);\n m = m * 2;\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/haar/haar_1d_inverse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7998287160386195}}
{"text": "function table = p_power_product ( p, e )\n\n%*****************************************************************************80\n%\n%% P_POWER_PRODUCT: power products for Legendre polynomial P(n,x).\n%\n% Discussion:\n%\n% Let P(n,x) represent the Legendre polynomial of degree i. \n%\n% For polynomial chaos applications, it is of interest to know the\n% value of the integrals of products of powers of X with every possible pair\n% of basis functions. That is, we'd like to form\n%\n% Tij = Integral ( -1 <= X <= +1 ) X^E * P(i,x) * P(j,x) dx\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 13 March 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer P, the maximum degree of the polyonomial factors.\n% 0 <= P.\n%\n% Input, integer E, the exponent of X in the integrand.\n% 0 <= E.\n%\n% Output, real TABLE(P+1,P+1), the table of integrals.\n%\n table(1:p+1,1:p+1) = 0.0;\n\n order = p + 1 + floor ( ( e + 1 ) / 2 );\n [ x_table, w_table ] = p_quadrature_rule ( order );\n\n for k = 1 : order\n\n x = x_table(k);\n l_table = p_polynomial_value ( 1, p, x );\n%\n% The following formula is an outer product in L_TABLE.\n%\n if ( e == 0 )\n table(1:p+1,1:p+1) = table(1:p+1,1:p+1) ...\n + w_table(k) * l_table(1:p+1)' * l_table(1:p+1);\n else\n table(1:p+1,1:p+1) = table(1:p+1,1:p+1) ...\n + w_table(k) * x^e * l_table(1:p+1)' * l_table(1:p+1);\n end\n\n end\n\n return\nend\n\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/legendre_polynomial/p_power_product.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915913, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.7998287108680202}}
{"text": "function [coreness,kn] = kcoreness_centrality_bu(CIJ)\n%KCORENESS_CENTRALITY_BU K-coreness centrality\n%\n% [coreness,kn] = kcoreness_centrality_bu(CIJ)\n%\n% The k-core is the largest subgraph comprising nodes of degree at least\n% k. The coreness of a node is k if the node belongs to the k-core but\n% not to the (k+1)-core. This function computes the coreness of all nodes\n% for a given binary undirected connection matrix.\n%\n% input: CIJ, connection/adjacency matrix (binary, undirected)\n%\n% output: coreness, node coreness.\n% kn, size of k-core\n%\n% References: e.g. Hagmann et al. (2008) PLoS Biology\n%\n% Olaf Sporns, Indiana University, 2007/2008/2010/2012\n\nN = size(CIJ,1);\n\n% determine if the network is undirected - if not, compute coreness on the\n% corresponding undirected network\nCIJund = CIJ+CIJ';\nif (any(CIJund(:)>1))\n CIJ = double(CIJund>0);\nend;\n\ncoreness = zeros(1,N); kn = zeros(1,N);\nfor k=1:N\n [CIJkcore,kn(k)] = kcore_bu(CIJ,k);\n ss = sum(CIJkcore)>0;\n coreness(ss) = k;\nend;\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/bct/kcoreness_centrality_bu.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832974, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7998287010372985}}
{"text": "function [filtered_signal,filtb,filta]=lopass_butterworth(inputsignal,cutoff_freq,Fs,order)\n% Low-pass Butterworth filter\n% [filtered_signal,filtb,filta] = lopass_butterworth(inputsignal,cutoff_freq,Fs,order)\n% \n% This is simply a set of built-in Matlab functions, repackaged for ease of\n% use by Chad Greene, October 2012. \n%\n% INPUTS: \n% inputsignal = input time series\n% cutoff_freq = filter corner frequency\n% Fs = data sampling frequency\n% order = order of Butterworth filter\n% \n% OUTPUTS: \n% filtered_signal = the filtered time series\n% filtb, filta = filter numerator and denominator (optional)\n% \n% EXAMPLE 1: \n% load train\n% t = (1:length(y))/Fs;\n% y_filt = lopass_butterworth(y,900,Fs,4); % cut off at 900 Hz\n% figure\n% plot(t,y,'b',t,y_filt,'r')\n% xlabel('time in seconds')\n% box off\n% legend('unfiltered','filtered')\n% sound(y,Fs) % play original time series\n% pause(2) % pause two seconds\n% sound(y_filt,Fs) % play filtered time series\n% \n% \n% EXAMPLE 2: \n% load train\n% t = (1:length(y))/Fs;\n% [y_filt,filtb,filta] = lopass_butterworth(y,900,Fs,4); % cut off at 900 Hz\n% [h1,f1] = freqz(filtb,filta,256,Fs);\n% \n% figure\n% subplot(3,1,1)\n% plot(t,y,'b',t,y_filt,'r')\n% xlabel('time in seconds')\n% box off\n% text(0,.1,' time series','units','normalized')\n% \n% subplot(3,1,2)\n% AX = plotyy(f1,10*log10(abs(h1)),f1,angle(h1),'semilogx');\n% set(get(AX(1),'ylabel'),'string','gain (dB)')\n% set(get(AX(2),'ylabel'),'string','phase (rad)')\n% xlim(AX(1),[min(f1) max(f1)])\n% xlim(AX(2),[min(f1) max(f1)])\n% text(0,.1,' filter response','units','normalized')\n% box off\n% \n% [Pxx,f] = pwelch(y,512,256,[],Fs,'onesided');\n% [Pxxf,f_f]= pwelch(y_filt,512,256,[],Fs,'onesided');\n% subplot(3,1,3)\n% semilogx(f,10*log10(Pxx))\n% hold on\n% semilogx(f_f,10*log10(Pxxf),'r')\n% xlabel('frequency (Hz)')\n% ylabel('PSD (dB)')\n% xlim([min(f1) max(f1)])\n% box off\n% legend('unfiltered','filtered','location','northwest')\n% legend boxoff\n\nnyquist_freq = Fs/2; % Nyquist frequency\nWn=cutoff_freq/nyquist_freq; % non-dimensional frequency\n[filtb,filta]=butter(order,Wn,'low'); % construct the filter\nfiltered_signal=filtfilt(filtb,filta,inputsignal); % filter the data with zero phase ", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/38584-butterworth-filters/Butterworth Filters/lopass_butterworth.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8740772335247531, "lm_q1q2_score": 0.7996940956894184}}
{"text": "function [is,os,str] = strengths_dir(CIJ)\n%STRENGTHS_DIR In-strength and out-strength\n%\n% [is,os,str] = strengths_dir(CIJ);\n%\n% Node strength is the sum of weights of links connected to the node. The\n% instrength is the sum of inward link weights and the outstrength is the\n% sum of outward link weights.\n%\n% Input: CIJ, directed weighted connection matrix\n%\n% Output: is, node instrength\n% os, node outstrength\n% str, node strength (instrength + outstrength)\n%\n% Notes: Inputs are assumed to be on the columns of the CIJ matrix.\n%\n%\n% Olaf Sporns, Indiana University, 2002/2006/2008\n\n\n% compute strengths\nis = sum(CIJ,1); % instrength = column sum of CIJ\nos = sum(CIJ,2)'; % outstrength = row sum of CIJ\nstr = is+os; % strength = instrength+outstrength\n\n\n", "meta": {"author": "canlab", "repo": "CanlabCore", "sha": "af242e120f0480c4feaeea90471c015a14f1f60e", "save_path": "github-repos/MATLAB/canlab-CanlabCore", "path": "github-repos/MATLAB/canlab-CanlabCore/CanlabCore-af242e120f0480c4feaeea90471c015a14f1f60e/CanlabCore/External/2019_03_03_BCT/strengths_dir.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474194456936, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.799631736472321}}
{"text": "function [T, Eps] = estimateRigidTransform(x, y)\n% ESTIMATERIGIDTRANSFORM\n% [T, EPS] = ESTIMATERIGIDTRANSFORM(X, Y) estimates the rigid transformation\n% that best aligns x with y (in the least-squares sense).\n% \n% Reference: \"Estimating Rigid Transformations\" in \n% \"Computer Vision, a modern approach\" by Forsyth and Ponce (1993), page 480\n% (page 717(?) of the newer edition)\n%\n% Input:\n% X: 3xN, N 3-D points (N>=3)\n% Y: 3xN, N 3-D points (N>=3)\n%\n% Output\n% T: the rigid transformation that aligns x and y as: xh = T * yh\n% (h denotes homogenous coordinates) \n% (corrspondence between points x(:,i) and y(:,i) is assumed)\n% \n% EPS: the smallest singular value. The closer this value it is \n% to 0, the better the estimate is. (large values mean that the \n% transform between the two data sets cannot be approximated\n% well with a rigid transform.\n%\n% Babak Taati, 2003\n% (revised 2009)\n\nif nargin ~= 2\n error('Requires two input arguments.')\nend\n\nif size(x,1)~=3 || size(y,1)~=3\n error('Input point clouds must be a 3xN matrix.');\nend\n\nif size(x, 2) ~= size(y,2)\n error('Input point clouds must be of the same size');\nend \n\nif size(x,2)<3 || size(y,2)<3\n error('At least 3 point matches are needed');\nend \n \npointCount = length(x); % since x has N=3+ points, length shows the number of points\n \nx_centroid = sum(x,2) / pointCount;\ny_centroid = sum(y,2) / pointCount; \n\nx_centrized = [x(1,:)-x_centroid(1) ; x(2,:)-x_centroid(2); x(3,:)-x_centroid(3)];\ny_centrized = [y(1,:)-y_centroid(1) ; y(2,:)-y_centroid(2); y(3,:)-y_centroid(3)];\n\nR12 = y_centrized' - x_centrized';\nR21 = x_centrized - y_centrized;\nR22_1 = y_centrized + x_centrized;\nR22 = crossTimesMatrix(R22_1(1:3,:));\n\nB = zeros(4, 4);\nA = zeros(4, 4, pointCount);\nfor ii=1:pointCount\n A(1:4,1:4,ii) = [0, R12(ii,1:3); R21(1:3,ii), R22(1:3,1:3,ii)];\n B = B + A(:,:,ii)' * A(:,:,ii);\nend\n\n[~, S, V] = svd(B);\nquat = V(:,4);\nrot = quat2rot(quat);\n\nT1 = [eye(3,3), -y_centroid ; 0 0 0 1];\nT2 = [rot, [0; 0; 0]; 0 0 0 1];\nT3 = [eye(3,3), x_centroid ; 0 0 0 1];\n\nT = T3 * T2 * T1;\nEps = S(4,4);\n\n \n \n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/28305-estimaterigidtransform/estimateRigidTransform/estimateRigidTransform.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.8705972768020108, "lm_q1q2_score": 0.7996264050728802}}
{"text": "function theta = circle_segment_angle_from_chord_angles ( omega1, omega2 )\n\n%*****************************************************************************80\n%\n%% CIRCLE_SEGMENT_ANGLE_FROM_CHORD_ANGLES computes the angle of a circle segment.\n%\n% Discussion:\n%\n% Begin with a circle of radius R. Choose two points P1 and P2 on the\n% circle, and draw the chord P1:P2. This chord divides the circle\n% into two pieces, each of which is called a circle segment.\n% Consider one of the pieces. The \"angle\" of this segment is the angle \n% P1:C:P2, where C is the center of the circle. Let Q be the point on \n% the chord P1:P2 which is closest to C. The \"height\" of the segment\n% is the distance from Q to the perimeter of the circle.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 17 May 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real OMEGA1, OMEGA2, the angles of the points P1 and P2.\n% OMEGA1 <= OMEGA2.\n%\n% Output, real THETA, the angle of the circle segment.\n% Essentially, THETA = OMEGA2 - OMEGA1.\n%\n while ( omega2 < omega1 )\n omega2 = omega2 + 2.0 * pi;\n end\n\n theta = omega2 - omega1;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/circle_segment/circle_segment_angle_from_chord_angles.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8652240930029118, "lm_q1q2_score": 0.7995897679971797}}
{"text": "function yp = p07_fun ( neqn, t, y )\n\n%*****************************************************************************80\n%\n%% P07_FUN evaluates the function for problem P07.\n%\n% Discussion:\n%\n% y1' = -y1 + y2\n% y2' = y1 - 2 y2 + y3\n% y3' = y2 - y3\n% y1(0) = 2\n% y2(0) = 0\n% y3(0) = 1\n%\n% 3 equations.\n% Enright and Pryce nonstiff problem #B2.\n% Autonomous.\n%\n% Note that the quantity (y1+y2+y3) is conserved by the exact solution.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 17 February 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Wayne Enright, John Pryce,\n% Algorithm 648,\n% ACM Transactions on Mathematical Software,\n% Volume 13, Number 1, pages 28-34.\n%\n% Parameters:\n%\n% Input, integer NEQN, the number of equations.\n%\n% Input, real T, Y(NEQN), the arguments of the derivative\n% function.\n%\n% Output, real YP(NEQN), the value of the derivative function.\n%\n yp = zeros ( neqn, 1 );\n\n yp(1) = - y(1) + y(2);\n yp(2) = y(1) - 2.0 * y(2) + y(3);\n yp(3) = y(2) - y(3);\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_ode/p07_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.8774767890838836, "lm_q1q2_score": 0.7995390356374538}}
{"text": "%% Rotational Approximation and Interpolation\n%\n%%\n% On this page, we want to cover the topic of function approximation from\n% discrete values on the Rotation group. To simulate this, we have stored some\n% nodes and corresponding function values which we can load. The csv-file\n% contains the Euler angles $\\phi_1$, $\\Phi$ and $\\phi_2$ of the nodes and the function\n% value in the fourth column. Lets import these data using the function\n% \n\nfname = fullfile(mtexDataPath, 'orientation', 'dubna.csv');\n[nodes, S] = orientation.load(fname,'columnNames',{'phi1','Phi','phi2','values'});\n\n%%\n% The second output |S| is a struct that contains a field |S.values| with\n% the function values from the fourth column. Next, we can make a section\n% plot to see, what we are dealing with\n\nplotSection(nodes, S.values,'all');\n\n%%\n% Now, we want to find a function which coincides with the given function\n% values in the nodes reasonably well.\n\n%% Interpolation\n%\n%%\n% Interpolation is done by the command\n% of class \n\nSO3F = SO3Fun.interpolate(nodes, S.values,'exact');\nplot(SO3F)\n\n%% \n% The interpolation is done by lsqr. Hence the error is not in machine\n% precision.\nnorm(SO3F.eval(nodes) - S.values)\n\n%%\n% If we don't restrict ourselfs to the given function values in the nodes, we have more\n% freedom, which can be seen in the case of approximation.\n\n%% Approximation\n%\n% In contrast to interpolation we are now not restricted to the function\n% values in the nodes but still want to keep the error reasonably small.\n%\n%%\n% One way is to interpolate the function similary as before, without the \n% option |'exact'|.\n%\n%%\n% Another way is to approximate the rotational function with a series of \n% (Harmonic series). \n% We don't take as many Wigner-D functions as there are nodes,\n% such that we are in the overdetermined case. In that way we don't have a\n% chance of getting the error in the nodes zero but hope for a smoother\n% approximation. This can be achieved by the \n% command of the class \n\nSO3F2 = SO3FunHarmonic.approximation(nodes, S.values);\nplot(SO3F2)\n\n%%\n% Plotting this function, we can immidiately see, that we have a much\n% smoother function. But one has to keep in mind that the error in the data\n% nodes is not zero as in the case of interpolation.\n\nnorm(eval(SO3F, nodes) - S.values)\n\n%%\n% But this may not be of great importance like in the case of function\n% approximation from noisy function values, where we don't know the exact\n% function values anyways.\n\n%%\n%\n% The strategy underlying the |approximation|-command\n% to obtain such an approximation works via Wigner-D functions\n% (). For that,\n% we seek for so-called Fourier-coefficients ${\\bf \\hat f} = (\\hat\n% f^{0,0}_0,\\dots,\\hat f^{N,N}_N)^T$ such that\n%\n% $$ g(x) = \\sum_{n=0}^N\\sum_{k,l = -n}^n \\hat f_n^{k,l} D_n^{k,l}(x) $$\n%\n% approximates our function. A basic strategy to achieve this is through\n% least squares, where we minimize the functional \n%\n% $$ \\sum_{m=1}^M|f(x_m)-g(x_m)|^2 $$\n%\n% for the data nodes $x_m$, $m=1,\\dots,M$, $f(x_m)$ the target function\n% values and $g(x_m)$ our approximation evaluated in the given data nodes.\n%\n% This can be done by the |lsqr| function of Matlab, which efficiently\n% seeks for roots of the derivative of the given functional (also known as\n% normal equation). In the process we compute the matrix-vector product\n% with the Fourier-matrix multible times, where the Fourier-matrix is given\n% by\n%\n% $$ F = [D_n^{k,l}(x_m)]_{m = 1,\\dots,M;~n = 0,\\dots,N,\\,k,l = -n,\\dots,n}. $$\n%\n% This matrix-vector product can be computed efficiently with the use of\n% the nonequispaced SO(3) Fourier transform\n% \n% or faster by the combination of an Wigner-transform together with a \n% .\n%\n% We end up with the Fourier-coefficients of our approximation $g$, which\n% describe our approximation.\n%\n", "meta": {"author": "mtex-toolbox", "repo": "mtex", "sha": "f0ce46a720935e9ae8106ef919340534bca1adcb", "save_path": "github-repos/MATLAB/mtex-toolbox-mtex", "path": "github-repos/MATLAB/mtex-toolbox-mtex/mtex-f0ce46a720935e9ae8106ef919340534bca1adcb/doc/SO3Functions/SO3FunApproximationInterpolation.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.8774767810736693, "lm_q1q2_score": 0.7995390325715506}}
{"text": "function [U, R, V] = cod(A, tol)\n%COD Complete orthogonal decomposition.\n% [U, R, V] = COD(A, TOL) computes a decomposition A = U*T*V,\n% where U and V are unitary, T = [R 0; 0 0] has the same dimensions as\n% A, and R is upper triangular and nonsingular of dimension rank(A).\n% Rank decisions are made using TOL, which defaults to approximately\n% LENGTH(A)*NORM(A)*EPS.\n% By itself, COD(A, TOL) returns R.\n\n% Reference:\n% G. H. Golub and C. F. Van Loan, Matrix Computations, third\n% edition, Johns Hopkins University Press, Baltimore, Maryland,\n% 1996; sec. 5.4.2.\n\n[m, n] = size(A);\n\n% QR decomposition.\n[U, R, P] = qr(A); % AP = UR\nV = P'; % A = URV;\nif nargin == 1, tol = max(m,n)*eps*abs(R(1,1)); end % |R(1,1)| approx NORM(A).\n\n% Determine r = effective rank.\nr = sum(abs(diag(R)) > tol);\nr = r(1); % Fix for case where R is vector.\nR = R(1:r,:); % Throw away negligible rows (incl. all zero rows, m>n).\n\nif r ~= n\n\n % Reduce nxr R' = r [L] to lower triangular form: QR' = [Lbar].\n % n-r [M] [0]\n\n [Q, R] = trap2tri(R');\n V = Q*V;\n R = R';\n\nend\n\nif nargout <= 1, U = R; end\n", "meta": {"author": "opencobra", "repo": "cobratoolbox", "sha": "e60274d127f65d518535fd0814d20c53dc530f73", "save_path": "github-repos/MATLAB/opencobra-cobratoolbox", "path": "github-repos/MATLAB/opencobra-cobratoolbox/cobratoolbox-e60274d127f65d518535fd0814d20c53dc530f73/external/base/utilities/matrixcomp/cod.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810481379379, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7994902267765951}}
{"text": "function [ti,fi]=midpoint(t1,f1,t2,f2,k)\n%MIDPOINT Mid-point construction used in the interference diagram. \n%\t[TI,FI]=MIDPOINT(T1,F1,T2,F2,K) gives the coordinates in the\n%\ttime-frequency plane of the interference-term corresponding to\n%\tthe points (T1,F1) and (T2,F2), for a distribution in the\n%\taffine class perfectly localized on power-law group-delays of \n%\tthe form : tx(nu)=t0+c nu^(K-1).\n%\n%\tT1 : time-coordinate of the first point\n%\tF1 : frequency-coordinate of the first point (>0)\n%\tT2 : time-coordinate of the second point\n%\tF2 : frequency-coordinate of the second point (>0)\n%\tK : power of the group-delay law\n%\t K = 2 : Wigner-Ville \n%\t K = 1/2 : D-Flandrin\n%\t K = 0 : Bertrand (unitary) \n%\t K = -1 : Unterberger (active)\n%\t K = inf : Margenau-Hill-Rihaczek\n%\tTI : time-coordinate of the interference term\n%\tFI : frequency-coordinate of the interference term\n%\n%\tSee also PLOTSID.\n\n%\tP. Flandrin, September 1995 - F. Auger, April 1996.\n%\tCopyright (c) 1996 by CNRS (France).\n%\n% This program is free software; you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation; either version 2 of the License, or\n% (at your option) any later version.\n%\n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with this program; if not, write to the Free Software\n% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n\nif f1<=0 | f2<=0,\n error('F1 and F2 must be >0');\nend\n[rt1,ct1]=size(t1);\n[rt2,ct2]=size(t2);\n[rf1,cf1]=size(f1);\n[rf2,cf2]=size(f2);\nif (rt1~=rt2|rt1~=rf1|rt1~=rf2) | (ct1~=ct2|ct1~=cf1|ct1~=cf2), \n error('T1, T2, F1 and F2 must have the same size');\nend\nif rt1>ct1,\n error('T1 must be a row-vector');\nelseif rt2>ct2,\n error('T2 must be a row-vector');\nelseif rf2>cf2,\n error('F2 must be a row-vector');\nelseif rf1>cf1,\n error('F1 must be a row-vector');\nend\n \nif (k==2),\n fi=(f1+f2)/2;\n ti=(t1+t2)/2;\nelseif (k==inf),\n ti=[t1;t2];\n fi=[f2;f1];\nelse\n I=find(abs(f1-f2)>sqrt(eps));\n if length(I)~=0, \n if (k==1),\n fi(I)=exp( (f1(I).*(log(f1(I))-1)-f2(I).*(log(f2(I))-1)) ./ ...\n \t(f1(I)-f2(I))); \n ti(I)=(t1(I).*f1(I)-t2(I).*f2(I)) ./ (f1(I)-f2(I)) - ...\n \t(t1(I)-t2(I)) ./ (log(f1(I))-log(f2(I)));\n elseif (k==0),\n fi(I)=(f1(I)-f2(I))./(log(f1(I))-log(f2(I)));\n ti(I)=(t1(I).*f1(I)-t2(I).*f2(I)) ./ (f1(I)-f2(I)) + ...\n f1(I) .* f2(I) .* (t2(I)-t1(I)) .* ...\n \t(log(f1(I))-log(f2(I))) ./ (f2(I)-f1(I)).^2; \n else\n t0(I)=(t1(I).*f2(I).^(k-1)-t2(I).*f1(I).^(k-1)) ./ ...\n \t(f2(I).^(k-1)-f1(I).^(k-1));\n fi(I)=((f1(I).^k-f2(I).^k) ./ (f1(I)-f2(I))/k).^(1/(k-1));\n ti(I)=t0(I)+(t2(I)-t1(I)) ./ (f2(I).^(k-1)-f1(I).^(k-1)) .*fi(I).^(k-1);\n end\n end\nend\n", "meta": {"author": "HeLiangHIT", "repo": "time_frequency", "sha": "09c2abe92355ff5cd867bdb169229682e9d7af7c", "save_path": "github-repos/MATLAB/HeLiangHIT-time_frequency", "path": "github-repos/MATLAB/HeLiangHIT-time_frequency/time_frequency-09c2abe92355ff5cd867bdb169229682e9d7af7c/tf_tool_box/tftb-0.2/mfiles/midpoint.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947179030095, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7994111367417014}}
{"text": "% KM_DEMO_KCCA Demo file for kernel canonical correlation analysis\n% algorithm.\n%\n% This script takes two multi-dimensional variables and uses kernel CCA to\n% map them onto a single latent 1-D variable. The kernel matrices are \n% decomposed using incomplete Cholesky decomposition in order to allow \n% large data sets. This demo includes 3 flavors of the KCCA generalized\n% eigenvalue problem, all yielding very similar results.\n%\n% Author: Steven Van Vaerenbergh (steven *at* gtas.dicom.unican.es), 2012.\n%\n% The algorithm in this file is based on the following publications: \n% D. R. Hardoon, S. Szedmak and J. Shawe-Taylor, \"Canonical Correlation \n% Analysis: An Overview with Application to Learning Methods\", Neural \n% Computation, Volume 16 (12), Pages 2639--2664, 2004.\n% F. R. Bach, M. I. Jordan, \"Kernel Independent Component Analysis\", Journal \n% of Machine Learning Research, 3, 1-48, 2002.\n%\n% This file is part of the Kernel Methods Toolbox for MATLAB.\n% https://github.com/steven2358/kmbox\n\nclose all; clear\nrs = 1; % seed for random generator\nrng('default')\nrng(rs)\n\n%% PARAMETERS\nN = 1000;\t% number of samples. method's complexity is O(NM^2)\nMmax = 50; % max. M (number of components in incomplete Cholesky decomp.)\nreg = 1E-5; % regularization\nkerneltype = 'gauss'; % kernel type\nkernelpar = 1; % kernel parameter\n\n%% PROGRAM\ntic\n\n% generate data\ns = randn(N,1);\t% latent signal\nr1 = randn(N,1); r2 = randn(N,1);\t% random (helper) variables\n\n% option 1: two multi-dimensional variables that are mappable onto s\nx1 = [tanh(r1-s)+0.1*r1 r1+3*s-1/10*(sin(3*s))];\nx2 = [s - 2*(1-exp(-r2))./(1+exp(-r2)) r2.*s tanh(r2+s)];\n\n% option 2: two invertible 1D nonlinear transformations\n% x1 = tanh(0.8*s)+0.1*s;\t% moderate saturation\n% x2 = -1/10*(sin(s*3)+1.1*s*3); % stairway\n\n% clean up: remove mean\nx1 = x1-repmat(mean(x1),N,1);\nx2 = x2-repmat(mean(x2),N,1);\n\n% normalize variance (to improve anisotropy) or any other preprocessing\nx1 = x1*sqrt(diag(1./diag(x1'*x1)));\nx2 = x2*sqrt(diag(1./diag(x2'*x2)));\n\n% KCCA\n[y1,y2,beta] = km_kcca(x1,x2,kerneltype,kernelpar,reg,1,'ICD',Mmax);\n\n% scale the estimated signals to compare without the scalar ambiguity\nscaling = sqrt(var(s))/sqrt(var(y1))*sign(s(1))*sign(y1(1));\n\n% mean square errors\nerror1 = s-scaling*y1;\nerror2 = s-scaling*y2;\nMSE1 = sum(error1.^2)/N;\nMSE2 = sum(error2.^2)/N;\n\ntoc\n%% OUTPUT\n\nfigure; hold all\nplot(s)\nplot(scaling*y1);\nplot(scaling*y2);\nlegend('latent variable','projection 1','projection 2')\n\nfprintf('2x %d data points\\n',N)\nfprintf('Canonical correlation: %f\\n',beta)\nfprintf('MSE1: %f\\n',MSE1);\nfprintf('MSE2: %f\\n',MSE2);\nfprintf('\\n')\n\n% figure;plot(sort(diag(real(betas)))) % check eigenvalues\n% figure;plot(sort(diag(betas))); % imaginary part due to numerical error\n", "meta": {"author": "epfl-lasa", "repo": "ML_toolbox", "sha": "61cc1245a2abe0c86a737d7b48bd645b28ffebee", "save_path": "github-repos/MATLAB/epfl-lasa-ML_toolbox", "path": "github-repos/MATLAB/epfl-lasa-ML_toolbox/ML_toolbox-61cc1245a2abe0c86a737d7b48bd645b28ffebee/methods/toolboxes/kmbox/demo/km_demo_kcca.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218262741297, "lm_q2_score": 0.8670357666736772, "lm_q1q2_score": 0.7993391974567866}}
{"text": "%HOMLINE Homogeneous line from two points\n%\n% L = HOMLINE(X1, Y1, X2, Y2) is a vector (3x1) which describes a line in\n% homogeneous form that contains the two Euclidean points (X1,Y1) and (X2,Y2).\n%\n% Homogeneous points X (3x1) on the line must satisfy L'*X = 0.\n%\n% See also PLOT_HOMLINE.\n\n% Copyright (C) 1993-2014, by Peter I. Corke\n%\n% This file is part of The Robotics Toolbox for MATLAB (RTB).\n% \n% RTB is free software: you can redistribute it and/or modify\n% it under the terms of the GNU Lesser General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% RTB is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU Lesser General Public License for more details.\n% \n% You should have received a copy of the GNU Leser General Public License\n% along with RTB. If not, see .\n%\n% http://www.petercorke.com\n\n% TODO, probably should be part of a HomLine class.\n\nfunction l = homline(x1, y1, x2, y2)\n\n l = cross([x1 y1 1], [x2 y2 1]);\n\n % normalize so that the result of x*l' is the pixel distance\n % from the line\n l = l / norm(l(1:2));\n", "meta": {"author": "Allopart", "repo": "rbpf-gmapping", "sha": "affe0adc25fa446fc7af4902d699d92864bdba1b", "save_path": "github-repos/MATLAB/Allopart-rbpf-gmapping", "path": "github-repos/MATLAB/Allopart-rbpf-gmapping/rbpf-gmapping-affe0adc25fa446fc7af4902d699d92864bdba1b/rvctools/common/homline.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.799237388741176}}
{"text": "function voronoi_neighbor_test01 ( )\n\n%*****************************************************************************80\n%\n%% VORONOI_NEIGHBOR_TEST01 demonstrates VORONOI_NEIGHBORS\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 08 December 2013\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'VORONOI_NEIGHBORS_TEST01:\\n' );\n fprintf ( 1, ' Select a random set of points in the unit square.\\n' );\n fprintf ( 1, ' Compute the Voronoi diagram.\\n' );\n fprintf ( 1, ' Have VORONOI_NEIGHBORS determine the neighbors.\\n' );\n\n n = 8;\n x = rand ( n, 2 );\n%\n% Compute and display the Voronoi diagram.\n%\n figure ( );\n\n hold on\n voronoi ( x(:,1), x(:,2) );\n for i = 1 : n\n txt = sprintf ( '%d', i );\n text ( x(i,1), x(i,2), txt, 'FontSize', 12 );\n end\n hold off\n\n filename = 'voronoi_neighbors_test01.png';\n print ( '-dpng', filename );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Voronoi diagram saved as \"%s\".\\n', filename );\n%\n% Compute and list the finite Voronoi edges.\n%\n [ V, C ] = voronoin ( x );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Voronoi edges:\\n' );\n fprintf ( 1, '\\n' );\n for i = 1 : length ( C )\n disp ( C{i} )\n end\n%\n% Compute the Voronoi neighbors.\n%\n vn = voronoi_neighbors ( x );\n%\n% To print the matrix, make a full version.\n%\n vn = full ( vn );\n i4mat_print ( n, n, vn, ' Voronoi adjacency:' )\n\n return\nend\n\n\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/voronoi_neighbors/voronoi_neighbors_test01.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8887587875995482, "lm_q1q2_score": 0.7991020251672709}}
{"text": "function y = trapmf(x, params)\n%TRAPMF Trapezoidal membership function.\n% TRAPMF(X, PARAMS) returns a matrix which is the trapezoidal\n% membership function evaluated at X. PARAMS = [A B C D] is a 4-element\n% vector that determines the break points of this membership function.\n% We require that A <= B and C <= D. If B >= C, this membership\n% function becomes a triangular membership function that could have\n% a height less than unity. (See the example below.)\n%\n% For example:\n%\n% x = (0:0.1:10)';\n% y1 = trapmf(x, [2 3 7 9]);\n% y2 = trapmf(x, [3 4 6 8]);\n% y3 = trapmf(x, [4 5 5 7]);\n% y4 = trapmf(x, [5 6 4 6]);\n% plot(x, [y1 y2 y3 y4]);\n% set(gcf, 'name', 'trapmf', 'numbertitle', 'off');\n%\n% See also DSIGMF, EVALMF, GAUSS2MF, GAUSSMF, GBELLMF, MF2MF, PIMF, PSIGMF,\n% SIGMF, SMF, TRIMF, ZMF.\n\n% Roger Jang, 6-28-93, 10-5-93, 4-14-94.\n% Copyright 1994-2002 The MathWorks, Inc. \n% $Revision: 1.22 $ $Date: 2002/04/14 22:21:13 $\n\nif nargin ~= 2\n error('Two arguments are required by the trapezoidal MF.');\nelseif length(params) < 4\n error('The trapezoidal MF needs at least four parameters.');\nend\n\na = params(1); b = params(2); c = params(3); d = params(4);\n\nif a > b,\n error('Illegal parameter condition: a > b');\nelseif c > d,\n error('Illegal parameter condition: c > d');\nend\n\ny1 = zeros(size(x));\ny2 = zeros(size(x));\n\n% Compute y1\nindex = find(x >= b);\nif ~isempty(index),\n y1(index) = ones(size(index));\nend\nindex = find(x < a);\nif ~isempty(index),\n y1(index) = zeros(size(index));\nend\nindex = find(a <= x & x < b);\nif ~isempty(index) & a ~= b,\n y1(index) = (x(index)-a)/(b-a);\nend\n\n% Compute y2\nindex = find(x <= c);\nif ~isempty(index),\n y2(index) = ones(size(index));\nend\nindex = find(x > d);\nif ~isempty(index),\n y2(index) = zeros(size(index));\nend\nindex = find(c < x & x <= d);\nif ~isempty(index) & c ~= d,\n y2(index) = (d-x(index))/(d-c);\nend\n\n% Compute y\ny = min(y1, y2);\n", "meta": {"author": "leoliuf", "repo": "MRiLab", "sha": "5cdcf1f7b67759700685d3a26ffeb70e55325567", "save_path": "github-repos/MATLAB/leoliuf-MRiLab", "path": "github-repos/MATLAB/leoliuf-MRiLab/MRiLab-5cdcf1f7b67759700685d3a26ffeb70e55325567/External/MatrixUser2.2/External/Matlab/trapmf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.8757869819218865, "lm_q1q2_score": 0.799099715351165}}
{"text": "function [ w, xy ] = triangle_unit_o03 ( )\n\n%*****************************************************************************80\n%\n%% TRIANGLE_UNIT_O03 returns a 3 point quadrature rule for the unit triangle.\n%\n% Discussion:\n%\n% This rule is precise for monomials through degree 2.\n%\n% The integration region is:\n%\n% 0 <= X\n% 0 <= Y\n% X + Y <= 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 06 April 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Carlos Felippa,\n% A compendium of FEM integration formulas for symbolic work,\n% Engineering Computation,\n% Volume 21, Number 8, 2004, pages 867-890.\n%\n% Parameters:\n%\n% Output, real W(3), the weights.\n%\n% Output, real XY(2,3), the abscissas.\n%\n w(1:3,1) = [ ...\n 0.33333333333333333333, ...\n 0.33333333333333333333, ...\n 0.33333333333333333333 ];\n\n xy(1:2,1:3) = [ ...\n 0.66666666666666666667, 0.16666666666666666667; ...\n 0.16666666666666666667, 0.66666666666666666667; ...\n 0.16666666666666666667, 0.16666666666666666667 ]';\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/triangle_felippa_rule/triangle_unit_o03.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404096760998, "lm_q2_score": 0.8596637559030337, "lm_q1q2_score": 0.7990062334702103}}
{"text": "function r = trirnd(varargin)\n%TRIRND Pseudorandom numbers drawn from the triangular distribution\n% \n% R = IOSR.STATISTICS.TRIRND(N) returns an N-by-N matrix containing\n% pseudorandom values drawn from the triangular distribution constrained\n% to (-1,1) and mode = 0.\n% \n% IOSR.STATISTICS.TRIRND(M,N) or IOSR.STATISTICS.TRIRND([M,N]) returns an\n% M-by-N matrix.\n% \n% IOSR.STATISTICS.TRIRND(M,N,P,...) or\n% IOSR.STATISTICS.TRIRND([M,N,P,...]) returns an M-by-N-by-P-by-...\n% array.\n% \n% IOSR.STATISTICS.TRIRND returns a scalar.\n% \n% TRIRND(SIZE(A)) returns an array the same size as A.\n%\n% Note: The size inputs M, N, P, ... should be nonnegative integers.\n% Negative integers are treated as 0.\n%\n% The sequence of numbers produced by TRIRND is determined by the\n% settings of the uniform random number generator that underlies RAND,\n% RANDI, and RANDN. Control that shared random number generator using\n% RNG.\n% \n% See also IOSR.STATISTICS.LAPRND, RAND, RANDN, RANDI, RNG.\n\n% Based on code (Matlab FE File ID: #13705) written by Elvis Chen, 2007.\n\n% Copyright 2016 University of Surrey.\n\n % Generate traingular noise\n u1 = rand(varargin{:})-0.5;\n u2 = rand(varargin{:})-0.5;\n r = u1+u2;\n\nend\n", "meta": {"author": "IoSR-Surrey", "repo": "MatlabToolbox", "sha": "4bff1bb2da7c95de0ce2713e7c710a0afa70c705", "save_path": "github-repos/MATLAB/IoSR-Surrey-MatlabToolbox", "path": "github-repos/MATLAB/IoSR-Surrey-MatlabToolbox/MatlabToolbox-4bff1bb2da7c95de0ce2713e7c710a0afa70c705/+iosr/+statistics/trirnd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7989589198984113}}
{"text": "%% Structured grid\n% This is a sample code showing how to use ConstructProjector2D().\n% This example is going to setup a transformation matrix based on forth\n% order polynomials in 2D. \n% Pay attention that no data is needed to construct the interpolator. Only\n% the coordinates of the points on source and destination grid.\nclear;clc;\n%% Initializing Part I\ndisp('- Initializing')\nxMin=0;\nxMax=2*pi;\nyMin=0;\nyMax=2*pi;\n\nnx=40;\nny=40;\n\nnPoly=4; % We gonna fit a fourth order polynomial, \n % i.e. sum_{n,m=0}^{n,m=nPoly} x^n*y^m \nnInterp=30; % nPoly=4 requires 25 points. However, \n % we are going to use 30 points. This would be \n % the least-square fit of the surface.\n % Note that: min(nInterp)=(nPoly+1)^2. Otherwise it won't work.\n%% Turning off the warnings\n% Depending on the parameter that you choose the matrices might be nearly\n% singular. In this example, despite being nearly singular, they are not \n% affecting the final interpolation. Therefore, I set the warning to off. \n% But generally do not turn it off and if you got this warning check if it \n% is going to affect your results or not.\ndisp('- Turning the warnings off')\nwarning('OFF','MATLAB:nearlySingularMatrix');\n\n%% Generating the Source Grid\ndisp('- Generating the source grid.')\n[xn,yn]=meshgrid(linspace(xMin,xMax,nx),linspace(yMin,yMax,ny));\n\n%% Finding the cell centers\ndisp('- Generating the destination grid')\nxc=(xn(1:ny-1,1:nx-1)+xn(2:ny,1:nx-1)+xn(1:ny-1,2:nx)+xn(2:ny,2:nx))*0.25;\nyc=(yn(1:ny-1,1:nx-1)+yn(2:ny,1:nx-1)+yn(1:ny-1,2:nx)+yn(2:ny,2:nx))*0.25;\n\nfigure\nsurface(xn,yn,zeros(size(xn)));\nhold on\nplot(xn,yn,'k.');\nplot(xc,yc,'b.');\naxis tight;\naxis square;\ntitle('Source Grid, black dots, & the destination grid, blue dots.', ...\n 'FontName','Arial','FontSize',12,'FontWeight','Bold');\n%% Constructing the Interpolant\n% Note: that we do not need the data on the source grid to create the\n% interpolant.\ndisp('- Constructing the interpolant')\nP=ConstructProjector2D(xn(:),yn(:),xc(:),yc(:),nPoly,nInterp);\n\n%% Generarting some Data\ndisp('- Generating some data and interpolating')\nF1=@(x,y) (sin(sqrt(x.^2+y.^2)));\nzn=F1(xn,yn);\nzc_interp=reshape(P*zn(:),size(xc));\nzc_Analytic=F1(xc,yc);\nRMSE=sqrt(mean((zc_Analytic(:)-zc_interp(:)).^2));\n\nfigure\nsurface(xc,yc,zc_interp,'EdgeColor','none');\ntitle(['nPoly: ' num2str(nPoly) ', RMSE= ' num2str(RMSE)]);\naxis tight\n\n%% Generating some more data\ndisp('- Generating multiple data field on the source grid and interpolating them.')\nF2=@(x,y) (sin(x).*cos(y));\nF3=@(x,y) (exp(-sqrt(x.^2+y.^2)));\nF4=@(x,y,x0,y0) (exp(-sqrt((x-x0).^2+(y-y0).^2)));\n\nzn(:,:,1)=F1(xn,yn);\nzn(:,:,2)=F2(xn,yn);\nzn(:,:,3)=F3(xn,yn);\nzn(:,:,4)=F4(xn,yn,mean(mean(xn)),mean(mean(yn)));\n\nzc_Analytic(:,:,1)=F1(xc,yc);\nzc_Analytic(:,:,2)=F2(xc,yc);\nzc_Analytic(:,:,3)=F3(xc,yc);\nzc_Analytic(:,:,4)=F4(xc,yc,mean(mean(xn)),mean(mean(yn)));\n\n% Now interpolating\n% Note that the same interpolant is used for all data fields and they can\n% be all interpolated with one sparse matrix multiplication.\nzc_interp=P*reshape(zn,nx*ny,4); % There are 4 data fields.\nzc_interp=reshape(zc_interp,(nx-1),(ny-1),4); % these two commands can be combined in one.\n % They were separated for clarity.\n\n% calculating the RMSE and plotting\nRMSE=zeros(4,1);\nfigure\nfor i=1:4\n RMSE(i)=sqrt(mean((reshape(zc_Analytic(:,:,i),(nx-1)*(ny-1),1)-reshape(zc_interp(:,:,i),(nx-1)*(ny-1),1)).^2));\n subplot(2,2,i);\n surface(xc,yc,squeeze(zc_interp(:,:,i)),'EdgeColor','none');\n title(['F' num2str(i) ', nPoly: ' num2str(nPoly) ', RMSE:' num2str(RMSE(i))])\n axis tight\n axis square\nend\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/41669-interpolantextrapolant-2d3d-data/Projector/Test_StructuredGrid_2D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167045, "lm_q2_score": 0.8615382076534743, "lm_q1q2_score": 0.798958904656929}}
{"text": "function values = coeffs2vals(coeffs)\n%COEFFS2VALS Convert Fourier coefficients to values at N equally spaced\n%points between [-1 1), where N is the number of coefficients.\n% V = COEFFS2VALS(C) returns the values of the trignometric polynomial \n% as follows:\n% If N is odd\n% F(x) = C(1)*z^(-(N-1)/2) + C(2)*z^(-(N-1)/2-1) + ... + C(N)*z^((N-1)/2)\n% If N is even\n% F(x) = C(1)*z^(-N/2) + C(2)*z^(-N/2+1) + ... + C(N)*z^(N/2-1)\n% where z = exp(1i*pi*x) and -1 <= x <= 1. \n%\n% If the input C is an (N+1)xM matrix then V = COEFFS2VALS(C) returns the\n% (N+1)xM matrix of values V such that V(i,j) is the ith value of the\n% trignometric polynomial corresponding to the jth column.\n%\n% See also VALS2COEFFS, TRIGPTS.\n\n% Copyright 2017 by The University of Oxford and The Chebfun Developers. \n% See http://www.chebfun.org/ for Chebfun information.\n\n% *Note about symmetry*. Some of the code below is designed to\n% enforce two symmetries whose failure might disturb users:\n% COEFFS exactly real ==> VALUES exactly hermitian\n% COEFFS exactly imaginary ==> VALUES exactly skew-hermitian\n% This is necessary because the MATLAB FFT code does not\n% exactly preserve symmetries.\n\n% Get the length of the input:\nn = size(coeffs, 1);\n\n% Trivial case (constant or empty):\nif ( n <= 1 )\n values = coeffs; \n return\nend\n\n% The coefficients are for interpolation defined on [-pi,pi), but the FFT\n% works for values on [0,2*pi). To fix the coefficients for this we just need to\n% assign c_k = (-1)^k c_k, with k=-(N-1)/2:(N-1)/2 for N odd, and \n% k = -N/2:N/2-1 for N even.\nif ( mod(n, 2) ) \n even_odd_fix = (-1).^(-(n-1)/2:(n-1)/2).';\nelse\n even_odd_fix = (-1).^((-n/2):(n/2-1)).';\nend\ncoeffs = bsxfun(@times, coeffs, even_odd_fix);\n\n% test for symmetry\nisHerm = max(abs(imag(coeffs)),[],1) == 0;\nisSkew = max(abs(real(coeffs)),[],1) == 0;\n\n% Shift the coefficients properly.\nvalues = ifft(ifftshift(n*coeffs, 1), [], 1);\n\n% correct if symmetric\nvals = [values;values(1,:)];\nhermvals = (vals+flipud(conj(vals)))/2;\nskewvals = (vals-flipud(conj(vals)))/2;\nvalues(:,isHerm) = hermvals(1:end-1,isHerm);\nvalues(:,isSkew) = skewvals(1:end-1,isSkew);\n\nend\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/@trigtech/coeffs2vals.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529786117893, "lm_q2_score": 0.8872045966995027, "lm_q1q2_score": 0.7989541657086147}}
{"text": "function OUT = datatreat(DATA,vtreat,nlag)\n% =======================================================================\n% Treat a time series with the specified method. If changes are computed\n% the function assumes 1 lag (unless otherwise specified)\n% =======================================================================\n% OUT = datatreat(DATA,vtreat,lag)\n% -----------------------------------------------------------------------\n% INPUT\n%\t- DATA: matrix DATA(T,N)\n% - vtreat: 0 No treatment \n% 1\tLog\n% 2 Difference\n% 3\tLog Difference\n% 4 Percent change\n% -----------------------------------------------------------------------\n% OPTIONAL INPUT\n% - lag: number of lags for changes\n% -----------------------------------------------------------------------\n% OUTPUT\n%\t- OUT: matrix DATA(T,N) of treated data. The first \"nlag\"\n% observations are NaNs\n% -----------------------------------------------------------------------\n% EXAMPLE\n% x = [1 2; -3 4; 5 6; 7 8; 9 10];\n% OUT = datatreat(x,3)\n% =======================================================================\n% VAR Toolbox 3.0\n% Ambrogio Cesa-Bianchi\n% ambrogiocesabianchi@gmail.com\n% March 2012. Updated November 2020\n% -----------------------------------------------------------------------\n\n% Check input\nif ~exist('nlag','var')\n nlag = 1;\nend\n\n% Set matrices\n[nobs, nvar] = size(DATA);\nOUT = nan(nobs,nvar);\n\n% No treatment\nif vtreat==0\n OUT = DATA;\n\n% Log\nelseif vtreat==1\n if ~isempty(DATA<0), warning('Negative numbers set to NaN before taking logs'), end\n DATA(DATA<0) = NaN;\n OUT = log(DATA);\n \n% Difference\nelseif vtreat==2\n OUT(nlag+1:end,:) = DATA(1+nlag:end,:) - DATA(1:end-nlag,:);\n \n% Log difference\nelseif vtreat==3\n if ~isempty(DATA<0), warning('Negative numbers set to NaN before taking logs'), end\n DATA(DATA<0) = NaN;\n OUT(nlag+1:end,:) = log(DATA(1+nlag:end,:))-log(DATA(1:end-nlag,:));\n\n% Percent change\nelseif vtreat==4\n OUT(nlag+1:end,:) = DATA(1+nlag:end,:)./DATA(1:end-nlag,:)-1;\nend\n", "meta": {"author": "ambropo", "repo": "VAR-Toolbox", "sha": "9fe5d763da307cdded2827851325766b3a7c60e1", "save_path": "github-repos/MATLAB/ambropo-VAR-Toolbox", "path": "github-repos/MATLAB/ambropo-VAR-Toolbox/VAR-Toolbox-9fe5d763da307cdded2827851325766b3a7c60e1/v3dot0/Utils/datatreat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.939913354875362, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7988992646177332}}
{"text": "function kappa = surfaceCurvature(kappa1, kappa2, theta)\n%SURFACECURVATURE Curvature on a surface from angle and principal curvatures.\n%\n% usage:\n% KAPPA = surfaceCurvature(KAPPA1, KAPPA2, THETA)\n% return the curvature KAPPA of surface with respect to direction THETA.\n\n% KAPPA1 and KAPPA2 are the principal curvatures of the surface at the\n% considered point. THETA is angle of direction relative to angle of\n% first principal curvature KAPPA1.\n%\n% Examples:\n% K = surfaceCurvature(KAPPA1, KAPPA2, 0) returns KAPPA1.\n% K = surfaceCurvature(KAPPA1, KAPPA2, pi/2) returns KAPPA2.\n%\n%\n% ---------\n%\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 07/04/2004.\n%\n\n% HISTORY\n% 20/04/2004 change name and add doc.\n% 14/06/2004 correct creation date\n\nkappa = kappa1 * cos(theta).^2 + kappa2 * sin(theta).^2;\n", "meta": {"author": "Arrowstar", "repo": "ksptot", "sha": "2b414440d3b167ba2294f56dafce0f465c07f982", "save_path": "github-repos/MATLAB/Arrowstar-ksptot", "path": "github-repos/MATLAB/Arrowstar-ksptot/ksptot-2b414440d3b167ba2294f56dafce0f465c07f982/helper_methods/z_geom3d/geom3d/surfaceCurvature.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308128813471, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.7988778386829933}}
{"text": "function [f,P,prob] = lomb(t,h,ofac,hifac)\n% LOMB(T,H,OFAC,HIFAC) computes the Lomb normalized periodogram (spectral\n% power as a function of frequency) of a sequence of N data points H,\n% sampled at times T, which are not necessarily evenly spaced. T and H must\n% be vectors of equal size. The routine will calculate the spectral power\n% for an increasing sequence of frequencies (in reciprocal units of the\n% time array T) up to HIFAC times the average Nyquist frequency, with an\n% oversampling factor of OFAC (typically >= 4).\n% \n% The returned values are arrays of frequencies considered (f), the\n% associated spectral power (P) and estimated significance of the power\n% values (prob). Note: the significance returned is the false alarm\n% probability of the null hypothesis, i.e. that the data is composed of\n% independent gaussian random variables. Low probability values indicate a\n% high degree of significance in the associated periodic signal.\n% \n% Although this implementation is based on that described in Press,\n% Teukolsky, et al. Numerical Recipes In C, section 13.8, rather than using\n% trigonometric rercurrences, this takes advantage of MATALB's array\n% operators to calculate the exact spectral power as defined in equation\n% 13.8.4 on page 577. This may cause memory issues for large data sets and\n% frequency ranges.\n% \n% Example \n% [f,P,prob] = lomb(t,h,4,1); \n% plot(f,P)\n% [Pmax,jmax] = max(P)\n% disp(['Most significant period is ',num2str(1/f(jmax)),...\n% ' with FAP of ',num2str(prob(jmax))])\n% \n% Written by Dmitry Savransky 21 May 2008\n\n%sample length and time span\nN = length(h);\nT = max(t) - min(t);\n\n%mean and variance \nmu = mean(h);\ns2 = var(h);\n\n%calculate sampling frequencies\nf = (1/(T*ofac):1/(T*ofac):hifac*N/(2*T)).';\n\n%angular frequencies and constant offsets\nw = 2*pi*f;\ntau = atan2(sum(sin(2*w*t.'),2),sum(cos(2*w*t.'),2))./(2*w);\n\n%spectral power\ncterm = cos(w*t.' - repmat(w.*tau,1,length(t)));\nsterm = sin(w*t.' - repmat(w.*tau,1,length(t)));\nP = (sum(cterm*diag(h-mu),2).^2./sum(cterm.^2,2) + ...\n sum(sterm*diag(h-mu),2).^2./sum(sterm.^2,2))/(2*s2);\n\n%estimate of the number of independent frequencies\nM=2*length(f)/ofac;\n\n%statistical significane of power\nprob = M*exp(-P);\ninds = prob > 0.01;\nprob(inds) = 1-(1-exp(-P(inds))).^M;\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/20004-lomb-lomb-scargle-periodogram/lomb.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308091776496, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7988778337972019}}
{"text": "function value = normal_ms_moment ( order, mu, sigma )\n\n%*****************************************************************************80\n%\n%% NORMAL_MS_MOMENT evaluates moments of the Normal PDF.\n%\n% Discussion:\n%\n% The formula was posted by John D Cook.\n%\n% Order Moment\n% ----- ------\n% 0 1\n% 1 mu\n% 2 mu^2 + sigma^2\n% 3 mu^3 + 3 mu sigma^2\n% 4 mu^4 + 6 mu^2 sigma^2 + 3 sigma^4\n% 5 mu^5 + 10 mu^3 sigma^2 + 15 mu sigma^4\n% 6 mu^6 + 15 mu^4 sigma^2 + 45 mu^2 sigma^4 + 15 sigma^6\n% 7 mu^7 + 21 mu^5 sigma^2 + 105 mu^3 sigma^4 + 105 mu sigma^6\n% 8 mu^8 + 28 mu^6 sigma^2 + 210 mu^4 sigma^4 + 420 mu^2 sigma^6 + 105 sigma^8\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 30 August 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer ORDER, the order of the moment.\n% 0 <= ORDER.\n%\n% Input, real MU, the mean of the distribution.\n%\n% Input, real SIGMA, the standard deviation of the distribution.\n%\n% Output, real VALUE, the value of the central moment.\n%\n j_hi = floor ( order / 2 );\n\n value = 0.0;\n for j = 0 : j_hi\n value = value ...\n + r8_choose ( order, 2 * j ) ...\n * r8_factorial2 ( 2 * j - 1 ) ...\n * mu ^ ( order - 2 * j ) * sigma ^ ( 2 * j );\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/truncated_normal/normal_ms_moment.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331956, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.798877831688011}}
{"text": "function corr_coef = RegreesionTID2013(objectiveValues,mos)\n%this script is used to calculate the pearson linear correlation\n%coefficient and root mean sqaured error after regression\n\n%get the objective scores computed by the IQA metric and the subjective\n%scores provided by the dataset\n% matData = load('VSIOnTID2013.mat');\n% VSIOnTID2013 = matData.VSIOnTID2013;\n% objectiveValues = VSIOnTID2013(:,1);\n% mos = VSIOnTID2013(:,2);\n\n%plot objective-subjective score pairs\n% p = plot(objectiveValues,mos,'+');\n% set(p,'Color','blue','LineWidth',1);\n\n%initialize the parameters used by the nonlinear fitting function\nbeta(1) = 10;\nbeta(2) = 0;\nbeta(3) = mean(objectiveValues);\nbeta(4) = 0.1;\nbeta(5) = 0.1;\n%fitting a curve using the data\n[bayta ehat,J] = nlinfit(objectiveValues,mos,@logistic,beta);\n%given an objective value, predict the correspoing mos (ypre) using the fitted curve\n[ypre junk] = nlpredci(@logistic,objectiveValues,bayta,ehat,J);\n\nRMSE = sqrt(sum((ypre - mos).^2) / length(mos));%root meas squared error\ncorr_coef = corr(mos, ypre, 'type','Pearson'); %pearson linear coefficient\n\n%draw the fitted curve\n% t = min(objectiveValues):0.01:max(objectiveValues);\n% [ypre junk] = nlpredci(@logistic,t,bayta,ehat,J);\n% hold on;\n% p = plot(t,ypre);\n% set(p,'Color','black','LineWidth',2);\n% legend('Images in TID2013','Curve fitted with logistic function', 'Location','NorthWest');\n% xlabel('Objective score by VSI');\n% ylabel('MOS');\n\n", "meta": {"author": "HuiZeng", "repo": "BIQA_Toolbox", "sha": "39d606574f0cbfde82ecbc3c208b353d9fa9a450", "save_path": "github-repos/MATLAB/HuiZeng-BIQA_Toolbox", "path": "github-repos/MATLAB/HuiZeng-BIQA_Toolbox/BIQA_Toolbox-39d606574f0cbfde82ecbc3c208b353d9fa9a450/tools/NonlinearFitting/RegressionTID2013.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7988778306273879}}
{"text": "function prob_test094 ( )\n\n%*****************************************************************************80\n%\n%% TEST094 tests INVERSE_GAUSSIAN_MEAN, INVERSE_GAUSSIAN_SAMPLE, INVERSE_GAUSSIAN_VARIANCE.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n nsample = 1000;\n seed = 123456789;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST094\\n' );\n fprintf ( 1, ' For the Inverse Gaussian PDF:\\n' );\n fprintf ( 1, ' INVERSE_GAUSSIAN_MEAN computes the mean;\\n' );\n fprintf ( 1, ' INVERSE_GAUSSIAN_SAMPLE samples;\\n' );\n fprintf ( 1, ' INVERSE_GAUSSIAN_VARIANCE computes the variance.\\n' );\n\n a = 2.0;\n b = 3.0;\n\n check = inverse_gaussian_check ( a, b );\n\n if ( ~check );\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST094 - Fatal error!\\n' );\n fprintf ( 1, ' The parameters are not legal.\\n' );\n return\n end\n\n mean = inverse_gaussian_mean ( a, b );\n variance = inverse_gaussian_variance ( a, b );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' PDF parameter A = %14f\\n', a );\n fprintf ( 1, ' PDF parameter B = %14f\\n', b );\n fprintf ( 1, ' PDF mean = %14f\\n', mean );\n fprintf ( 1, ' PDF variance = %14f\\n', variance );\n\n for i = 1 : nsample\n [ x(i), seed ] = inverse_gaussian_sample ( a, b, seed );\n end\n\n mean = r8vec_mean ( nsample, x );\n variance = r8vec_variance ( nsample, x );\n xmax = max ( x(1:nsample) );\n xmin = min ( x(1:nsample) );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Sample size = %6d\\n', nsample );\n fprintf ( 1, ' Sample mean = %14f\\n', mean );\n fprintf ( 1, ' Sample variance = %14f\\n', variance );\n fprintf ( 1, ' Sample maximum = %14f\\n', xmax );\n fprintf ( 1, ' Sample minimum = %14f\\n', xmin );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/prob/prob_test094.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7988778233702638}}
{"text": "function interp_Function_Coeffs(x1,x2)\n\n\nmat1 = [1 0 0 0 0 0 0 0 0 0 0 0];\nmat2 = [0 1 0 0 0 0 0 0 0 0 0 0];\nmat3 = [0 0 1 0 0 0 0 0 0 0 0 0];\nmat4 = [1 x1 x1^2 x1^3 -1 -x1 -x1^2 -x1^3 0 0 0 0];\nmat5 = [0 1 2*x1 3*x1^2 0 -1 -2*x1 -3*x1^2 0 0 0 0];\nmat6 = [0 0 2 6*x1 0 0 -2 -6*x1 0 0 0 0];\n\nmat7 = [0 0 0 0 1 x2 x2^2 x2^3 -1 -x2 -x2^2 -x2^3];\nmat8 = [0 0 0 0 0 1 2*x2 3*x2^2 0 -1 -2*x2 -3*x2^2];\nmat9 = [0 0 0 0 0 0 2 6*x2 0 0 -2 -6*x2];\n\nmat10= [0 0 0 0 0 0 0 0 1 1 1 1];\nmat11= [0 0 0 0 0 0 0 0 0 1 2 3];\nmat12= [0 0 0 0 0 0 0 0 0 0 2 6];\n\nmat = [mat1; mat2; mat3; mat4; mat5; mat6; mat7; mat8; mat9; mat10; mat11; mat12];\n\nrhs = [0 0 0 0 0 0 0 0 0 1 0 0]';\n\n%mat1 = [-x1^2 0 x1^3 x1^2 x1 1];\n%mat2 = [-2*x1 0 3*x1^2 2*x1 1 0];\n%mat3 = [-2 0 6*x1 2 0 0];\n%mat4 = [0 (x2-1)^2 x2^3 x2^2 x2 1];\n%mat5 = [0 2*(x2-1) 3*x2^2 2*x2 1 0];\n%mat6 = [0 2 6*x2 2 0 0];\n%mat = [mat1; mat2; mat3; mat4; mat5; mat6];\n%rhs = [0 0 0 1 0 0]';\n\ncoeffs = mat\\rhs\n\n\n\na0 = coeffs(1);\na1 = coeffs(2); \na2 = coeffs(3);\na3 = coeffs(4);\nb0 = coeffs(5); \nb1 = coeffs(6);\nb2 = coeffs(7);\nb3 = coeffs(8); \nc0 = coeffs(9);\nc1 = coeffs(10);\nc2 = coeffs(11); \nc3 = coeffs(12);\n\nds = 0.01;\nx = 0:ds:1;\n\nfigure(1)\nfor i=1:length(x)\n plot(x(i),g(coeffs,x(i),x1,x2),'*'); hold on;\nend\n\n\nfigure(2)\nfor i=1:length(x)\n plot(x(i),gP(coeffs,x(i),x1,x2),'*'); hold on;\nend\n\nfigure(3)\nfor i=1:length(x)\n plot(x(i),gPP(coeffs,x(i),x1,x2),'*'); hold on;\nend\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% FUNCTION: evaluate interpolating polynomial\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nfunction val = g(coeffs,x,x1,x2)\n\nif x<=x1\n val = coeffs(1) + coeffs(2)*x + coeffs(3)*x^2 + coeffs(4)*x^3;\nelseif x<=x2\n val = coeffs(5) + coeffs(6)*x + coeffs(7)*x^2 + coeffs(8)*x^3;\nelse\n val = coeffs(9) + coeffs(10)*x + coeffs(11)*x^2 + coeffs(12)*x^3;\nend\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% FUNCTION: evaluate interpolating polynomial 1st derivative\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nfunction val = gP(coeffs,x,x1,x2)\n\nif x<=x1\n val = coeffs(2) + 2*coeffs(3)*x + 3*coeffs(4)*x^2;\nelseif x<=x2\n val = coeffs(6) + 2*coeffs(7)*x + 3*coeffs(8)*x^2;\nelse\n val = coeffs(10) + 2*coeffs(11)*x + 3*coeffs(12)*x^2;\nend\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% FUNCTION: evaluate interpolating polynomial 2nd derivative\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nfunction val = gPP(coeffs,x,x1,x2)\n\nif x<=x1\n val = 2*coeffs(3) + 6*coeffs(4)*x;\nelseif x<=x2\n val = 2*coeffs(7) + 6*coeffs(8)*x;\nelse\n val = 2*coeffs(11) + 6*coeffs(12)*x;\nend\n\n% \n% figure(1)\n% for i=1:length(x1_part)\n% x = x1_part(i);\n% plot(x,a*x^2,'ro'); hold on;\n% end\n% \n% for i=1:length(x2_part)\n% x = x2_part(i);\n% plot(x,c*x^3+d*x^2+g*x+h,'*'); hold on;\n% end\n% \n% for i=1:length(x3_part)\n% x = x3_part(i);\n% plot(x,-b*(x-1)^2+1,'go'); hold on;\n% end\n% \n% xtotal = 0:ds:1;\n% for i=1:length(xtotal)\n% x = xtotal(i);\n% plot(x,0.5*(1+tanh(4.3*(x-0.5))),'m*'); hold on;\n% end\n% title('function vals');\n% \n% \n% figure(2)\n% for i=1:length(x1_part)\n% x = x1_part(i);\n% plot(x,2*a*x,'ro'); hold on;\n% end\n% \n% for i=1:length(x2_part)\n% x = x2_part(i);\n% plot(x,3*c*x^2+2*d*x+g,'*'); hold on;\n% end\n% \n% for i=1:length(x3_part)\n% x = x3_part(i);\n% plot(x,-2*b*(x-1),'go'); hold on;\n% end\n% title('1st deriv');\n% \n% \n% figure(3)\n% for i=1:length(x1_part)\n% x = x1_part(i);\n% plot(x,2*a,'ro'); hold on;\n% end\n% \n% for i=1:length(x2_part)\n% x = x2_part(i);\n% plot(x,6*c*x+2*d,'*'); hold on;\n% end\n% \n% for i=1:length(x3_part)\n% x = x3_part(i);\n% plot(x,-2*b,'go'); hold on;\n% end\n% title('2nd deriv');\n", "meta": {"author": "nickabattista", "repo": "IB2d", "sha": "392d99c228cc801ff65766889c72e2e1492fe747", "save_path": "github-repos/MATLAB/nickabattista-IB2d", "path": "github-repos/MATLAB/nickabattista-IB2d/IB2d-392d99c228cc801ff65766889c72e2e1492fe747/matIB2d/Examples/Example_Jellyfish_Swimming/Tethered_Jellyfish/600x400/interp_Function_Coeffs.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.8633915976709976, "lm_q1q2_score": 0.7988357708667638}}
{"text": "function histmat = hist2D(x, y, xedges, yedges)\n% function histmat = hist2D(x, y, xedges, yedges)\n%\n% Extract 2D histogram data containing the number of events\n% of [x , y] pairs that fall in each bin of the grid defined by \n% xedges and yedges. The edges are vectors with monotonically \n% non-decreasing values. \n%\n%EXAMPLE \n%\n% events = 1000000;\n% x1 = sqrt(0.05)*randn(events,1)-0.5; x2 = sqrt(0.05)*randn(events,1)+0.5;\n% y1 = sqrt(0.05)*randn(events,1)+0.5; y2 = sqrt(0.05)*randn(events,1)-0.5;\n% x= [x1;x2]; y = [y1;y2];\n%\n%For linearly spaced edges:\n% xedges = linspace(-1,1,64); yedges = linspace(-1,1,64);\n% histmat = hist2(x, y, xedges, yedges);\n% figure; pcolor(xedges,yedges,histmat'); colorbar ; axis square tight ;\n%\n%For nonlinearly spaced edges:\n% xedges_ = logspace(0,log10(3),64)-2; yedges_ = linspace(-1,1,64);\n% histmat_ = hist2(x, y, xedges_, yedges_);\n% figure; pcolor(xedges_,yedges_,histmat_'); colorbar ; axis square tight ;\n\n% University of Debrecen, PET Center/Laszlo Balkay 2006\n% email: balkay@pet.dote.hu\n\nif nargin ~= 4\n error ('The four input arguments are required!');\n return;\nend\nif any(size(x) ~= size(y)) \n error ('The size of the two first input vectors should be same!');\n return;\nend\n\n[xn, xbin] = histc(x,xedges);\n[yn, ybin] = histc(y,yedges);\n\n%xbin, ybin zero for out of range values \n% (see the help of histc) force this event to the \n% first bins\nxbin(find(xbin == 0)) = inf;\nybin(find(ybin == 0)) = inf;\n\nxnbin = length(xedges);\nynbin = length(yedges);\n\nif xnbin >= ynbin\n xy = ybin*(xnbin) + xbin;\n indexshift = xnbin; \nelse\n xy = xbin*(ynbin) + ybin;\n indexshift = ynbin; \nend\n\n%[xyuni, m, n] = unique(xy);\nxyuni = unique(xy);\nxyuni(end) = []; \nhstres = histc(xy,xyuni);\nclear xy;\n\nhistmat = zeros(ynbin,xnbin);\nhistmat(xyuni-indexshift) = hstres;\n\n", "meta": {"author": "buzsakilab", "repo": "buzcode", "sha": "2d700a38b3c2a860ad1333be90f14d7a37a72815", "save_path": "github-repos/MATLAB/buzsakilab-buzcode", "path": "github-repos/MATLAB/buzsakilab-buzcode/buzcode-2d700a38b3c2a860ad1333be90f14d7a37a72815/utilities/hist2D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.863391599428538, "lm_q1q2_score": 0.7988357671527053}}
{"text": "\n% Averaging Quaternions\n% Since quaternions are not regular vectors, but rather representations \n% of orientation, an average quaternion cannot just be obtained by taking \n% a weighted mean. This function implements the work done by paper by \n% F. Landis Merkley to calculate the average quaternion. The algorithm \n% explained by F. Landis Markley at: \n% http://www.acsu.buffalo.edu/~johnc/ave_quat07.pdf\n% For this particular implementation, I would also like to reference Mandar\n% Harshe:\n% http://www-sop.inria.fr/members/Mandar.Harshe/knee-joint/html/index.html\n%\n% This algorithm is compared by rotqrmean from VoiceBox and found to \n% produce quite similar results, yet it is more elegant, much simpler to \n% implement and follow. (Though, there might be difference in signs)\n%\n% Usage : \n% Q is an Mx4 matrix, where each row stores a quaternion to be averaged.\n% In return, the function outputs Qavg, which is a single quaternion\n% corresponding to the average.\n%\n% Tolga Birdal\n\nfunction [Qwavg]=weighted_avg_quat(Q, weights)\n\n% Form the symmetric accumulator matrix\nA=zeros(4,4);\nM=size(Q,1);\n\nfor i=1:M\n q=Q(i,:)';\n A=q*q'*weights(i)+A; % rank 1 update\nend\n\n% scale\nA=A/sum(weights);\n\n% Get the eigenvector corresponding to largest eigen value\n[Qwavg, Eval]=eigs(A,1);\n\nend\n", "meta": {"author": "JzHuai0108", "repo": "ekfmonoslam", "sha": "443f6be744732453cdb90679abcaf5c962a6295e", "save_path": "github-repos/MATLAB/JzHuai0108-ekfmonoslam", "path": "github-repos/MATLAB/JzHuai0108-ekfmonoslam/ekfmonoslam-443f6be744732453cdb90679abcaf5c962a6295e/ekfmonoslam/kinematics/weighted_avg_quat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172630429475, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.798822889149316}}
{"text": "function M=axisAng2RotMat(u,theta,handed)\n%%AXISANG2ROTMAT Get a rotation matrix to rotate a 3D vector an angle of\n% theta counterlockwise (right-handed) or clockwise\n% (left-handed) about an axis given by the unit vector u.\n%\n%INPUTS: u A unit vector representing the axis about which a vector should\n% be rotated using the rotation matrix.\n% theta The angle in radians by which a vector is to be rotated is to be\n% rotated about the axis u when multiplied by the rotation matrix.\n% handed The handedness of the rotation angle. If omitted, it is assumed\n% that the rotation is right-handed (the standard). Possible\n% values are\n% 'right' The default if omitted. The rotation is right-handed.\n% 'left' The rotation is left-handed. The rotation angle is\n% counterclockwise when one is looking in the same\n% direction that the rotation axis points.\n%\n%OUTPUTS: M The rotation matrix such that M*v rotates the vector v by the\n% desired rotation.\n%\n%To rotate a 3D vector x an angle of theta about the axis u, simply\n%evaluate M*x.\n%\n%The rotation matrix is obtained by obtaining the unit quaternion for the\n%rotation and turning it into the corresponding rotation matrix as\n%described in [1].\n%\n%REFERENCES:\n%[1] David F. Crouse , \"Basic tracking using nonlinear 3D monostatic and\n% bistatic measurements,\" IEEE Aerospace and Electronic Systems\n% Magazine, vol. 29, no. 8, Part II, pp. 4-53, Aug. 2014.\n%\n%December 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<3||isempty(handed))\n handed='right';\nend\n\nq=axisAng2Quat(u,theta);\nM=quat2RotMat(q,handed);\n\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Coordinate_Systems/Rotations/axisAng2RotMat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328286, "lm_q2_score": 0.8791467690927439, "lm_q1q2_score": 0.7988084884283401}}
{"text": "function [ a, more ] = compnz_next ( n, k, a, more )\n\n%*****************************************************************************80\n%\n%% COMPNZ_NEXT computes the compositions of the integer N into K nonzero parts.\n%\n% Discussion:\n%\n% A composition of the integer N into K nonzero parts is an ordered sequence\n% of K positive integers which sum to N. The compositions (1,2,1)\n% and (1,1,2) are considered to be distinct.\n%\n% The routine computes one composition on each call until there are no more.\n% For instance, one composition of 6 into 3 parts is 3+2+1, another would\n% be 4+1+1 but 5+1+0 is not allowed since it includes a zero part.\n%\n% On the first call to this routine, set MORE = FALSE. The routine\n% will compute the first element in the sequence of compositions, and\n% return it, as well as setting MORE = TRUE. If more compositions\n% are desired, call again, and again. Each time, the routine will\n% return with a new composition.\n%\n% However, when the LAST composition in the sequence is computed\n% and returned, the routine will reset MORE to FALSE, signaling that\n% the end of the sequence has been reached.\n%\n% Example:\n%\n% The 10 compositions of 6 into three nonzero parts are:\n%\n% 4 1 1, 3 2 1, 3 1 2, 2 3 1, 2 2 2, 2 1 3,\n% 1 4 1, 1 3 2, 1 2 3, 1 1 4.\n%\n% Modified:\n%\n% 01 December 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Albert Nijenhuis and Herbert Wilf,\n% Combinatorial Algorithms,\n% Academic Press, 1978, second edition,\n% ISBN 0-12-519260-6.\n%\n% Parameters:\n%\n% Input, integer N, the integer whose compositions are desired.\n%\n% Input, integer K, the number of parts in the composition.\n% K must be no greater than N.\n%\n% Input, integer A(K), the previous composition. On the first call,\n% with MORE = FALSE, set A = []. Thereafter, A should be the \n% value of A output from the previous call.\n%\n% Input, logical MORE. The input value of MORE on the first\n% call should be FALSE, which tells the program to initialize.\n% On subsequent calls, MORE should be TRUE, or simply the\n% output value of MORE from the previous call.\n%\n% Output, integer A(K), the next composition.\n%\n% Output, logical MORE, will be TRUE unless the composition \n% that is being returned is the final one in the sequence.\n%\n persistent h;\n persistent t;\n%\n% We use the trick of computing ordinary compositions of (N-K)\n% into K parts, and adding 1 to each part.\n%\n if ( n < k )\n more = 0;\n a(1:k) = -1;\n return\n end\n\n if ( ~more )\n\n t = n - k;\n h = 0;\n a(1) = n - k;\n a(2:k) = 0;\n\n else\n\n a(1:k) = a(1:k) - 1;\n\n if ( 1 < t )\n h = 0;\n end\n\n h = h + 1;\n t = a(h);\n a(h) = 0;\n a(1) = t - 1;\n a(h+1) = a(h+1) + 1;\n\n end\n\n more = ( a(k) ~= ( n - k ) );\n\n a(1:k) = a(1:k) + 1;\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/cc_display/compnz_next.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.9086178895092415, "lm_q1q2_score": 0.7988084862175283}}
{"text": "function c=cross7(a,b)\n%%CROSS7 Find the cross product of two 7-dimensional vectors. The cross\n% product has the properties:\n% 1) cross7(a,b) is a bilinear function of a and b.\n% 2) cross7(a,b) is perpendicular to both a and b.\n% Thus, dot(cross7(a,b),a)=0 and dot(cross7(a,b),b)=0\n% 3) norm(cross7(a,b))^2=norm(a)^2*norm(b)^2-dot(a,b)^2\n% Just as two forms of the 3D cross product exist (left-handed and\n% right-handed) 480 forms of the 7-dimensional cross product exist.\n% This function implements a cross product defined in terms of an\n% orthonormal basis using asymmetry as in [1].\n%\n%INPUTS: a A 7 by numVecs matrix of numVecs vectors.\n% b A 7 by numVecs matrix of numVecs vectors.\n%\n%OUTPUTS: c The 7 by numVecs cross products of a and b, aXb, for each of\n% the vectors in a and b.\n%\n%As noted in [2], it is only possible for a cross product between two\n%vectors to have all of the properties listed above in three and seven\n%dimensions. \n%\n%As noted in 1, the Jacobi identity does not hold. This means that\n%cross7(cross7(a,b),c)+cross7(cross7(b,c),a)+cross7(cross7(c,a),b) does\n%not necessarily equal zero. However, the following identities can be\n%proven:\n%cross7(a,b)=-cross7(b,a)\n%dot(a,cross7(b,c))=dot(b,cross7(c,a))=dot(c,cross7(a,b))\n%cross7(a,cross7(a,b))=dot(a,b)*a-norm(a)^2*b\n%cross7(cross7(a,b),cross7(a,c))=cross7(cross7(cross7(a,b),c),a)+cross7(cross7(cross7(b,c),a),a)+cross7(cross7(cross7(c,a),a),b)\n%\n%REFERENCES:\n%[1] P. Lounesto, \"Octonians and triality,\" Advances in Clifford Algebras,\n% vol. 11, no. 2, pp. 191-213, Dec. 2001.\n%[2] W. S. Massey, \"Cross products of vectors in higher dimensional\n% Euclidean spaces,\" The American Mathematical Monthly, vol. 90, no. 10,\n% pp. 697-701, Dec. 1983.\n%\n%December 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nnumVecs=size(a,2);\nc=zeros(7,numVecs);\n\nc(1,:)=+0 +a(2,:).*b(4,:) +a(3,:).*b(7,:) -a(4,:).*b(2,:) +a(5,:).*b(6,:) -a(6,:).*b(5,:) -a(7,:).*b(3,:);\nc(2,:)=-a(1,:).*b(4,:) +0 +a(3,:).*b(5,:) +a(4,:).*b(1,:) -a(5,:).*b(3,:) +a(6,:).*b(7,:) -a(7,:).*b(6,:);\nc(3,:)=-a(1,:).*b(7,:) -a(2,:).*b(5,:) +0 +a(4,:).*b(6,:) +a(5,:).*b(2,:) -a(6,:).*b(4,:) +a(7,:).*b(1,:);\nc(4,:)=+a(1,:).*b(2,:) -a(2,:).*b(1,:) -a(3,:).*b(6,:) +0 +a(5,:).*b(7,:) +a(6,:).*b(3,:) -a(7,:).*b(5,:);\nc(5,:)=-a(1,:).*b(6,:) +a(2,:).*b(3,:) -a(3,:).*b(2,:) -a(4,:).*b(7,:) +0 +a(6,:).*b(1,:) +a(7,:).*b(4,:);\nc(6,:)=+a(1,:).*b(5,:) -a(2,:).*b(7,:) +a(3,:).*b(4,:) -a(4,:).*b(3,:) -a(5,:).*b(1,:) +0 +a(7,:).*b(2,:);\nc(7,:)=+a(1,:).*b(3,:) +a(2,:).*b(6,:) -a(3,:).*b(1,:) +a(4,:).*b(5,:) -a(5,:).*b(4,:) -a(6,:).*b(2,:) +0;\n\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Basic_Matrix_Operations/cross7.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768635777511, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7987192772252717}}
{"text": "function [snrdB,ptotdB,psigdB,pnoisedB] = calcSNR(vout,f,fB,w,N)\n% SNR calculation in the time domain (P. Malcovati, S. Brigati)\n% function [snrdB,ptotdB,psigdB,pnoisedB] = calcSNR(vout,f,fB,w,N)\n% vout: Sigma-Delta bit-stream taken at the modulator output\n% f: Normalized signal frequency (fs -> 1)\n% fB:\tBase-band frequency bins\n% w:\twindowing vector\n% N: samples number\n%\n% snrdB: SNR in dB\n% ptotdB: Bit-stream power spectral density (vector)\n% psigdB: Extracted signal power spectral density (vector)\n% pnoisedB: Noise power spectral density (vector)\n%\nfB=ceil(fB);\nsignal=(N/sum(w))*sinusx(vout(1:N).*w,f,N);\t% Extracts sinusoidal signal\nnoise=vout(1:N)-signal;\t\t\t % Extracts noise components\nstot=((abs(fft((vout(1:N).*w)'))).^2);\t\t% Bit-stream PSD\nssignal=(abs(fft((signal(1:N).*w)'))).^2;\t% Signal PSD\nsnoise=(abs(fft((noise(1:N).*w)'))).^2;\t\t% Noise PSD\npwsignal=sum(ssignal(1:fB)); % Signal power\npwnoise=sum(snoise(1:fB));\t\t % Noise power\nsnr=pwsignal/pwnoise;\nsnrdB=dbp(snr);\nnorm=sum(stot)/sum(vout(1:N).^2)*N;\t\t\t\t\t\t\t\t% PSD normalization\nif nargout > 1\n\tptot=stot/norm;\n\tptotdB=dbp(ptot);\nend\n\nif nargout > 2\n\tpsig=ssignal/norm;\n\tpsigdB=dbp(psig);\nend\n\nif nargout > 3\n\tpnoise=snoise/norm;\n\tpnoisedB=dbp(pnoise);\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/15417-successive-approximation-adc/calcSNR.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.853912760387131, "lm_q1q2_score": 0.798704324754136}}
{"text": "% Filter design\n% FIR Filter Design via Spectral Factorization and Convex Optimization\n% EE364 lecture, Filter design and equalization\n%\n% fir_chebychev_design.m - Chebychev design of an FIR filter given a desired H(w)\n% one_over_f_filter.m - Design a 1/f spectrum shaping (pink-noise) filter\n% equalizer_design.m - Equalizer design example\n% iir_mag_design_bandpass_max_atten.m - Maximize stopband attenuation of a bandpass IIR filter\n% fir_lin_phase_lowpass_max_atten.m - Maximize stopband attenuation of a linear phase lowpass FIR filter\n% fir_mag_design_lowpass_max_atten.m - Maximize stopband attenuation of a lowpass FIR filter (magnitude design)\n% iir_mag_design_lowpass_max_atten.m - Maximize stopband attenuation of a lowpass IIR filter\n% fir_lin_phase_lowpass_min_order.m - Minimize order of a linear phase lowpass FIR filter\n% fir_mag_design_lowpass_min_order.m - Minimize order of a lowpass FIR filter (magnitude design)\n% fir_lin_phase_lowpass_min_ripple.m - Minimize stopband ripple of a linear phase lowpass FIR filter\n% fir_lin_phase_lowpass_min_trans.m - Minimize transition bandwidth of a linear phase lowpass FIR filter\n% spectral_fact.m - Spectral factorization using Kolmogorov 1939 approach.\nhelp Contents\n", "meta": {"author": "cvxr", "repo": "CVX", "sha": "a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd", "save_path": "github-repos/MATLAB/cvxr-CVX", "path": "github-repos/MATLAB/cvxr-CVX/CVX-a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd/examples/filter_design/Contents.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465116437761, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7987043147215103}}
{"text": "function varargout = createDodecahedron()\n%CREATEDODECAHEDRON Create a 3D mesh representing a dodecahedron.\n%\n% [V, E, F] = createDodecahedron;\n% Create a 3D mesh representing a dodecahedron\n% V is the 20-by-3 array of vertex coordinates\n% E is the 30-by-2 array of edge vertex indices\n% F is the 12-by-5 array of face vertex indices\n%\n% [V, F] = createDodecahedron;\n% Returns only the vertices and the face vertex indices.\n%\n% MESH = createDodecahedron;\n% Returns the data as a mesh structure, with fields 'vertices', 'edges'\n% and 'faces'.\n%\n% Example\n% [v, e, f] = createDodecahedron;\n% drawMesh(v, f);\n%\n% Use values given by P. Bourke, see:\n% http://local.wasp.uwa.edu.au/~pbourke/geometry/platonic/\n% faces are re-oriented to have normals pointing outwards.\n%\n% See also\n% meshes3d, drawMesh\n% createCube, createOctahedron, createIcosahedron, createTetrahedron\n%\n\n% ---------\n% author : David Legland \n% e-mail: david.legland@inra.fr\n% INRA - TPV URPOI - BIA IMASTE\n% created the 29/07/2010.\n%\n\n% HISTORY\n\n% golden ratio\nphi = (1+sqrt(5))/2;\n\n% coordinates pre-computations\nb = 1 / phi ; \nc = 2 - phi ;\n\n% use values given by P. Bourke, see:\n% http://local.wasp.uwa.edu.au/~pbourke/geometry/platonic/\ntmp = [ ...\n c 0 1 ; b b b ; 0 1 c ; -b b b ; -c 0 1 ; ...\n-c 0 1 ; -b -b b ; 0 -1 c ; b -b b ; c 0 1 ; ...\n c 0 -1 ; b -b -b ; 0 -1 -c ; -b -b -b ; -c 0 -1 ; ...\n-c 0 -1 ; -b b -b ; 0 1 -c ; b b -b ; c 0 -1 ; ...\n 0 1 -c ; 0 1 c ; b b b ; 1 c 0 ; b b -b ; ...\n 0 1 c ; 0 1 -c ; -b b -b ; -1 c 0 ; -b b b ; ...\n 0 -1 -c ; 0 -1 c ; -b -b b ; -1 -c 0 ; -b -b -b ; ...\n 0 -1 c ; 0 -1 -c ; b -b -b ; 1 -c 0 ; b -b b ; ...\n 1 c 0 ; b b b ; c 0 1 ; b -b b ; 1 -c 0 ; ...\n 1 -c 0 ; b -b -b ; c 0 -1 ; b b -b ; 1 c 0 ; ...\n-1 c 0 ; -b b -b ; -c 0 -1 ; -b -b -b ; -1 -c 0 ; ...\n-1 -c 0 ; -b -b b ; -c 0 1 ; -b b b ; -1 c 0 ; ...\n];\n\n% extract coordinates of unique vertices\n[verts, M, N] = unique(tmp, 'rows', 'first'); %#ok\n\n% compute indices of face vertices, put result in a 12-by-5 index array\nind0 = reshape((1:60), [5 12])';\nfaces = N(ind0);\n\n% extract edges from faces\nedges = [reshape(faces(:, 1:5), [60 1]) reshape(faces(:, [2:5 1]), [60 1])];\nedges = unique(sort(edges, 2), 'rows');\n\n\n% format output\nvarargout = formatMeshOutput(nargout, verts, edges, faces);\n", "meta": {"author": "Arrowstar", "repo": "ksptot", "sha": "2b414440d3b167ba2294f56dafce0f465c07f982", "save_path": "github-repos/MATLAB/Arrowstar-ksptot", "path": "github-repos/MATLAB/Arrowstar-ksptot/ksptot-2b414440d3b167ba2294f56dafce0f465c07f982/helper_methods/z_geom3d/meshes3d/createDodecahedron.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.8740772253241802, "lm_q1q2_score": 0.798623842483888}}
{"text": "function [J, grad] = cofiCostFunc(params, Y, R, num_users, num_movies, ...\n num_features, lambda)\n%COFICOSTFUNC Collaborative filtering cost function\n% [J, grad] = COFICOSTFUNC(params, Y, R, num_users, num_movies, ...\n% num_features, lambda) returns the cost and gradient for the\n% collaborative filtering problem.\n%\n\n% Unfold the U and W matrices from params\nX = reshape(params(1:num_movies*num_features), num_movies, num_features);\nTheta = reshape(params(num_movies*num_features+1:end), ...\n num_users, num_features);\n\n \n% You need to return the following values correctly\nJ = 0;\nX_grad = zeros(size(X));\nTheta_grad = zeros(size(Theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost function and gradient for collaborative\n% filtering. Concretely, you should first implement the cost\n% function (without regularization) and make sure it is\n% matches our costs. After that, you should implement the \n% gradient and use the checkCostFunction routine to check\n% that the gradient is correct. Finally, you should implement\n% regularization.\n%\n% Notes: X - num_movies x num_features matrix of movie features\n% Theta - num_users x num_features matrix of user features\n% Y - num_movies x num_users matrix of user ratings of movies\n% R - num_movies x num_users matrix, where R(i, j) = 1 if the \n% i-th movie was rated by the j-th user\n%\n% You should set the following variables correctly:\n%\n% X_grad - num_movies x num_features matrix, containing the \n% partial derivatives w.r.t. to each element of X\n% Theta_grad - num_users x num_features matrix, containing the \n% partial derivatives w.r.t. to each element of Theta\n%\n\n%sum(R .* (((X * Theta') .- Y) .^ 2)) 1*4 matrix\nJ = 1 / 2 * sum(sum(R .* (((X * Theta') .- Y) .^ 2)));\nJ = J + lambda / 2 * sum(sum(X .^ 2)) + lambda / 2 * sum(sum(Theta .^ 2));\n\n% (((X * Theta') .- Y) * Theta)\n\nX_grad = (R .* ((X * Theta') .- Y)) * Theta;\nX_grad = X_grad + lambda .* X;\nTheta_grad = (R .* ((X * Theta') .- Y))' * X;\nTheta_grad = Theta_grad + lambda .* Theta;\n\n\n\n\n\n% =============================================================\n\ngrad = [X_grad(:); Theta_grad(:)];\n\nend\n", "meta": {"author": "scruel", "repo": "Notes-ML-AndrewNg", "sha": "916852d35684dcc77047ed861650aca36b62b98d", "save_path": "github-repos/MATLAB/scruel-Notes-ML-AndrewNg", "path": "github-repos/MATLAB/scruel-Notes-ML-AndrewNg/Notes-ML-AndrewNg-916852d35684dcc77047ed861650aca36b62b98d/assignments/machine-learning-ex8/ex8/cofiCostFunc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.8740772236840656, "lm_q1q2_score": 0.798623838930782}}
{"text": "function [ ns, xyz ] = sphere_cubed_grid_points_face ( n, i1, j1, k1, i2, ...\n j2, k2, ns, xyz )\n\n%*****************************************************************************80\n%\n%% SPHERE_CUBED_GRID_POINTS_FACE: points on a face of a cubed sphere grid.\n%\n% Discussion:\n%\n% This function generates points on a face of a cubed sphere grid, and\n% appneds them to a growing list.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 May 2015\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of sections into which each face of\n% the cube is to be divided.\n%\n% Input, integer I1, J1, K1, I2, J2, K2, the logical indices, between 0 \n% and N, of two corners of the face grid. It is guaranteed that I1 <= I2,\n% J1 <= J2, and K1 <= K2. \n%\n% Input, integer NS, the initial number of points.\n%\n% Input, real XYZ(NS,3), distinct points on the unit sphere\n% generated by a cubed sphere grid.\n%\n% Output, integer NS, the final number of points.\n%\n% Output, real XYZ(NS,3), distinct points on the unit sphere\n% generated by a cubed sphere grid, including the points just genereated.\n%\n for i = i1 : i2\n\n if ( i1 < i2 )\n xc = tan ( ( 2 * i - n ) * 0.25 * pi / n );\n elseif ( i1 == 0 )\n xc = -1.0;\n elseif ( i1 == n )\n xc = +1.0;\n else\n xc = 0.0;\n end\n\n for j = j1 : j2\n\n if ( j1 < j2 )\n yc = tan ( ( 2 * j - n ) * 0.25 * pi / n );\n elseif ( j1 == 0 )\n yc = -1.0;\n elseif ( j1 == n )\n yc = +1.0;\n else\n yc = 0.0;\n end\n\n for k = k1 : k2\n\n if ( k1 < k2 )\n zc = tan ( ( 2 * k - n ) * 0.25 * pi / n );\n elseif ( k1 == 0 )\n zc = -1.0;\n elseif ( k1 == n )\n zc = +1.0;\n else\n zc = 0.0;\n end\n\n xyzn = sqrt ( xc^2 + yc^2 + zc^2 );\n\n ns = ns + 1;\n xyz(ns,1) = xc / xyzn;\n xyz(ns,2) = yc / xyzn;\n xyz(ns,3) = zc / xyzn;\n\n end\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/sphere_cubed_grid/sphere_cubed_grid_points_face.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8705972818382005, "lm_q1q2_score": 0.7986012059947017}}
{"text": "function a = diagonal ( m, n, x )\n\n%*****************************************************************************80\n%\n%% DIAGONAL returns the DIAGONAL matrix.\n%\n% Formula:\n%\n% if ( I = J )\n% A(I,J) = X(I)\n% else\n% A(I,J) = 0\n%\n% Example:\n%\n% M = 5, N = 5, X = ( 1, 2, 3, 4, 5 )\n%\n% 1 0 0 0 0\n% 0 2 0 0 0\n% 0 0 3 0 0\n% 0 0 0 4 0\n% 0 0 0 0 5\n%\n% Square Properties:\n%\n% A is banded, with bandwidth 1.\n%\n% A is nonsingular if, and only if, each X(I) is nonzero.\n%\n% The inverse of A is a diagonal matrix with diagonal values 1/X(I).\n%\n% A is symmetric: A' = A.\n%\n% Because A is symmetric, it is normal.\n%\n% Because A is normal, it is diagonalizable.\n%\n% LAMBDA(1:N) = X(1:N).\n%\n% The matrix of eigenvectors of A is the identity matrix.\n%\n% det ( A ) = product ( 1 <= I <= N ) X(I).\n%\n% Because A is diagonal, it has property A (bipartite).\n%\n% The family of matrices is nested as a function of N.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns of A.\n%\n% Input, real X(min(M,N)), the diagonal entries of A.\n%\n% Output, real A(M,N), the matrix.\n%\n a = zeros ( m, n );\n\n for i = 1 : m\n for j = 1 : n\n\n if ( i == j )\n a(i,j) = x(i);\n else\n a(i,j) = 0.0;\n end\n\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/diagonal.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642019, "lm_q2_score": 0.870597271765821, "lm_q1q2_score": 0.7986011888824383}}
{"text": "function h = p28_h ( n, x )\n\n%*****************************************************************************80\n%\n%% P28_H evaluates the Hessian for problem 28.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 17 January 2001\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of variables.\n%\n% Input, real X(N), the values of the variables.\n%\n% Output, real H(N,N), the N by N Hessian matrix.\n%\n h = zeros ( n, n );\n\n r = sqrt ( x(1)^2 + x(2)^2 );\n\n rx1 = x(1) / r;\n rx2 = x(2) / r;\n\n rx1x1 = x(2)^2 / r^3;\n rx1x2 = - x(1) * x(2) / r^3;\n rx2x1 = - x(1) * x(2) / r^3;\n rx2x2 = x(1)^2 / r^3;\n%\n% F = A * B\n% dFdX1 = ( Ar * B + A * Br ) * Rx1\n% d2FdX1dX1 = ( Arr * B + Ar * Br ) * Rx1^2 + ( Ar * B + A * Br ) * Rx1x1\n% etc\n%\n a = sqrt ( r );\n ar = 0.5 / sqrt ( r );\n arr = - 0.25 / sqrt ( r^3 );\n\n b = 1.0 + ( sin ( 50.0 * r^0.2 ) )^2;\n br = 10.0 * sin ( 100.0 * r^0.2 ) * r^(-0.8);\n brr = 200.0 * cos ( 100.0 * r^0.2 ) * r^(-1.6) ...\n - 10.0 * sin ( 100.0 * r^0.2 ) * 0.8 * r^(-1.8);\n\n h(1,1) = ( arr * b + 2.0 * ar * br + a * brr ) * rx1 * rx1 ...\n + ( ar * b + a * br ) * rx1x1;\n\n h(1,2) = ( arr * b + 2.0 * ar * br + a * brr ) * rx1 * rx2 ...\n + ( ar * b + a * br ) * rx1x2;\n\n h(2,1) = ( arr * b + 2.0 * ar * br + a * brr ) * rx2 * rx1 ...\n + ( ar * b + a * br ) * rx2x1;\n\n h(2,2) = ( arr * b + 2.0 * ar * br + a * brr ) * rx2 * rx2 ...\n + ( ar * b + a * br ) * rx2x2;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_opt/p28_h.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509315, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.798492367124167}}
{"text": "function [v]=tetVolMeanEst(F,V)\n\n% function [v]=tetVolMeanEst(F,V)\n% ------------------------------------------------------------------------\n%\n% This function calculates the volume of an ideal regular tetrahedron with\n% edge lengths (all equal) that match the mean edge lengths occuring for\n% the input surface defined by F (faces) and V (vertices). \n\n%\n% Kevin Mattheus Moerman\n% gibbon.toolbox@gmail.com\n% \n% 2014/10/17\n%------------------------------------------------------------------------\n%%\n\n[edgeLengths]=patchEdgeLengths(F,V);\nedgeLengthsMean=mean(edgeLengths);\nmeanProposedVolume=edgeLengthsMean^3./(6*sqrt(2)); %For a regular tetrahedron\nv=meanProposedVolume;\n \n%% \n% _*GIBBON footer text*_ \n% \n% License: \n% \n% GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for\n% image segmentation, image-based modeling, meshing, and finite element\n% analysis.\n% \n% Copyright (C) 2006-2022 Kevin Mattheus Moerman and the GIBBON contributors\n% \n% This program is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n% \n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n% \n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see .\n", "meta": {"author": "gibbonCode", "repo": "GIBBON", "sha": "8178520664a6148db939eaea87e75b3cba4f2b4f", "save_path": "github-repos/MATLAB/gibbonCode-GIBBON", "path": "github-repos/MATLAB/gibbonCode-GIBBON/GIBBON-8178520664a6148db939eaea87e75b3cba4f2b4f/lib/tetVolMeanEst.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750360641185, "lm_q2_score": 0.8376199653600371, "lm_q1q2_score": 0.7984822026866151}}
{"text": "function hEllipse = ellipsedraw(hand,a,b,x0,y0,phi,lineStyle)\n%ELLIPSEDRAW can draw an arbitrary ellipse with given parameters.\n% The properties of that ellipse plot can be customized \n% by setting the ellipse handle. \n%\n% hEllipse = ellipsedraw(hand,a,b,x0,y0,phi,lineStyle)\n%\n% Input parameters:\n% hand Parent handle for ellipse\n% a Value of the major axis\n% b Value of the minor axis\n% x0 Abscissa of the center point of the ellipse\n% y0 Ordinate of the center point of the ellipse\n% phi Angle between x-axis and the major axis\n% lineStyle Definition of the plotted line style\n%\n% Output:\n% hEllipse Handle of the ellipse\n%\n% Simple usage:\n% ellipsedraw(5,3);\n% ellipsedraw(5,3,'g--');\n% ellipsedraw(5,3,pi/4);\n%\n% Complete usage:\n% h = ellipsedraw(5,3,1,-2,pi/4,'r-.');\n% set(h,'LineWidth',2);\n\n% Designed by: Lei Wang, , 25-Mar-2003.\n% Last Revision: 01-Apr-2003.\n% Dept. Mechanical & Aerospace Engineering, NC State University.\n% Copyright (c)2003, Lei Wang \n%$Revision: 1.0 $ $ 4/1/2003 5:42:24 PM $\n\nif (nargin < 3)||(nargin > 7),\n error('Too few or too many arguments.');\n \nelseif nargin == 3\n x0 = 0; y0 = 0;\n phi = 0; lineStyle = 'b-';\n \nelseif nargin == 4\n if ischar(x0) == 1\n lineStyle = x0; \n x0 = 0; y0 = 0;\n phi = 0; \n else\n phi = x0; \n x0 = 0; y0 = 0;\n lineStyle = 'b-';\n end\n \nelseif nargin == 5 \n phi = 0; lineStyle = 'b-';\n \nelseif nargin == 6\n lineStyle = 'b-';\nend\n\n\n\ntheta = [-0.03:0.01:2*pi];\n\n% Parametric equation of the ellipse\n%----------------------------------------\n x = a*cos(theta);\n y = b*sin(theta);\n\n\n\n% Coordinate transform \n%----------------------------------------\n X = cos(phi)*x - sin(phi)*y;\n Y = sin(phi)*x + cos(phi)*y;\n X = X + x0;\n Y = Y + y0;\n\n\n% Plot the ellipse\n%----------------------------------------\n hEllipse = plot(hand,X,Y,lineStyle);\n \n \n %axis equal;", "meta": {"author": "jramshur", "repo": "HRVAS", "sha": "ffe2465a0b8f8bf21bc78db474e5da4890761a44", "save_path": "github-repos/MATLAB/jramshur-HRVAS", "path": "github-repos/MATLAB/jramshur-HRVAS/HRVAS-ffe2465a0b8f8bf21bc78db474e5da4890761a44/ellipsedraw.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.920789673717312, "lm_q2_score": 0.8670357649558007, "lm_q1q2_score": 0.7983575791148918}}
{"text": "function a = gk323 ( m, n )\n\n%*****************************************************************************80\n%\n%% GK323 returns the GK323 matrix.\n%\n% Discussion:\n%\n% This matrix is occasionally known as the \"Todd\" matrix.\n%\n% Formula:\n%\n% A(I,J) = abs ( I - J )\n%\n% Example:\n%\n% N = 5\n%\n% 0 1 2 3 4\n% 1 0 1 2 3\n% 2 1 0 1 2\n% 3 2 1 0 1\n% 4 3 2 1 0\n%\n% Rectangular Properties:\n%\n% A is integral: int ( A ) = A.\n%\n% A is a special case of the Fiedler matrix.\n%\n% Square Properties:\n%\n% A is symmetric: A' = A.\n%\n% Because A is symmetric, it is normal.\n%\n% Because A is normal, it is diagonalizable.\n%\n% det ( A ) = (-1)^(N-1) * 2^(N-2) * ( N - 1 ).\n%\n% A has a dominant positive eigenvalue, and N-1 real negative eigenvalues.\n%\n% If N = 2 mod 4, then -1 is an eigenvalue, with an eigenvector\n% of the form ( 1, -1, -1, 1, 1, -1, -1, 1, ... ).\n%\n% The family of matrices is nested as a function of N.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 09 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Robert Gregory, David Karney,\n% Example 3.23,\n% A Collection of Matrices for Testing Computational Algorithms,\n% Wiley, New York, 1969, page 51, \n% LC: QA263.G68.\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns \n% of the matrix.\n%\n% Output, real A(M,N), the matrix.\n%\n a = zeros ( m, n );\n\n for i = 1 : m\n for j = 1 : n\n a(i,j) = abs ( i - j );\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/gk323.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715774, "lm_q2_score": 0.8824278772763472, "lm_q1q2_score": 0.7982888536344362}}
{"text": "%function chol_comparison\n% Test what is the best way to evaluate Cholesky(-like) decomposition.\n\nn = 1000;\n\n% Large and ill-conditioned covariance matrix\nC = gpcov(log(100), 1:n, 1:n);\n\n% Regular Cholesky with diagonal addition\ntic\nLchol = chol(C + 100*eps*eye(n), 'lower');\nLchol(1:10, 1:10)\ntoc\n\n% LDL with negative values to zero\ntic\n[Lldl, Dldl] = ldl(C);\n%Dldl(Dldl<0) = 0;\n%Lldl = Lldl * sqrt(Dldl);\nd = diag(Dldl);\nd(d<0) = 0;\nLldl(1:10,1:10)\nLldl = bsxfun(@times, Lldl, sqrt(d(:))');\ntoc\n\n% My LDL with negative values to zero\ntic\n[Lmyldl, Dmyldl] = ldl(C);\n%Dldl(Dldl<0) = 0;\n%Lldl = Lldl * sqrt(Dldl);\nd = diag(Dmyldl);\nd(d<0) = 0;\nLmyldl(1:10,1:10)\nLmyldl = bsxfun(@times, Lmyldl, sqrt(d(:))');\ntoc\n%return\n\n% Matlab's cholcov based on eigenvalue decomposition\n% Note that this solution does not, in general, give triangular matrix!!!\n% Also, this is very slow!\ntic\nLcholcov = cholcov(C)';\nLcholcov = [Lcholcov, zeros(n, n-cols(Lcholcov))];\ntoc\n\n\n% Errors:\nerror_chol = norm(C - Lchol*Lchol')\nerror_ldl = norm(C - Lldl*Lldl')\nerror_myldl = norm(C - Lmyldl*Lmyldl')\n%error_ldl = norm(C - Lldl*Dldl*Lldl')\nerror_cholcov = norm(C - Lcholcov*Lcholcov')\n\n% What other measures could be used?\n% How accurate these methods are in solving linear equations?\n\nx = randn(n,1);\ny = C * x;\n\nopts.LT = true;\nopts.TRANSA = false;\nx_chol = linsolve(Lchol, y, opts);\nopts.TRANSA = true;\nx_chol = linsolve(Lchol, x_chol, opts);\n\nopts.LT = true;\nopts.TRANSA = false;\nx_ldl = linsolve(Lldl, y, opts);\nopts.TRANSA = true;\nx_ldl = linsolve(Lldl, x_ldl, opts);\n\nopts.LT = true;\nopts.TRANSA = false;\nx_myldl = linsolve(Lmyldl, y, opts);\nopts.TRANSA = true;\nx_myldl = linsolve(Lmyldl, x_myldl, opts);\n\nopts.LT = false;\nopts.TRANSA = false;\nx_cholcov = linsolve(Lcholcov, y, opts);\nopts.TRANSA = true;\nx_cholcov = linsolve(Lcholcov, x_cholcov, opts);\n\nerror_chol = norm(x - x_chol)\nerror_ldl = norm(x - x_ldl)\nerror_myldl = norm(x - x_myldl)\nerror_cholcov = norm(x - x_cholcov)\n", "meta": {"author": "jluttine", "repo": "matlab", "sha": "63406c7782b0869948f06e1dbc594460c165d24e", "save_path": "github-repos/MATLAB/jluttine-matlab", "path": "github-repos/MATLAB/jluttine-matlab/matlab-63406c7782b0869948f06e1dbc594460c165d24e/gppca/chol_comparison.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191335436404, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.7981534028856445}}
{"text": "function z = cumint3(x,y)\n%\n% z = cumint3(x,y)\n%\n% This returns a vector z the same size as x and y\n% which is the cumulative integral of y with respect\n% to x, with the lower integration limit set to x(1) and\n% the upper limit ranging from x(1) to x(n). The\n% successive intervals in x need not be of equal lengths, \n% though none should be of zero length. A third order\n% approximation is made so that for up to cubic polynomials\n% the values will be exact except for rounding. \n% x and y must be column vectors of the same length\n% and have at least four elements. Note that with only \n% z = b.*g below, this would be computing matlab's\n% 'cumtrapz' trapezoidal integration, the rest of the\n% expression in z serving to carry out the additional\n% third order approximation. RAS - 03/11/08\n\n% Test arguments\n[n,m] = size(x);\nif any([n,m]~=size(y)) | m~=1\n error('x and y must be column vectors of equal length.')\nend\nif n<4\n error('There must be at least four points.')\nend\n\n% Compute third order integral\nxe = [x(4);x;x(n-3)]; ye = [y(4);y;y(n-3)]; % Provide for endpoints\nx0 = xe(1:n-1); x1 = xe(2:n); x2 = xe(3:n+1); x3 = xe(4:n+2);\ny0 = ye(1:n-1); y1 = ye(2:n); y2 = ye(3:n+1); y3 = ye(4:n+2);\na = x1-x0; b = x2-x1; c = x3-x2;\nd = y1-y0; e = y2-y1; f = y3-y2;\ng = (y1+y2)/2;\n\n% Each z value will be the integral from x1 to x2 of a cubic\n% polynomial running through (x0,y0),(x1,y1),(x2,y2),(x3,y3).\nz = b.*g+1/12*b.^2.*(+c.*b.*(2*c+b).*(c+b).*d ...\n -a.*c.*(c-a).*(2*c+2*a+3*b).*e-a.*b.*(2*a+b).*(a+b).*f) ...\n ./(a.*c.*(a+b).*(c+b).*(c+a+b));\n\t\n% Obtain cumulative integral values\nz = [0;cumsum(z)];\n\nreturn\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/19152-cumulative-cubic-integration/cumint3.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.7981440294918475}}
{"text": "% Synthesis of a stationary time signal given sinusoids parameters\n%\n% Octave compatible\n% \n% Inputs\n% sins : matrix of size(3,N) [freq;amp;phase]\n% fs : [Hz] Sampling frequency\n% winlen : length of the time signal to synthesize\n% derive : if deriv=1, synthesize the derivative of the signal\n%\n% Outputs\n% s : The synthesized signal\n%\n% Copyright (c) 2012 University of Crete - Computer Science Department\n% \n% License\n% This file is under the LGPL license, you can\n% redistribute it and/or modify it under the terms of the GNU Lesser General \n% Public License as published by the Free Software Foundation, either version 3 \n% of the License, or (at your option) any later version. This file is\n% distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; \n% without even the implied warranty of MERCHANTABILITY or FITNESS FOR A \n% PARTICULAR PURPOSE. See the GNU Lesser General Public License for more\n% details.\n%\n% This function is part of the Covarep project: http://covarep.github.io/covarep\n%\n% Author\n% Gilles Degottex \n%\n\nfunction [s t] = sin2sig(sins, fs, winlen, deriv)\n if nargin<4; deriv=0; end\n\n% t = (0:winlen-1)/fs;\n% t = (0:winlen-1)/fs;\n % The time reference used for the phase in sins is in the window center\n t = (-(winlen-1)/2:(winlen-1)/2)/fs;\n\n if deriv==0\n A = cos(2*pi*t'*sins(1,:) + ones(length(t),1)*sins(3,:));\n A = ones(length(t),1)*sins(2,:).*A;\n s = sum(A,2);\n elseif deriv==1\n A = -sin(2*pi*t'*sins(1,:) + ones(length(t),1)*sins(3,:));\n A = ones(length(t),1)*(sins(2,:).*(2*pi*partials(1,:))).*A;\n s = sum(A,2);\n end\n\nreturn\n", "meta": {"author": "covarep", "repo": "covarep", "sha": "5a2be5d6b776f14a0b275c69fde90eb13849e60d", "save_path": "github-repos/MATLAB/covarep-covarep", "path": "github-repos/MATLAB/covarep-covarep/covarep-5a2be5d6b776f14a0b275c69fde90eb13849e60d/sinusoidal/sin2sig.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248242542284, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7981440284900129}}
{"text": "function varargout = zettl(X)\n% Zettl function\n%\n% ZETTL([x1, x2]) returns the value of the Zettle function at the\n% specified points. [x1] and [x2] may be vectors. The search domain \n% is \n%\n% -5 < x_i < 5\n%\n% The global minimum is \n%\n% f(x1, x2) = f(-0.0299, 0) = -0.003791\n\n% Author: Rody P.S. Oldenhuis\n% Delft University of Technology\n% E-mail: oldenhuis@dds.nl\n% Last edited 20/Jul/2009\n\n % if no input is given, return dimensions, bounds and minimum\n if (nargin == 0)\n varargout{1} = 2; % # dims\n varargout{2} = [-5, -5]; % LB\n varargout{3} = [+5, +5]; % UB\n varargout{4} = [-2.989597760285287e-002, 0]; % solution\n varargout{5} = -3.791237220468656e-003; % function value at solution\n \n % otherwise, output function value\n else\n % keep all values in the search domain\n X(X < -5) = inf; X(X > 5) = inf;\n \n % split input vector X into x1, x2\n if size(X, 1) == 2\n x1 = X(1, :); x2 = X(2, :);\n else\n x1 = X(:, 1); x2 = X(:, 2);\n end\n \n % output function value\n varargout{1} = (x1.^2 + x2.^2 - 2*x1).^2 + x1/4;\n end\n \nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/23147-many-testfunctions-for-global-optimizers/single-objective/zettl.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222395, "lm_q2_score": 0.8499711775577735, "lm_q1q2_score": 0.7981440283754032}}
{"text": "function [varargout]=ellipsefit(x,y)\n%ELLIPSEFIT Stable Direct Least Squares Ellipse Fit to Data.\n% [Xc,Yc,A,B,Phi,P]=ELLIPSEFIT(X,Y) finds the least squares ellipse that\n% best fits the data in X and Y. X and Y must have at least 5 data points.\n% Xc and Yc are the x- and y-axis center of the ellipse respectively.\n% A and B are the major and minor axis of the ellipse respectively.\n% Phi is the radian angle of the major axis with respect to the x-axis.\n% P is a vector containing the general conic parameters of the ellipse.\n% The conic representation of the ellipse is given by:\n%\n% P(1)*x^2 + P(2)*x*y + P(3)*y^2 + P(4)*x + P(5)*y + P(6) = 0\n%\n% S=ELLIPSEFIT(X,Y) returns the output data in a structure with field names\n% equal to the variable names given above, e.g., S.Xc, S.Yc, S.A, S.B,\n% S.Phi and S.P\n%\n% Reference: R. Halif and J. Flusser, \"Numerically Stable Direct Least\n% Squares FItting of Ellipses,\" Department of Software Engineering, Charles\n% University, Czech Republic, 2000.\n\n% Conversion from conic to conventional ellipse equation inspired by\n% fit_ellipse.m on MATLAB Central\n\n% D.C. Hanselman, University of Maine, Orono, ME 04469\n% Mastering MATLAB 7\n% 2005-02-28\n% Rotation angle fixed 2005-08-09\n\n%--------------------------------------------------------------------------\nx=x(:); % convert data to column vectors\ny=y(:);\nif numel(x)~=numel(y) || numel(x)<5\n error('X and Y Must be the Same Length and Contain at Least 5 Values.')\nend\n\nD1=[x.*x x.*y y.*y]; % quadratic terms\nD2=[x y ones(size(x))]; % linear terms\nS1=D1'*D1;\nS2=D1'*D2;\n\n[Q2,R2]=qr(D2,0);\nif condest(R2)>1.0e10\n warning('ellipsefit',...\n 'Data is Poorly Conditioned and May Not Represent an Ellipse.')\nend\nT=-R2\\(R2'\\S2'); % -inv(S3) * S2'\n\nM=S1+S2*T;\nCinvM=[M(3,:)/2; -M(2,:); M(1,:)/2];\n[V,na]=eig(CinvM);\nc=4*V(1,:).*V(3,:) - V(2,:).^2;\nA1=V(:,c>0);\nP=[A1; T*A1];\n\n% correct signs if needed\nif ~isempty(P),\n P=sign(P(1))*P;\n \n Phi=atan(P(2)/(P(3)-P(1)))/2;\n c=cos(Phi);\n s=sin(Phi);\n \n % rotate the ellipse parallel to x-axis\n Pr=zeros(6,1);\n Pr(1)=P(1)*c*c - P(2)*c*s + P(3)*s*s;\n Pr(2)=2*(P(1)-P(3))*c*s + (c^2-s^2)*P(2);\n Pr(3)=P(1)*s*s + P(2)*s*c + P(3)*c*c;\n Pr(4)=P(4)*c - P(5)*s;\n Pr(5)=P(4)*s + P(5)*c;\n Pr(6)=P(6);\n \n % extract other data\n XcYc=[c s;-s c]*[-Pr(4)/(2*Pr(1));-Pr(5)/(2*Pr(3))];\n Xc=XcYc(1);\n Yc=XcYc(2);\n F=-Pr(6) + Pr(4)^2/(4*Pr(1)) + Pr(5)^2/(4*Pr(3));\n AB=sqrt(F./Pr(1:2:3));\n A=AB(1);\n B=AB(2);\n Phi=-Phi;\n if A.\n%\n% Reference:\n%\n% Guowei Cai et al. Unmanned Rotorcraft Systems. Springer. 2011. \n% Eq. 2.22, p. 31.\n%\n% Version: 001\n% Date: 2019/01/16\n% Author: Rodrigo Gonzalez \n% URL: https://github.com/rodralez/navego\n\n% Preallocate\n\necef = zeros(size(llh));\n\nlat = llh(:,1);\nlon = llh(:,2);\nh = llh(:,3);\n\n[~,RN] = radius(lat);\n\ne = 0.0818191908426; % Eccentricity \n\nslat = sin(lat);\nclat = cos(lat);\nclon = cos(lon);\nslon = sin(lon);\n\necef(:,1) = (RN + h) .* clat .* clon;\necef(:,2) = (RN + h) .* clat .* slon;\necef(:,3) = (RN *(1-e^2) + h) .* slat;\n\nend\n", "meta": {"author": "rodralez", "repo": "NaveGo", "sha": "3de9a74ab1597be13255d4649892e68aeff9a8b7", "save_path": "github-repos/MATLAB/rodralez-NaveGo", "path": "github-repos/MATLAB/rodralez-NaveGo/NaveGo-3de9a74ab1597be13255d4649892e68aeff9a8b7/conversions/llh2ecef.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582535657921, "lm_q2_score": 0.8577681049901036, "lm_q1q2_score": 0.7981174129335308}}
{"text": " function [alphas, beta] = nufft_alpha_kb_fit(N, J, K, L, beta, chat)\n%\n% return the alpha and beta corresponding to LS fit of L components\n% to optimized Kaiser-Bessel scaling factors (m=0, alpha=2.34J).\n% This is the best method I know currently for choosing alpha!\n%\n% Copyright 2002-7-16, Jeff Fessler, The University of Michigan\n\nif nargin < 3, help(mfilename), error(mfilename), end\nif ~isvar('L') | isempty(L)\n\tif N > 40\n\t\tL = 13;\t\t% empirically found to be reasonable\n\telse\n\t\tL = ceil(N/3);\t% a kludge to avoid \"rank deficient\" complaints\n\tend\nend\nif ~isvar('beta') | isempty(beta),\tbeta = 1; end\nif ~isvar('chat') | isempty(chat),\tchat = 0; end\n\nkb_alf = 2.34 * J;\t% KB shape parameter\nkb_m = 0;\t\t% KB order\n\n[tmp, sn_kaiser] = nufft1_error(0, N, J, K, 'kaiser', 'ft');\nsn_kaiser = reale(sn_kaiser);\n\n%\n% use regression to match NUFFT with BEST kaiser scaling's\n%\ngam = 2*pi/K;\nnlist = [0:(N-1)]' - (N-1)/2;\nX = cos(beta*gam*nlist*[0:L]);\t% [N,L]\ncoef = (X \\ sn_kaiser)';\t% regress(sn_kaiser, X)';\nalphas = [reale(coef(1)) coef(2:end)/2];\n\nif chat\n\tprintf('cond # for LS fit to KB scale factors: %g', cond(X))\nend\n", "meta": {"author": "thomaskuestner", "repo": "CS_MoCo_LAB", "sha": "a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b", "save_path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB", "path": "github-repos/MATLAB/thomaskuestner-CS_MoCo_LAB/CS_MoCo_LAB-a26e8e483624b2e4ee669e7a069ba9c74d2d2e4b/reconstruction/matlab/CS_LAB_matlab/@NUFFT/private/nufft_alpha_kb_fit.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582477806522, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.7981174096627688}}
{"text": "function [bcUx, bcUy, bcPR, bcdUndt] = KovasznayBC2D(x, y, nx, ny, mapI, mapO, mapW, mapC, time, nu)\n\n% function [bcUx, bcUy, bcPR, bcdUndt] = KovasznayBC2D(x, y, nx, ny, mapI, mapO, mapW, mapC, time, nu)\n% Purpose: evaluate boundary conditions for Kovasznay flow \n\nzer = zeros(size(x)); bcUx = zer; bcUy = zer; bcPR = zer; bcdUndt = zer;\n\nlam = (0.5/nu) - sqrt( (0.25/(nu^2)) + 4*pi^2 );\n\n% inflow\nxI = x(mapI); yI = y(mapI);\nbcUx(mapI)= 1-exp(lam*xI).*cos(2*pi*yI);\nbcUy(mapI)= (0.5*lam/pi)*exp(lam*xI).*sin(2*pi*yI);\n\n% outflow\nxO = x(mapO); yO = y(mapO);\n\nif(0)\n bcPR(mapO) = .5*(1-exp(2*lam*xO));\n bcUx(mapO)= 1-exp(lam*xO).*cos(2*pi*yO);\n bcUy(mapO)= (0.5*lam/pi)*exp(lam*xO).*sin(2*pi*yO);\nelse\n bcPR(mapO) = .5*(1-exp(2*lam*xO));\n\n % Neumann data for each velocity\n bcUx(mapO) = -lam*exp(lam*xO).*cos(2*pi*yO);\n bcUy(mapO) = lam*(0.5*lam/pi)*exp(lam*xO).*sin(2*pi*yO);\nend\nreturn\n\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/JSHesthaven&TWarburton/CFD2D/KovasznayBC2D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.950410982634296, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.798092391084662}}
{"text": "function dist=KLDiv(P,Q)\n% dist = KLDiv(P,Q) Kullback-Leibler divergence of two discrete probability\n% distributions\n% P and Q are automatically normalised to have the sum of one on rows\n% have the length of one at each \n% P = n x nbins\n% Q = 1 x nbins or n x nbins(one to one)\n% dist = n x 1\n\n\n\nif size(P,2)~=size(Q,2)\n error('the number of columns in P and Q should be the same');\nend\n\nif sum(~isfinite(P(:))) + sum(~isfinite(Q(:)))\n error('the inputs contain non-finite values!') \nend\n\n% normalizing the P and Q\nif size(Q,1)==1\n Q = Q ./sum(Q);\n P = P ./repmat(sum(P,2),[1 size(P,2)]);\n dist = sum(P.*log(P./repmat(Q,[size(P,1) 1])),2);\n \nelseif size(Q,1)==size(P,1)\n \n Q = Q ./repmat(sum(Q,2),[1 size(Q,2)]);\n P = P ./repmat(sum(P,2),[1 size(P,2)]);\n dist = sum(P.*log(P./Q),2);\nend\n\n% resolving the case when P(i)==0\ndist(isnan(dist))=0;\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/20689-jensen-shannon-divergence/home/nrazavi/Desktop/KLDiv.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.798046062126425}}
{"text": "% MORLET_2D_NODC computes the 2-D elliptic Morlet filter given a set of \n% parameters in Fourier domain\n%\n% Usage\n% gab = MORLET_2D_NODC(N, M, sigma, slant, xi, theta, offset)\n%\n% Input\n% N (numeric): Width of the filter.\n% M (numeric): Height of the filter.\n% sigma (numeric): Standard deviation of the envelope.\n% slant (numeric): Eccentricity of the elliptic envelope.\n% (the smaller slant, the larger angular resolution).\n% xi (numeric): The frequency peak.\n% theta (numeric): Orientation in radians of the filter.\n% offset (numeric, optional): 2-D vector reprensting the offset location \n% (default [0 0]).\n% \n% Output\n% gab (numeric): N-by-M matrix representing the gabor filter in spatial\n% domain.\n%\n% Description\n% Compute a Morlet wavelet in Fourier domain. \n%\n% Morlet wavelets have a 0 DC component.\n%\n% See also\n% GABOR_2D, MORLET_2D_PYRAMID\n\nfunction gab = morlet_2d_noDC(N, M, sigma, slant, xi, theta, offset)\n\t\n\tif ~exist('offset','var')\n\t\toffset = [0, 0];\n\tend\n\t[x , y] = meshgrid(1:M, 1:N);\n\t\n\tx = x - ceil(M/2) - 1 - offset(1);\n\ty = y - ceil(N/2) - 1 - offset(2);\n\t\n\tRth = rotation_matrix_2d(theta);\n\tA = Rth\\ [1/sigma^2, 0 ; 0 slant^2/sigma^2] * Rth ;\n\ts = x.* ( A(1,1)*x + A(1,2)*y) + y.*(A(2,1)*x + A(2,2)*y ) ;\n\t\n\t%normalize sucht that the maximum of fourier modulus is 1\n\t\n\tgaussian_envelope = exp( - s/2);\n\toscilating_part = gaussian_envelope .* exp(1i*(x*xi*cos(theta) + y*xi*sin(theta)));\n\tK = sum(oscilating_part(:)) ./ sum(gaussian_envelope(:));\n\tgabc = oscilating_part - K.*gaussian_envelope;\n\t\n\tgab=1/(2*pi*sigma^2/slant^2)*fftshift(gabc);\n\t\nend\n", "meta": {"author": "scatnet", "repo": "scatnet", "sha": "59d935afa20359845282a3518134e24244862c1f", "save_path": "github-repos/MATLAB/scatnet-scatnet", "path": "github-repos/MATLAB/scatnet-scatnet/scatnet-59d935afa20359845282a3518134e24244862c1f/filters/morlet_2d_noDC.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7980460503880874}}
{"text": "function [La,dLa,lambda0] = lagrange(U,s,b,more)\n%LAGRANGE Plot the Lagrange function for Tikhonov regularization.\n%\n% [La,dLa,lambda0] = lagrange(U,s,b,more)\n% [La,dLa,lambda0] = lagrange(U,sm,b,more) , sm = [sigma,mu]\n%\n% Plots the Lagrange function\n% La(lambda) = || A x - b ||^2 + lambda^2*|| L x ||^2\n% and its first derivative dLa = dLa/dlambda versus lambda.\n% Here, x is the Tikhonov regularized solution.\n%\n% If nargin = 4, || A x - b || and || L x || are also plotted.\n%\n% Returns La, dLa, and the value lambda0 of lambda for which\n% dLa has its minimum.\n\n% Per Christian Hansen, IMM, Feb. 21, 2001.\n\n% Set default number of points.\nnpoints = 200;\n\n% Initialization.\n[m,n] = size(U); [p,ps] = size(s);\nbeta = U'*b; beta2 = norm(b)^2 - norm(beta)^2;\nif (ps==2)\n s = s(p:-1:1,1)./s(p:-1:1,2); beta = beta(p:-1:1);\nend\nxi = beta(1:p)./s;\n\n% Compute the L-curve.\neta = zeros(npoints,1); rho = eta;\nlambda(npoints,1) = s(p);\nratio = (s(1)/s(p))^(1/(npoints-1));\nfor i=npoints-1:-1:1, lambda(i) = ratio*lambda(i+1); end\nfor i=1:npoints\n f = fil_fac(s,lambda(i));\n eta(i) = norm(f.*xi);\n rho(i) = norm((1-f).*beta(1:p));\nend\nif (m > n && beta2 > 0), rho = sqrt(rho.^2 + beta2); end\n\n% Compute the Lagrange function and its derivative.\nLa = rho.^2 + (lambda.^2).*(eta.^2);\ndLa = 2*lambda.*(eta.^2);\n[mindLa,mindLi] = min(dLa); lambda0 = lambda(mindLi);\n\n% Plot the functions.\nif (nargin==3)\n loglog(lambda,La,'-',lambda,dLa,'--',lambda0,mindLa,'o')\n legend('La','dLa/d\\lambda')\nelse\n loglog(lambda,La,'-',lambda,dLa,'--',lambda,eta,':',lambda,rho,'-.',...\n lambda0,mindLa,'o')\n legend('La','dLa/d\\lambda','|| L x ||_2','|| A x - b ||_2')\nend\nxlabel('\\lambda')\ntitle('Lagrange function La and its derivative')", "meta": {"author": "goodshawn12", "repo": "REST", "sha": "e34ce521fcb36e7813357a9720072dd111edf797", "save_path": "github-repos/MATLAB/goodshawn12-REST", "path": "github-repos/MATLAB/goodshawn12-REST/REST-e34ce521fcb36e7813357a9720072dd111edf797/dependencies/BCILAB/dependencies/SIFT-private/external/regu/regu/lagrange.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.8558511524823262, "lm_q1q2_score": 0.7980412358111157}}
{"text": "function probVal=trivarNormCDF(b,mu,R)\n%%TRIVARNORMCDF Evaluate the cumulative density function of the trivariate\n% normal distribution with a specified mean and covariance\n% matrix. This evaluates Pr{x1r % need to find additional vectors\n g=chol(w);\n v=g\\null(c'*g');\n [p,l,q]=svd(v'*b*v);\n a(:,r+1:n)=v*p(:,1:n-r);\n a(:,1:r)=c;\n else\n a=c; % no new vectors to find\n end\n if nargout>1\n ari=a/triu(qr(chol(a'*w*a))); % matrix a must be of full rank\n f=diag(ari'*b*ari);\n end\nelse\n [g,d]=eig(b,w,'qz');\n [ds,is]=sort(-diag(d));\n a=g(:,is(1:n));\n if nargout>1\n f=-ds(1:n);\n end\nend\nif nargout > 2\n B=a'*b*a;\n if nargout > 3\n W=a'*w*a;\n end\n \nend\n", "meta": {"author": "ImperialCollegeLondon", "repo": "sap-voicebox", "sha": "28f2654b7584f724277ec81de533debe28ff51ac", "save_path": "github-repos/MATLAB/ImperialCollegeLondon-sap-voicebox", "path": "github-repos/MATLAB/ImperialCollegeLondon-sap-voicebox/sap-voicebox-28f2654b7584f724277ec81de533debe28ff51ac/voicebox/v_ldatrace.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951661947455, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7978919452363069}}
{"text": "function varargout = carromtable(X)\n% Carrom table function\n%\n% CARROMTABLE([x1, x2]) returns the value of the Carrom table\n% function at the specified points. [x1] and [x2] may be vectors. \n% The search domain is\n%\n% -10 < x_i < 10\n%\n% The four global minimum are found near the corners of the interval,\n% with\n%\n% fmin = 24.1568155.\n\n% Author: Rody P.S. Oldenhuis\n% Delft University of Technology\n% E-mail: oldenhuis@dds.nl\n% Last edited 20/Jul/2009\n\n % if no input is given, return dimensions, bounds and minimum\n if (nargin == 0)\n varargout{1} = 2; % # dims\n varargout{2} = [-10, -10]; % LB\n varargout{3} = [+10, +10]; % UB\n varargout{4} = [+9.646157266348881e+000, +9.646134286497169e+000\n -9.646157266348881e+000, +9.646134286497169e+000\n +9.646157266348881e+000, -9.646134286497169e+000\n -9.646157266348881e+000, -9.646134286497169e+000]; % solution\n varargout{5} = -2.415681551650653e+001; % function value at solution\n\n % otherwise, output function value\n else\n \n % keep values in the serach interval\n X(X < -10) = inf; X(X > 10) = inf;\n \n % split input vector X into x1, x2\n if size(X, 1) == 2\n x1 = X(1, :); x2 = X(2, :);\n else\n x1 = X(:, 1); x2 = X(:, 2);\n end\n \n % output function value\n varargout{1} = -((cos(x1).*cos(x2).*exp(abs(1 - sqrt(x1.^2 + x2.^2)/pi))).^2)/30;\n \n end\n \nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/23147-many-testfunctions-for-global-optimizers/single-objective/carromtable.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897492587141, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7977593747837486}}
{"text": "function [kl1,kl2] = mvnkl(Mu1,Sigma1,Mu2,Sigma2)\n%MVNKL Kullback-Leibler divergence between two multivariate normal pdfs.\n\nD = numel(Mu1);\n\nMu1 = Mu1(:);\nMu2 = Mu2(:);\n\ndmu = Mu2 - Mu1;\ndetq1 = det(Sigma1);\ndetq2 = det(Sigma2);\nlndet = log(detq2 / detq1);\n\nkl1 = 0.5*(trace(Sigma2\\Sigma1) + dmu'*(Sigma2\\dmu) - D + lndet);\nif nargout > 1\n kl2 = 0.5*(trace(Sigma1\\Sigma2) + dmu'*(Sigma1\\dmu) - D - lndet);\nend", "meta": {"author": "acerbilab", "repo": "vbmc", "sha": "54ba2cdd6c11d2595b9613557da14573abbb7b92", "save_path": "github-repos/MATLAB/acerbilab-vbmc", "path": "github-repos/MATLAB/acerbilab-vbmc/vbmc-54ba2cdd6c11d2595b9613557da14573abbb7b92/shared/mvnkl.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474194456935, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7975921987745835}}
{"text": "function yp = fpcube ( x )\n\n%*****************************************************************************80\n%\n%% FPCUBE sets the derivative of the cubic function.\n%\n% Discussion:\n%\n% Y(X) = ( ( X + 2 ) * X + 3 ) * X + 4\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 February 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument.\n%\n% Output, real YP, the value of the derivative of the cubic function.\n%\n yp = ( 3.0E+00 * x + 4.0E+00 ) * x + 3.0E+00;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/spline/fpcube.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.8705972768020108, "lm_q1q2_score": 0.7975625348430915}}
{"text": "function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters)\n%GRADIENTDESCENT Performs gradient descent to learn theta\n% theta = GRADIENTDESENT(X, y, theta, alpha, num_iters) updates theta by \n% taking num_iters gradient steps with learning rate alpha\n\n% Initialize some useful values\nm = length(y); % number of training examples\nJ_history = zeros(num_iters, 1);\n\nfor iter = 1:num_iters\n\n % ====================== YOUR CODE HERE ======================\n % Instructions: Perform a single gradient step on the parameter vector\n % theta. \n %\n % Hint: While debugging, it can be useful to print out the values\n % of the cost function (computeCost) and gradient here.\n %\n theta_temp = theta;\n for j = 1:size(X, 2)\n theta_temp(j) = theta(j)-alpha*(1/m)*(X*theta - y)' * X(:, j);\n end\n theta = theta_temp;\n\n\n\n\n\n % ============================================================\n\n % Save the cost J in every iteration \n J_history(iter) = computeCost(X, y, theta);\n\nend\n\nend\n", "meta": {"author": "zlotus", "repo": "Coursera_Machine_Learning_Exercises", "sha": "3000f402e8e495b7c49e80c0ce4a58d42bf6b430", "save_path": "github-repos/MATLAB/zlotus-Coursera_Machine_Learning_Exercises", "path": "github-repos/MATLAB/zlotus-Coursera_Machine_Learning_Exercises/Coursera_Machine_Learning_Exercises-3000f402e8e495b7c49e80c0ce4a58d42bf6b430/ex1/gradientDescent.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.8705972633721708, "lm_q1q2_score": 0.797562522539886}}
{"text": "function x = tuple_next_fast ( m, n, rank )\n\n%*****************************************************************************80\n%\n%% TUPLE_NEXT_FAST computes the next element of a tuple space, \"fast\".\n%\n% Discussion:\n%\n% The elements are N vectors. Each entry is constrained to lie\n% between 1 and M. The elements are produced one at a time.\n% The first element is\n% (1,1,...,1)\n% and the last element is\n% (M,M,...,M)\n% Intermediate elements are produced in lexicographic order.\n%\n% This code was written as a possibly faster version of TUPLE_NEXT.\n%\n% Example:\n%\n% N = 2,\n% M = 3\n%\n% INPUT OUTPUT\n% ------- -------\n% Rank X\n% ---- ----\n% -1 -1 -1\n%\n% 0 1 1\n% 1 1 2\n% 2 1 3\n% 3 2 1\n% 4 2 2\n% 5 2 3\n% 6 3 1\n% 7 3 2\n% 8 3 3\n% 9 1 1\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 11 August 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, the maximum entry in each component.\n% M must be greater than 0.\n%\n% Input, integer N, the number of components.\n% N must be greater than 0.\n%\n% Input, integer RANK, indicates the rank of the tuples.\n% Typically, 0 <= RANK < N**M; values greater than this are\n% legal and meaningful, being equivalent to the corresponding\n% value mod N**M. RANK < 0 indicates that this is the first\n% call for the given values of (M,N). Initialization is done,\n% and X is set to a dummy value.\n%\n% Output, integer X(N), the next tuple of the given rank,\n% or a dummy value if initialization is being done.\n%\n global tuple_next_fast_BASE\n\n if ( rank < 0 )\n\n if ( m <= 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TUPLE_NEXT_FAST - Fatal error!\\n' );\n fprintf ( 1, ' M <= 0 is illegal.\\n' );\n fprintf ( 1, ' M = %d\\n', m );\n error ( 'TUPLE_NEXT_FAST - Fatal error!' );\n end\n\n if ( n <= 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TUPLE_NEXT_FAST - Fatal error!\\n' );\n fprintf ( 1, ' N <= 0 is illegal.\\n' );\n fprintf ( 1, ' N = %d\\n', n );\n error ( 'TUPLE_NEXT_FAST - Fatal error!' );\n end\n\n tuple_next_fast_BASE(n) = 1;\n for i = n-1 : -1 : 1\n tuple_next_fast_BASE(i) = tuple_next_fast_BASE(i+1) * m;\n end\n\n x(1:n) = -1;\n\n else\n\n x(1:n) = mod ( floor ( rank ./ tuple_next_fast_BASE(1:n) ), m ) + 1;\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/ccvt_reflect/tuple_next_fast.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8740772236840656, "lm_q1q2_score": 0.7975396617761051}}
{"text": "function orbEls=state2OrbEls(stateVec,elType,GM,epsVal)\n%%STATE2ORBELS Convert a state vector consisting of at least position and\n% velocity into a set of orbital elements. Such elements are\n% for a simple two-body problem where the satellite (object)\n% in motion has negligible mass. The elements can be found\n% with respect to a given epoch time.\n%\n%INPUTS: stateVec A 6XnumVec matrix of numVec state vectors consisting of\n% position and velocity in a Cartesian (quasi)-inertial\n% coordinate system where the gravitating body is at the\n% origin. Extra state elements are ignored. The units are\n% assumed to be meters and meters per second.\n% elType A value indicating the type of orbital elements. Possible\n% values are:\n% 0 (The default if omitted) The elements are Gooding's\n% universal orbital elements.\n% 2 The elements are direct equinoctial orbital elements.\n% 3 The elements are retrograde equnoctial orbital\n% elements.\n% GM Optionally, the universal gravitation constant times the\n% mass of the body about which the object with the given\n% state vector is orbiting. If this parameter is omitted,\n% the value in Constants.WGS84GMWithAtmosphere is used. The\n% units are m^3/sec^2.\n% epsVal If universal orbital elements are chosen, this is a\n% precision bound used for equality comparisons when\n% determining whether a trajectory is rectilinear,\n% parabolic or circular. If omitted, a default value of\n% eps is used.\n%\n%OUTPUTS: orbEls An 6XnumVec set of vectors of orbital elements, the format\n% of which depends on the elType parameter. The format of\n% the elements is discussed below.\n%\n%Gooding's universal orbital elements are consist of (in order)\n%alpha=GM/a where a is the semi-major axis in meters\n%q=a*(1-e) where e is the eccentricity (unitless). This is the perifocal\n% distance.\n%i inclination in radians\n%Omega longitude (right ascension) of the ascending node in radians\n%omega argument of periapsis/perigee in radians\n%tau the time at pericenter (seconds)\n%\n%The equinoctial orbital elements (for both direct and retrograde elements)\n%are\n%a semi-major axis in meters\n%h first eccentricity vector component (unitless)\n%k second eccentricity vector component (unitless)\n%p first ascending node vector component (unitless)\n%q second ascending node vector component (unitless)\n%lambda mean longitude in radians.\n%\n%The algorithm using Gooding's universal orbital elements is very robust to\n%numerical errors. It is implemented using the algorithm of [1], where the\n%elements are also described.\n%\n%Equinoctial orbital elements are discussed in Section 2 of [2]. and in\n%[3]. The diffference between direct and retrograde elements is essentially\n%a matter of handedness.\n%\n%Orbital elements are discussed in general in Chapter 2.2 of [4].\n%\n%The inverse of this function is orbEls2State, which can also predict the\n%state forward in time. Adding a time interval in seconds to the tau\n%argument also predicts the trajectory forward in terms of universal\n%orbital elements.\n%\n%REFERENCES:\n%[1] R. H. Gooding, \"On universal elements, and conversion procedures to\n% and from position and velocity,\" Celestial mechanics, vol. 44, no. 3,\n% pp. 283-298, 1988.\n%[2] D. A. Danielson, C. P. Sagovac, B. Neta, and L. W. Early,\n% \"Semianalytic satellite theory,\" Mathematics Department, Naval\n% Postgraduate School, Monterey, CA, Tech. Rep., 1995. [Online].\n% Available: http://oai.dtic.mil/oai/oai?verb=getRecord&metadataPrefix= html&identifier=ADA531136\n%[3] R. A. Broucke and P. J. Cefola, \"On the equinoctial orbit elements,\"\n% Celestial Mechanics, vol. 5, no. 3, pp. 303-310, 1972.\n%[4] O. Montenbruck and E. Gill, Satellite Orbits: Models, Methods\n% Applications. Berlin: Springer, 2000.\n%\n%January 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<4)\n epsVal=eps;\nend\n\nif(nargin<3)\n GM=Constants.WGS84GMWithAtmosphere;\nend\n\nif(nargin<2)\n elType=0;\nend\n\nnumVec=size(stateVec,2);\norbEls=zeros(6,numVec);\n\nswitch(elType)\n case 0\n for curVec=1:numVec\n orbEls(:,curVec)=state2OrbElsUniv(stateVec(1:6,curVec),GM,epsVal);\n end\n case 1\n for curVec=1:numVec\n orbEls(:,curVec)=state2OrbElsEquinoctial(stateVec(1:6,curVec),1,GM);\n end\n case 2\n for curVec=1:numVec\n orbEls(:,curVec)=state2OrbElsEquinoctial(stateVec(1:6,curVec),-1,GM);\n end\n otherwise\n error('Invalid element type provided.')\nend\n\nend\n\nfunction elEqui=state2OrbElsEquinoctial(state,I,GM)\n%%STATE2ORBELSEQUINOCTIAL An algorithm to convert from a target state to a\n% set of equinoctial orbital elements.\n%\n%The input I is the retrograde factor ond is +1 for direct equinoctial\n%elements and -1 for retrograde equinoctial elements.\n%\n%The algorithm is taken from Section 2.1.5 of\n%D. A. Danielson, C. P. Sagovac, B. Neta, and L. W. Early, \"Semianalytic\n%satellite theory,\" Mathematics Department, Naval Postgraduate School,\n%Monterey, CA, Tech. Rep., 1995. [Online]. Available:\n%http://oai.dtic.mil/oai/oai?verb=getRecord&metadataPrefix= html&identifier=ADA531136\n%\n%January 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n%position\nr=state(1:3);\n%velocity\nrDot=state(4:6);\n\n%Equation 1\na=1/(2/norm(r)-norm(rDot)^2/GM);%Semi-major axis.\n%Equation 2\nw=cross(r,rDot)/norm(cross(r,rDot));\n\n%Equation 3\np=w(1)/(1+I*w(3));%First ascending node vector component.\nq=-w(2)/(1+I*w(3));%Second ascending node vector component.\n\n%Equation 4\ne=-r/norm(r)+cross(rDot,cross(r,rDot))/GM;\n\n%Equation 2.1.4-1\ncoeff=(1/(1+p^2+q^2));\nf=coeff*[1-p^2+q^2;\n 2*p*q;\n -2*I*p];\ng=coeff*[2*I*p*q;\n (1+p^2-q^2)*I;\n 2*q];\n \n%Equation 5\nh=dot(e,g);%First eccentricity vector component.\nk=dot(e,f);%Second eccentricity vector component.\n\n%Equation 6\nX=dot(r,f);\nY=dot(r,g);\n\n%Equation 2.1.4-4\nb=1/(1+sqrt(1-h^2-k^2));\n%Equation 7\ndenom=a*sqrt(1-h^2-k^2);\nsinF=h+((1-h^2*b)*Y-h*k*b*X)/denom;\ncosF=k+((1-k^2*b)*X-h*k*b*Y)/denom;\nF=atan2(sinF,cosF);\n\nlambda=F+h*cosF-k*sinF;%Mean longitude\n\nelEqui=[a;h;k;p;q;lambda];\n\nend\n\n\nfunction elUniv=state2OrbElsUniv(state,GM,epsVal)\n%%STATE2ORBELSUNIV An implementation of Gooding's conversion from a target\n% state to universal orbital elements. This implements the\n% PV3ELS function.\n%\n%The implementation is taken from Appendix D of\n%R. H. Gooding, \"On universal elements, and conversion procedures to\n%and from position and velocity,\" Celestial mechanics, vol. 44, no. 3,\n%pp. 283-298, 1988.\n%with minor changes so that equality comparisons are replaced with\n%comparisons within a region epsVal.\n%\n%October 2014 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\nrVec=state(1:3);\nvVec=state(4:6);\nx=rVec(1);\ny=rVec(2);\nz=rVec(3);\n\nxyMag=norm(rVec(1:2));\nr=norm(rVec);\n\n%The projection of the velocity onto the radial component.\nVR=dot(rVec,vVec)/r;%Radial velocity\n\n%The angular momentum vector.\nhVec=cross(rVec,vVec);\n\nif(norm(hVec)^2=0.\n% r Radial distance.\n% u Angle from assumed reference direction.\n% GM Universal gravitational constant times the mass of the\n% gravitating body.\n% epsVal A small number for determining equality within finite\n% precision bounds.\n%\n%The algorithm is taken from Appendix C of\n%R. H. Gooding, \"On universal elements, and conversion procedures to\n%and from position and velocity,\" Celestial mechanics, vol. 44, no. 3,\n%pp. 283-298, 1988.\n%with minor changes so that equality comparisons are not performed. \n%\n%October 2014 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\nsw=0.25;\n\nVMag2=VR^2+VT^2;\nalpha=2*GM/r-VMag2;\n\nd=r*VR;\nh=r*VT;\np=h^2;\n\nesq1=p*alpha;\nes=d*sqrt(abs(alpha));\nec=r*VMag2-GM;\nif(alpha>0)%One formula superior for the ellipse\n e=sqrt(ec^2+es^2);\nelse%Different formula superior for the hyperbola\n e=sqrt(GM^2-esq1);\nend\n\nq=p/(GM+e);\nif(abs(alpha)<=epsVal)%Parabola\n tau=d*(2*q+r)/(3*GM);\n v=2*atan2(VR,VT);%The true anomaly\nelseif(abs(e)<=epsVal)%Circle\n tau=0;\n v=0;%The true anomaly\nelse%Ellipse or hyperbola\n e1=alpha*q;\n \n if(alpha>0)%Ellipse\n eh=atan2(es,ec);\n if(GM*eh^2/6+e1>GM*sw)%General case\n em=GM*eh-es;\n ecesq=GM*ec-e^2;\n else%For e1 and eh both near zero\n em=GM*GoodingSinDiffFun(e1/GM,eh);\n ecesq=(esq1*ec^2-e^2*es^2)/(e^2+GM*ec);\n end\n else%Hyperbola\n eh=asinh(es/e);\n \n if(GM*eh^2/6-e1>GM*sw)%General case\n em=es-GM*eh;\n ecesq=e^2-GM*ec;\n else%For e1 and eh both near zero\n em=e*GoodingHyperSinDiffFun(-e1/e,es/e);\n ecesq=-(esq1*ec^2+e^2*es^2)/(e^2+GM*ec);\n end\n end\n %Still ellipse or hyperbola\n en=abs(alpha)^(3/2);\n tau=em/en;\n v=atan2(es*h*sqrt(abs(alpha)),ecesq);%The true anomaly\nend\n%All orbits\nomega=u-v;%The argument of periapsis\n\n%Adjust revolutions, if necessary, so that omega remains in the range\n%-pi to pi. The second condition in the if-statement takes care of possible\n%parabolic case; this is just for the elliptical case.\nif(alpha>0&&abs(alpha)>epsVal)\n adj=2*pi*fix(abs(omega/(2*pi))+(1/2))*sign(omega);\n omega=omega-adj;\n tau=tau+adj/en;\nend\n\nend\n\n\nfunction x=GoodingSinDiffFun(e,EE)\n%%GOODINGSINDIFFFUN Evaluate the function EE-(1-e)*sin(EE) using Gooding's\n% EMKEP procedure for when e and EE are close\n% to (1,0). This is supposed to be more accurate than\n% just directly evaluating the functions, unless EE is\n% large as it is then supposed to worsen rounding errors.\n%\n%\n%The algorithm is the EMKPL algorithm taken from Appendix C of\n%A. W. Odell and R. H. Gooding, \"Procedure for solving Kepler's\n%equation,\" Celestial Mechanics, vol. 38, no. 4, pp. 307-334, Apr. 1986.\n%modified to solve EE-(1-e)*sin(EE) instead of EE-e*sin(EE).\n%\n%October 2014 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\nx=e*sin(EE);\nEE2=-EE^2;\nterm=EE;\nd=0;\nwhile(1)\n d=d+2;\n term=term*EE2/(d*(d+1));\n x0=x;\n x=x-term;\n if(x==x0)\n break;\n end\nend\n\nend\n\n\nfunction x=GoodingHyperSinDiffFun(g1,s)\n%%GOODINGHYPERSINDIFFFUN Evaluate the function s-(1-g1)*asinh(s) when\n% (g1,s) is close to (0,0) using Gooding's method.\n% This is supposed to have a higher precision than\n% just explicitly evaluating the function.\n%\n%The algorithm is the SHMKEP function taken from Appendix B of \n%R. H. Gooding and A. W. Odell, \"The hyperbolic Kepler's equation,\n%and the elliptic equations revisited,\" Royal Aerospace Executive,\n%Procurement Executive, Ministry of Defence, Farnborough, Hants, United\n%Kingdom, Tech. Rep. 369, Jul. 1989.\n%\n%October 2014 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\ng=1-g1;\nt=s/(1+sqrt(1+s^2));\nx=s*(g1+g*t^2);\nterm=2*g*t;\ntwoI1=1;\n%Iterate until convergence or until a maximum number of iterations is\n%reached.\nmaxIter=64;\nfor curIter=1:maxIter\n twoI1=twoI1+2;\n term=term*t^2;\n x0=x;\n x=x-term/twoI1;\n if(x==x0)\n break;\n end\nend\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Astronomical_Code/state2OrbEls.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.8499711794579722, "lm_q1q2_score": 0.7973783748923229}}
{"text": "function fx = p34_fun ( n, x )\n\n%*****************************************************************************80\n%\n%% P34_FUN evaluates the integrand for problem 34.\n%\n% Interval:\n%\n% 0 <= x <= 1\n%\n% Integrand:\n%\n% ( 10 * x - 1 ) * ( 10 * x - 1.1 ) * ( 10 * x - 1.2 ) * ( 10 * x - 1.3 )\n%\n% Exact Integral:\n%\n% 1627879 / 1500\n%\n% Approximate Integral (20 digits):\n%\n% 1085.2526666666666666...\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 04 November 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Hermann Engels,\n% Numerical Quadrature and Cubature,\n% Academic Press, 1980.\n%\n% Parameters:\n%\n% Input, integer N, the number of evaluation points.\n%\n% Input, real X(N), the evaluation points.\n%\n% Output, real FX(N), the integrand values.\n%\n fx = ( 10.0 * x - 1.0 ) .* ( 10.0 * x - 1.1 ) .* ( 10.0 * x - 1.2 ) ...\n .* ( 10.0 * x - 1.3 );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_int/p34_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.8670357598021707, "lm_q1q2_score": 0.7973629664947972}}
{"text": "function p = gaussian_prob(x, m, C, use_log)\n% GAUSSIAN_PROB Evaluate a multivariate Gaussian density.\n% p = gaussian_prob(X, m, C)\n% p(i) = N(X(:,i), m, C) where C = covariance matrix and each COLUMN of x is a datavector\n\n% p = gaussian_prob(X, m, C, 1) returns log N(X(:,i), m, C) (to prevents underflow).\n%\n% If X has size dxN, then p has size Nx1, where N = number of examples\n\nif nargin < 4, use_log = 0; end\n\nif length(m)==1 % scalar\n x = x(:)';\nend\n[d N] = size(x);\n%assert(length(m)==d); % slow\nm = m(:);\nM = m*ones(1,N); % replicate the mean across columns\ndenom = (2*pi)^(d/2)*sqrt(abs(det(C)));\nmahal = sum(((x-M)'*inv(C)).*(x-M)',2); % Chris Bregler's trick\nif any(mahal<0)\n warning('mahal < 0 => C is not psd')\nend\nif use_log\n p = -0.5*mahal - log(denom);\nelse\n p = exp(-0.5*mahal) / (denom+eps);\nend\n", "meta": {"author": "bayesnet", "repo": "bnt", "sha": "bebba5f437b4e1e29169f0f3669df59fb5392e62", "save_path": "github-repos/MATLAB/bayesnet-bnt", "path": "github-repos/MATLAB/bayesnet-bnt/bnt-bebba5f437b4e1e29169f0f3669df59fb5392e62/KPMstats/gaussian_prob.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067195846919, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7973064370361043}}
{"text": "function [v,d,dref] = generate_doddbench(N)\n% Generate DODDBENCH signal.\n%\n% Benchmark signal introduced in Dodd, T.J., Kadirkamanathan, V. and\n% Harrison, R.F., \"Function estimation in Hilbert space using sequential\n% projections,\" Proc. of the IFAC Conf. on Intelligent Control Systems and\n% Signal Processing, 113-118, 2003.\n% \n% Comment: copyright Cedric Richard, http://cedric-richard.fr/\n%\n% Input: N: number of data points\n% \n% Outputs: v: input sequence (2-dimensional sequence [v(:,1);v(:,2)])\n% d: noisy desired output (1-dimensional sequence)\n% dref: noise-free desired output\n%\n% This file is part of the Kernel Adaptive Filtering Toolbox for Matlab.\n% https://github.com/steven2358/kafbox/\n\ndref = zeros(1,N+2);\ndref(1:2)=[0.1 0.1];\n\nfor t=3:N+2\n dref(t) = (0.8-0.5*exp(-dref(t-1)^2))*dref(t-1) - ...\n (0.3+0.9*exp(-dref(t-1)^2))*dref(t-2)+0.1*sin(pi*dref(t-1));\nend\nd = dref + 0.1*randn(1,N+2);\nv = [d(1:N); d(2:N+1)]';\n\nd(1:2)=[];\ndref(1:2)=[];\n", "meta": {"author": "steven2358", "repo": "kafbox", "sha": "694cf94df02a9728a90d7bacda1a8520b425f86f", "save_path": "github-repos/MATLAB/steven2358-kafbox", "path": "github-repos/MATLAB/steven2358-kafbox/kafbox-694cf94df02a9728a90d7bacda1a8520b425f86f/demo/literature/richard2009online/generate_doddbench.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294587, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7973064356435208}}
{"text": "function [ x, seed ] = simplex_unit_sample ( dim_num, n, seed )\n\n%*****************************************************************************80\n%\n%% SIMPLEX_UNIT_SAMPLE samples the unit simplex.\n%\n% Discussion:\n%\n% The interior of the unit DIM_NUM-dimensional simplex is the set of\n% points X(1:DIM_NUM) such that each X(I) is nonnegative, and\n% sum(X(1:DIM_NUM)) <= 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 August 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Reuven Rubinstein,\n% Monte Carlo Optimization, Simulation, and Sensitivity\n% of Queueing Networks,\n% Wiley, 1986.\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the dimension of the space.\n%\n% Input, integer N, the number of points.\n%\n% Input/output, integer SEED, a seed for the random number generator.\n%\n% Output, real X(DIM_NUM,N), the points.\n%\n\n%\n% The construction begins by sampling DIM_NUM+1 points from the\n% exponential distribution with parameter 1.\n%\n for j = 1 : n\n\n [ e, seed ] = r8vec_uniform_01 ( dim_num+1, seed );\n\n e(1:dim_num+1) = -log ( e(1:dim_num+1) );\n\n x(1:dim_num,j) = e(1:dim_num)' / sum ( e(1:dim_num+1) );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/simplex_gm_rule/simplex_unit_sample.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067163548471, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.79730643064319}}
{"text": "function area = triangle_area_2d ( t )\n\n%*****************************************************************************80\n%\n%% TRIANGLE_AREA_2D computes the area of a triangle in 2D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 January 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real T(2,3), the triangle vertices.\n%\n% Output, real AREA, the absolute area of the triangle.\n%\n area = 0.5 * abs ( ...\n t(1,1) * ( t(2,2) - t(2,3) ) ...\n + t(1,2) * ( t(2,3) - t(2,1) ) ...\n + t(1,3) * ( t(2,1) - t(2,2) ) );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/triangulation/triangle_area_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404018582427, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7972443271340975}}
{"text": "\nif (~exist('syms.m','file')) \n fprintf('The symbolic toolbox is not installed, skipping test\\n');\n return;\nend\n\n%% Gradients\nclear\nclc\n\nsyms x1 x2\nx = [0.1;0.1];\n\n%OPTI Sym\nfun = @(x) sin(x(1) + x(2)) + (x(1) - x(2))^2 - 1.5*x(1) + 2.5*x(2) + 1\n[jac,jacp] = symJac(fun)\n[hess,hessp] = symHess(fun)\n\n%Symbolic\nsfun = sin(x1+x2) + (x1-x2)^2 - 1.5*x1 + 2.5*x2 + 1\njac1 = jacobian(sfun)\nhess1 = hessian(sfun)\n\n%Eval\n[jac(x);double(subs(jac1,{'x1','x2'},{x(1) x(2)}))]\nfull(jacp())\n[hess(x);double(subs(hess1,{'x1','x2'},{x(1) x(2)}))]\nfull(hessp())\n\n%OPTI Sym\nfun = @(x) [x(1) + x(2) - 1; \n x(1)^2 + x(2)^2 - 1];\njac = symJac(fun)\n\n%Symbolic\nfun = [x1 + x2 - 1; \n x1^2 + x2^2 - 1];\njac1 = jacobian(fun)\n\n%Eval\n[jac(x);double(subs(jac1,{'x1','x2'},{x(1) x(2)}))]\n\n%OPTI Sym\nfun = @(x) 0.01*(x(1)-1)^2 + (x(2)-x(1)^2)^2;\n[jac,jacp] = symJac(fun)\n[hess,hessp] = symHess(fun)\n\n%Symbolic\nsfun = 0.01*(x1-1)^2 + (x2-x1^2)^2;\njac1 = jacobian(sfun)\nhess1 = hessian(sfun)\n\n%Eval\n[jac(x);double(subs(jac1,{'x1','x2'},{x(1) x(2)}))]\nfull(jacp())\n[hess(x);double(subs(hess1,{'x1','x2'},{x(1) x(2)}))]\nfull(hessp())\n\n\n%% Symbolic Hessian of Lagrangian\nclc\nfun = @(x) x(1)*x(4)*(x(1) + x(2) + x(3)) + x(3);\n% Nonlinear Constraints \n nlcon = @(x) [ x(1)*x(2)*x(3)*x(4); \n x(1)^2 + x(2)^2 + x(3)^2 + x(4)^2 ];\n\njac = symJac(fun) \nhessObj = symHess(fun)\n\n[hessLag,pattern] = symHessLag(fun,nlcon,4,true)\n\n\n% Hessian\n H = @(x,sigma,lambda) sparse(sigma*[ 2*x(4) 0 0 0;\n x(4) 0 0 0;\n x(4) 0 0 0;\n 2*x(1)+x(2)+x(3) x(1) x(1) 0 ] + ...\n lambda(1)*[ 0 0 0 0;\n x(3)*x(4) 0 0 0;\n x(2)*x(4) x(1)*x(4) 0 0;\n x(2)*x(3) x(1)*x(3) x(1)*x(2) 0 ] + ...\n lambda(2)*diag([2 2 2 2]));\n \n \nx = 0.1:0.1:0.4;\nsigma = 0.3;\nlambda = 1:2;\n\nhessLag(x,sigma,lambda)\nfull(H(x,sigma,lambda))\nfull(pattern())\n\n\n%% Application to an NLP, first no derivs\nclc\n% Objective\n fun = @(x) x(1)*x(4)*(x(1) + x(2) + x(3)) + x(3);\n\n% Nonlinear Constraints \n nlcon = @(x) [ x(1)*x(2)*x(3)*x(4); \n x(1)^2 + x(2)^2 + x(3)^2 + x(4)^2 ];\n cl = [25;40];\n cu = [Inf;40]; \n\n% Bounds (lb <= x <= ub)\n lb = ones(4,1);\n ub = 5*ones(4,1); \n\n% Initial Guess\n x0 = [1 5 5 1]';\n \nopts = optiset('display','iter','solver','ipopt','derivCheck','on','solverOpts',ipoptset('derivative_test','first-order'));\nOpt = opti('fun',fun,'nl',nlcon,cl,cu,'bounds',lb,ub,'x0',x0,'options',opts)\n\n[x,f,e,i] = solve(Opt)\n\n\n%% Application to an NLP, now with symJac, symHessLag\nclc\n% Objective\n fun = @(x) x(1)*x(4)*(x(1) + x(2) + x(3)) + x(3);\n\ngrad = symJac(fun); \n \n% Nonlinear Constraints \n nlcon = @(x) [ x(1)*x(2)*x(3)*x(4); \n x(1)^2 + x(2)^2 + x(3)^2 + x(4)^2 ];\n \n[nljac,nljacstr] = symJac(nlcon);\n \n cl = [25;40];\n cu = [Inf;40]; \n \n %Hessian\n [hess,hstr] = symHessLag(fun,nlcon);\n\n% Bounds (lb <= x <= ub)\n lb = ones(4,1);\n ub = 5*ones(4,1); \n\n% Initial Guess\n x0 = [1 5 5 1]';\n \nopts = optiset('display','iter','solver','ipopt','derivCheck','on','solverOpts',ipoptset('derivative_test','second-order'));\nOpt = opti('fun',fun,'grad',grad,'nl',nlcon,cl,cu,'nljac',nljac,'nljacstr',nljacstr,'H',hess,'HStr',hstr,'bounds',lb,ub,'x0',x0,'options',opts)\n\n[x,f,e,i] = solve(Opt)\n \n\n%% Application to an NLP, analytical derivs supplied\nclc\n% Objective\n fun = @(x) x(1)*x(4)*(x(1) + x(2) + x(3)) + x(3);\n\n% Gradient\n grad = @(x) [x(1)*x(4) + x(4)*sum(x(1:3)), x(1)*x(4),...\n x(1)*x(4) + 1, x(1)*sum(x(1:3))];\n \n% Nonlinear Constraints \n nlcon = @(x) [ x(1)*x(2)*x(3)*x(4); \n x(1)^2 + x(2)^2 + x(3)^2 + x(4)^2 ];\n \n% Jacobian\n jac = @(x) sparse([prod(x')./x';\n 2.*x']);\n\n% Jacobian Structure\n jacstr = @() sparse(ones(2,4));\n \n cl = [25;40];\n cu = [Inf;40]; \n \n %Hessian\n% Hessian\n H = @(x,sigma,lambda) sparse(sigma*[ 2*x(4) 0 0 0;\n x(4) 0 0 0;\n x(4) 0 0 0;\n 2*x(1)+x(2)+x(3) x(1) x(1) 0 ] + ...\n lambda(1)*[ 0 0 0 0;\n x(3)*x(4) 0 0 0;\n x(2)*x(4) x(1)*x(4) 0 0;\n x(2)*x(3) x(1)*x(3) x(1)*x(2) 0 ] + ...\n lambda(2)*diag([2 2 2 2]));\n\n% Hessian Structure\n Hstr = @() sparse(tril(ones(4)));\n\n% Bounds (lb <= x <= ub)\n lb = ones(4,1);\n ub = 5*ones(4,1); \n\n% Initial Guess\n x0 = [1 5 5 1]';\n \nopts = optiset('display','iter','solver','ipopt','derivCheck','on','solverOpts',ipoptset('derivative_test','second-order'));\nOpt = opti('fun',fun,'grad',grad,'nl',nlcon,cl,cu,'nljac',nljac,'nljacstr',nljacstr,'H',H,'HStr',hstr,'bounds',lb,ub,'x0',x0,'options',opts)\n\n[x,f,e,i] = solve(Opt)\n \n \n", "meta": {"author": "Arrowstar", "repo": "ksptot", "sha": "2b414440d3b167ba2294f56dafce0f465c07f982", "save_path": "github-repos/MATLAB/Arrowstar-ksptot", "path": "github-repos/MATLAB/Arrowstar-ksptot/ksptot-2b414440d3b167ba2294f56dafce0f465c07f982/helper_methods/math/opti/Test Problems/Development/test_sym_diff.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.8596637505099167, "lm_q1q2_score": 0.797220612272447}}
{"text": "function n = vectorNorm3d(v)\n%VECTORNORM3D Norm of a 3D vector or of set of 3D vectors\n%\n% N = vectorNorm3d(V);\n% Returns the norm of vector V.\n%\n% When V is a N-by-3 array, compute norm for each vector of the array.\n% Vector are given as rows. Result is then a N-by-1 array.\n%\n% NOTE: compute only euclidean norm.\n%\n% See Also\n% vectors3d, normalizeVector3d, vectorAngle3d, hypot3\n%\n\n% ---------\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 21/02/2005.\n\n% HISTORY\n% 19/06/2009 rename as vectorNorm3d\n\nn = sqrt(sum(v.*v, 2));\n", "meta": {"author": "rpng", "repo": "lips", "sha": "a97157e586b509c9c2e3e01e64e4347f36d0b63e", "save_path": "github-repos/MATLAB/rpng-lips", "path": "github-repos/MATLAB/rpng-lips/lips-a97157e586b509c9c2e3e01e64e4347f36d0b63e/lips_matlab/matlab/functions/matGeom/geom3d/vectorNorm3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.7972206088795434}}
{"text": "function result = polygon_x_2d ( n, v )\n\n%*****************************************************************************80\n%\n%% POLYGON_X_2D integrates the function X over a polygon in 2D.\n%\n% Discussion:\n%\n% The polygon is bounded by the points (X(1:N), Y(1:N)).\n%\n% INTEGRAL = (1/6) * sum ( 1 <= I <= N )\n% ( X(I)^2 + X(I) * X(I-1) + X(I-1)^2 ) * ( Y(I) - Y(I-1) )\n%\n% where X(0) and Y(0) should be replaced by X(N) and Y(N).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 27 February 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% S F Bockman,\n% Generalizing the Formula for Areas of Polygons to Moments,\n% American Mathematical Society Monthly,\n% 1989, pages 131-132.\n%\n% Parameters:\n%\n% Input, integer N, the number of vertices of the polygon.\n% N should be at least 3 for a nonzero result.\n%\n% Input, real V(2,N), the coordinates of the vertices\n% of the polygon. These vertices should be given in counter-clockwise order.\n%\n% Output, real RESULT, the value of the integral.\n%\n result = 0.0;\n\n if ( n < 3 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'POLYGON_X_2D - Warning!\\n' );\n fprintf ( 1, ' The number of vertices must be at least 3.\\n' );\n fprintf ( 1, ' The input value of N = %d\\n', n );\n return\n end\n\n for i = 1 : n\n\n if ( i == 1 )\n im1 = n;\n else\n im1 = i - 1;\n end\n\n result = result + ( v(1,i).^2 + v(1,i) * v(1,im1) + v(1,im1).^2 ) ...\n * ( v(2,i) - v(2,im1) );\n\n end\n\n result = result / 6.0;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/polygon_x_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167044, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7972206069191615}}
{"text": "function pde = Darcydata4\n%% Darcydata4 diagonal and anisotropic tensor\n%\n% p = x^2 + y^2\n% K = [1 + 4*(x^2 + y^2) 0 ]\n% = [0 1 + 11*(x^2 + y^2)]\n\npde = struct('exactp',@exactp,'K',@K,'exactu',@exactu,'Dp',@gradp,...\n 'f', @f,'g_D',@g_D,'g_N',@g_N);\n\n function s = K(pt)\n x = pt(:,1); y = pt(:,2);\n% s(:,3) = 3*x.*y; \n s(:,1) = 1 + 4*(x.^2 + y.^2);\n s(:,2) = 1 + 11*(x.^2 + y.^2);\n end\n function s = exactp(pt)\n x = pt(:,1); y = pt(:,2);\n% s = x.^3.*y + y.^4 + sin(pi*x).*cos(pi*y);\n s = x.^2 + y.^2;\n end\n function s = gradp(pt)\n x = pt(:,1); y = pt(:,2);\n% s(:,2) = x.^3 + 4*y.^3 - pi*sin(pi*x).*sin(pi*y);\n% s(:,1) = 3*x.^2.*y + pi*cos(pi*x).*cos(pi*y); \n s(:,2) = 2*y;\n s(:,1) = 2*x; \n end\n function s = exactu(pt)\n Dp = gradp(pt); % u = K*grad(p)\n K = K(pt);\n s(:,2) = K(:,2).*Dp(:,2);\n s(:,1) = K(:,1).*Dp(:,1);\n end\n function s = f(pt)\n x = pt(:,1); y = pt(:,2);\n% s = 2+24*x.^2+14*y.^2+6*x.^2+2+22*x.^2+66*y.^2;\n s = 2+24*x.^2+16*y.^2++2+22*x.^2+66*y.^2;\n s = -s;\n end\n function s = g_D(pt)\n s = exactp(pt); \n end\n function f = g_N(p,vargin)\n if nargin > 1\n f = dot(exactu(p),vargin,2);\n else\n f = zeros(size(p,1),1);\n x = p(:,1); \n y = p(:,2);\n uprime = exactu(p);\n leftbd = (abs(x)= sum(isnan(yhat)) \n yhat(isnan(y))=[];\n y(isnan(y))=[];\n else\n y(isnan(yhat))=[]; \n yhat(isnan(yhat))=[];\n end\nend\n\n% 1 - SSe/SSt\nR2 = 1 - ( sum( (y-yhat).^2 ) / sum( (y-mean(y)).^2 ) );\n\n% SSr/SSt\n% R2 = sum((yhat-mean(y)).^2) / sum( (y-mean(y)).^2 ) ;\n\nif R2<0 || R2>1\n error(['R^2 of ',num2str(R2),' : yhat does not appear to be the estimate of y from a regression.'])\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/13872-rsquare/rsquare.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966732132747, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7968693552357399}}
{"text": "function dist = sphere_distance_xyz ( xyz1, xyz2 )\n\n%*****************************************************************************80\n%\n%% SPHERE_DISTANCE_XYZ computes great circle distances on a sphere.\n%\n% Discussion:\n%\n% XYZ coordinates are used.\n%\n% We assume the points XYZ1 and XYZ2 lie on the same sphere.\n%\n% This computation is a special form of the Vincenty formula.\n% It should be less sensitive to errors associated with very small\n% or very large angular separations.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 August 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% \"Great-circle distance\",\n% Wikipedia.\n%\n% Parameters:\n%\n% Input, real XYZ1(3), the coordinates of the first point.\n%\n% Input, real XYZ2(3), the coordinates of the second point.\n%\n% Output, real DIST, the great circle distance between the points.\n%\n r = norm ( xyz1 );\n\n lat1 = r8_asin ( xyz1(3) );\n lon1 = r8_atan ( xyz1(2), xyz1(1) );\n\n lat2 = r8_asin ( xyz2(3) );\n lon2 = r8_atan ( xyz2(2), xyz2(1) );\n\n top = ( cos ( lat2 ) * sin ( lon1 - lon2 ) ).^2 ...\n + ( cos ( lat1 ) * sin ( lat2 ) ...\n - sin ( lat1 ) * cos ( lat2 ) * cos ( lon1 - lon2 ) ).^2;\n\n top = sqrt ( top );\n\n bot = sin ( lat1 ) * sin ( lat2 ) ...\n + cos ( lat1 ) * cos ( lat2 ) * cos ( lon1 - lon2 );\n\n dist = r * atan2 ( top, bot );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/sphere_distance_xyz.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.946596665680527, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7968693470162734}}
{"text": "%%% This program provides a numerical verification that equations (15.2)\n%%% and (15.6) coincide in a 2x2 case. The program generates a random 2x2\n%%% GOE matrix H and uses it to compute the numerical value of Z(x)\n%%% according to the two formulas. You will be asked to choose the real and\n%%% imaginary parts of the number x (imaginary part has to be positive).\n\nclear all\nclose all\n\n%%% Reads the real part from the Command Window\nprompt = '\\n Choose real part of argument x: ';\nre = input(prompt);\n\n%%% Reads the imaginary part from the Command Window\nprompt = '\\n Choose imaginary part of argument x: ';\nim = input(prompt);\n\nif im <= 0\n sprintf('ERROR: Imaginary part has to be positive')\n return;\nend\n\nx = re - i*im;\n\n%%% Generating 2x2 GOE matrix\nH = randn(2)/sqrt(2);\nH = (H + H')/2;\n\n%%% Eigenvalues of matrix H\nE = eig(H);\n\n%%% Definition of integrand function for Z\nf = @(y1,y2) exp(-i*((x-H(1,1)).*y1.^2 + 2.*H(1,2).*y1.*y2 + (x-H(2,2)).*y2.^2)/2);\n\n%%% Z function\nZ = integral2(f,-Inf,Inf,-Inf,Inf);\n\n%%% Explicit form of Z function\nZ_exp = 2*pi*exp(-(log(E(1)-x) + log(E(2)-x))/2 + i*pi/2);\n\nsprintf('Value of Z function computed as integral: %6.4f%+6.4fi',real(Z),imag(Z))\nsprintf('Value of Z function computed explicitly via eigenvalues of H: %6.4f%+6.4fi',real(Z_exp),imag(Z_exp))\n\n", "meta": {"author": "RMT-TheoryAndPractice", "repo": "RMT", "sha": "8710c8bafb25b0abde206c9d869a8acdd582dbed", "save_path": "github-repos/MATLAB/RMT-TheoryAndPractice-RMT", "path": "github-repos/MATLAB/RMT-TheoryAndPractice-RMT/RMT-8710c8bafb25b0abde206c9d869a8acdd582dbed/Zmultiple.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172587090975, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7968380508425176}}
{"text": "function AInv=invert2X2Matrix(A)\n%%INVERT2X2MATRIX Inver the 2X2 matrix A. This function demonstrates the\n% algorithm given in [1], which is more efficient than Gaussian\n% elimination. This could be used as a template for implementation in\n% other languages. In Matlab, this function is not faster than the\n% built-in inv function.\n%\n%INPUTS: A A 2X2 real or complex invertible matrix.\n%\n%OUTPUTS: AInv The 2X2 matrix inverse of A. \n%\n%EXAMPLE:\n%This just shows that this function produces the same result as Matlab\n%within finite precision limitations.\n% A=randn(2,2);\n% C=invert2X2Matrix(A);\n% C1=inv(A);%Matlab's way.\n% RelErr=max(max(abs(abs((C-C1)./C1))))\n%\n%REFERENCES:\n%[1] V. Strassen, \"Gaussian elimination is not optimal,\" Numerische\n% Mathematik, vol. 13, pp. 354-356, 1965.\n%\n%October 2022 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nI=1/A(1,1);\nII=A(2,1)*I;\nIII=I*A(1,2);\nIV=A(2,1)*III;\nV=IV-A(2,2);\nVI=1/V;\n\nAInv=zeros(2,2);\nAInv(1,2)=III*VI;\nAInv(2,1)=VI*II;\nVII=III*AInv(2,1);\nAInv(1,1)=I-VII;\nAInv(2,2)=-VI;\n\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Basic_Matrix_Operations/Fixed_Size_Operations/invert2X2Matrix.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.8807970842359876, "lm_q1q2_score": 0.7968135535693902}}
{"text": "% Demo script for software from the paper\n% 'Generating spike-trains with specified correlations',\n% Macke et al., submitted for publication, 2008\n%\n% www.kyb.mpg.de/bethgegroup/code/efficientsampling\n%\n% Instructions:\n% - Change to the code directory and run demo.m\n% - The script will take you through the functions .\n% - After each step, the script will pause. \n% - To continue, hit any button.\n% - Read along in the demo.m file to follow what's happening.\n%\n% If you have questions, feel free to email us.\n\nf = 1;\nfprintf('\\nDemo program for GENERATING SPIKE TRAINS WITH SPECIFIED CORRELATIONS, Macke et al.\\n')\n\n\n%% Step 1: Generating correlated binary variables (2D example)\nmu = [.4,.3]'; % set the mean\nv = mu.*(1-mu); % calculate the variances\nC = diag(v); % build covariance matrix\nC(1,2) = .1;\nC(2,1) = .1;\n\n[S,g,L] = sampleDichGauss01(mu,C,1e5); % generate samples from the DG model\n\nmuHat = mean(S,2); % estimate mean\nCHat = cov(S'); % estimate covariance\n\nfprintf('\\nStep 1: Generating correlated binary variables (section 2.1)\\n\\n')\nfprintf('Target mean X1: %.2f Estimated mean X1: %.3f\\n',mu(1),muHat(1))\nfprintf('Target mean X2: %.2f Estimated mean X2: %.3f\\n',mu(2),muHat(2))\nfprintf('Target cov X1X2: %.2f Estimated cov X1X2: %.3f\\n',C(1,2),CHat(1,2))\n\ndisp('To proceed to compare histograms, hit any key...')\npause\n\n%% Step 2: How much do correlations change the distribution when means are\n% assumed to be equal?\n\nfprintf('\\nStep 2: Effect of correlations\\n\\n')\nfprintf('Computing...\\n')\n\n% First, we generate a mean vector in ten dimensions. We assume that all\n% means are approximately .5, but we add some Gaussian noise to the network\n% is not to uniform. We set the covariances so that the resulting\n% correlations are sizable, but not to large (~0.1). \n\nmu = ones(10,1) * .2 + randn(10,1)*0.05;\nv = mu.*(1-mu);\nC = ones(10,10) * .02;\nC(eye(size(C))==1) = v;\n\n% We find the histogram of the independent distribution with this mean\n% vector P(x) = PROD_i P(X_i=1) and the DG distribution with the same mean\n% and the covariances as defined above.\n\nh1 = binHistIndep(mu); % returns the histogram of an independet distribution\nS = sampleDichGauss01(mu,C,1e5);\nh2 = binHist(S); % creates a histogram of the binary patterns in S\nh2 = h2 / sum(h2);\n\n% When we compare them, we see that some patterns occur much more often \n% in the correlated then in the independent distribution. This a clear\n% indication of the strength of the correlations. The \"stripes\" coincide\n% with patterns with a different number of active neurons (starting at 0 in\n% the upper left corner).\n\nfigure(f)\nloglog(h1,h2,'k.')\nxlabel('P(X) in independent model')\nylabel('P(X) in DG model')\ntitle('Step 2: What effect do correlations have?')\naxis square\n\nf = f+1;\n\n\ndisp('To proceed to generate Poisson RVs, hit any key...')\npause\n\n%% Step 3: Correlated Poisson from a binary process (3.1)\n% First, we generate samples from a correlated Poisson distribution with\n% specified mean and covariance matrix. The covariance between the two\n% distributions is positive and quite strong. The construction follows the\n% description in section 3.1, i.e. we first find a binary process with the\n% correct parameters and sum over it. This means we create\n% a joint Poisson distribution.\n\nfprintf('\\nStep 3: Correlated Poisson from a binary process (3.1)\\n\\n')\nfprintf('Computing...\\n')\n\nmu = [7,9]'; % set the mean\nC = [7 3;3 9]; % set an admissable covariance matrix\n\nS = sampleCovPoisson(mu,C,10000); % generate sample via discretized Gaussian\n\n% We obtain a set of samples S. Next, we verify that the samples have \n% desired mean and covariance structure. We see that this is indeed the case.\n\nmuHat = mean(S,2);\nCHat = cov(S');\n\nfprintf('Target mean X1: %.2f Estimated mean X1: %.3f\\n',mu(1),muHat(1))\nfprintf('Target mean X2: %.2f Estimated mean X2: %.3f\\n',mu(2),muHat(2))\nfprintf('Target cov X1X2: %.2f Estimated cov X1X2: %.3f\\n',C(1,2),CHat(1,2))\n\ndisp('To plot the marginals and joint histogram, hit any key...')\npause\nfprintf('Computing...\\n')\n\nfigure (f)\n\n% Now, we look at the marginal distribution we obtain from our sampling\n% procedure. For comparison, we also plot the true 1D Poisson distributions\n% as specified by the mean of the marginal (dotted). We see that they are\n% very close to one another. \n\nh1 = histc(S(1,:),0:30); h1 = h1/sum(h1);\nh2 = histc(S(2,:),0:30); h2 = h2/sum(h2);\n\nsubplot(1,2,1)\nplot(0:length(h1)-1,h1,'-r','markersize',5), hold on\nplot(0:length(h1),poisspdf(0:length(h1),mu(1)),'.r','markersize',5)\nplot(0:length(h2)-1,h2,'-g','markersize',5)\nplot(0:length(h1),poisspdf(0:length(h1),mu(2)),'.g','markersize',5)\nt = legend('X_1','X_1 Poisson','X_2','X_2 Poisson');\nset(t,'box','off')\naxis square\nxlabel('X'), ylabel('P(X)')\ntitle(sprintf('Step 3: Correlated Poisson, Positive Correlation\\nMarginal Distributions with Poisson\\n distribution with correct mean'))\n\n% Finally, we convince ourselves that the two variables are indeed\n% positively correlated by looking at the 2D joint histogram. We can see\n% that although the marginals are perfect Poissonian, most samples are\n% concentrated along the main diagonal, indicating the positive\n% correlation.\n\nsubplot(1,2,2)\nhh = EstimateDiscreteJoint(S);\nimagesc(hh)\naxis square\ntitle('')\nxlabel('X_1'), ylabel('X_2')\n\ndisp('To proceed to positively correlated Poisson variables with another method, hit any key...')\npause\n\n\nf = f+1;\n\n\n%% Step 4: Generating correlated Poisson variables via the method \n% in section 3.3 for positive correlations\n%\n% Again, we generate samples from a correlated Poisson distribution with\n% specified mean and covariance matrix. The covariance between the two\n% distributions is positive and quite strong. The construction follows now\n% section 3.3, so we truncate a Gaussian to obtain a distribution with\n% Poisson marginals and a given covariance.\n\nfprintf('\\nStep 4: Generating positively correlated Poisson variables (section 3.3)\\n\\n')\nfprintf('Computing...\\n')\n\nmu = [7,9]'; % set the mean\nC = [7 3;3 9]; % set an admissable covariance matrix\n\n[S,gamma,Lambda,joints2D] = DGPoisson(mu,C,1e5); % generate sample via discretized Gaussian\n\n% We obtain a set of samples S, the parameters of the hidden Gaussian\n% variable (gamma and Lambda) and a structure containing the marginal\n% distributions as well as the 2D joint distribution\n\n% Next, we verify that the samples have desired mean and covariance\n% structure. We see that this is indeed the case.\n\nmuHat = mean(S,2);\nCHat = cov(S');\n\n\nfprintf('Target mean X1: %.2f Estimated mean X1: %.3f\\n',mu(1),muHat(1))\nfprintf('Target mean X2: %.2f Estimated mean X2: %.3f\\n',mu(2),muHat(2))\nfprintf('Target cov X1X2: %.2f Estimated cov X1X2: %.3f\\n',C(1,2),CHat(1,2))\n\ndisp('To plot the marginals and joint histogram, hit any key...')\npause\n\nfigure(f)\n\n% Now, we look at the marginal distribution we obtain from our sampling\n% procedure. For comparison, we also plot the true 1D Poisson distributions\n% as specified by the mean of the marginal (dotted). We see that they are\n% very close to one another. \n\nsubplot(2,2,1)\nh1 = joints2D{1,1}; % marginal of X_1\nh2 = joints2D{2,2}; % marginal of X_2\nplot(0:length(h1)-1,h1,'-r','markersize',5), hold on\nplot(0:length(h1),poisspdf(0:length(h1),mu(1)),'.r','markersize',5)\nplot(0:length(h2)-1,h2,'-g','markersize',5)\nplot(0:length(h1),poisspdf(0:length(h1),mu(2)),'.g','markersize',5)\nt = legend('X_1','X_1 Poisson','X_2','X_2 Poisson');\nset(t,'box','off')\naxis square\nxlabel('X'), ylabel('P(X)')\ntitle(sprintf('Step 4: Correlated Poisson, Positive Correlation\\nMarginal Distributions with Poisson\\n distribution with correct mean'))\n\n% Finally, we convince ourselves that the two variables are indeed\n% positively correlated by looking at the 2D joint histogram. We can see\n% that although the marginals are perfect Poissonian, most samples are\n% concentrated along the main diagonal, indicating the positive\n% correlation.\n\nsubplot(2,2,3)\nhh = joints2D{2}; % joint histogram\nimagesc(hh)\naxis square\ntitle('')\nxlabel('X_1'), ylabel('X_2')\n\ndisp('To proceed to negatively correlated Poisson variables, hit any key...')\npause\n\n%% Step 5: Generating correlated Poisson variables via the method \n% in section 3.3 for negative correlations\n%\n% Again, we generate samples from a correlated Poisson distribution with\n% specified mean and covariance matrix. This time the covariance is\n% negative though.\n\nfprintf('\\nStep 5: Generating negatively correlated Poisson variables (section 3.3)\\n\\n')\nfprintf('Computing...\\n')\n\nmu = [7,9]'; % set the mean\nC = [7 -3;-3 9]; % set an admissable covariance matrix\n\n[S,gamma,Lambda,joints2D] = DGPoisson(mu,C,1e5); % generate sample via discretized Gaussian\n\n% Next, we verify that the samples have desired mean and covariance\n% structure. We see that this is indeed the case. \n\nmuHat = mean(S,2);\nCHat = cov(S');\n\nfprintf('Target mean X1: %.2f Estimated mean X1: %.3f\\n',mu(1),muHat(1))\nfprintf('Target mean X2: %.2f Estimated mean X2: %.3f\\n',mu(2),muHat(2))\nfprintf('Target cov X1X2: %.2f Estimated cov X1X2: %.3f\\n',C(1,2),CHat(1,2))\n\ndisp('To plot the marginals and joint histogram, hit any key...')\npause\n\nfigure(f)\n\n% Again we compare the marginal distributions to the Poisson distribution\n% with the same mean and we find them matching very well.\n\nsubplot(2,2,2)\nh1 = joints2D{1,1}; % marginal of X_1\nh2 = joints2D{2,2}; % marginal of X_2\nplot(0:length(h1)-1,h1,'-r','markersize',5), hold on\nplot(0:length(h1),poisspdf(0:length(h1),mu(1)),'.r','markersize',5)\nplot(0:length(h2)-1,h2,'-g','markersize',5)\nplot(0:length(h1),poisspdf(0:length(h1),mu(2)),'.g','markersize',5)\nt = legend('X_1','X_1 Poisson','X_2','X_2 Poisson');\nset(t,'box','off')\naxis square\nxlabel('X'), ylabel('P(X)')\ntitle(sprintf('Step 5: Correlated Poisson, Negative Correlation\\nMarginal Distributions with Poisson\\n distribution with correct mean'))\n\n% Nevertheless, the samples have a different structure as we can see from\n% the 2D joint histogram. This time, the two variables are negatively\n% correlated and when X_1 tends to take large values, X_2 tends to take low\n% ones. \n\nsubplot(2,2,4)\nhh = joints2D{2}; % joint histogram\nimagesc(hh)\naxis square\ntitle('')\nxlabel('X_1'), ylabel('X_2')\n\n\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/20591-sampling-from-multivariate-correlated-binary-and-poisson-random-variables/demo.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.944176857294597, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7967862276696893}}
{"text": "function mel = frq2mel(frq)\n%FRQ2ERB Convert Hertz to Mel frequency scale MEL=(FRQ)\n%\tmel = frq2mel(frq) converts a vector of frequencies (in Hz)\n%\tto the corresponding values on the Mel scale which corresponds\n%\tto the perceived pitch of a tone\n\n%\tThe relationship between mel and frq is given by:\n%\n%\tm = ln(1 + f/700) * 1000 / ln(1+1000/700)\n%\n% \tThis means that m(1000) = 1000\n%\n\nmel = sign(frq).*log(1+abs(frq)/700)*1127.01048;\nif ~nargout\n plot(frq,mel,'-x');\n xlabel(['Frequency (' xticksi 'Hz)']);\n ylabel(['Frequency (' yticksi 'Mel)']);\nend\n", "meta": {"author": "bastamon", "repo": "sound_signal_process-matlab-", "sha": "d621374ce1b3b2e3413e9ccc5ba9e6e925ea5f19", "save_path": "github-repos/MATLAB/bastamon-sound_signal_process-matlab-", "path": "github-repos/MATLAB/bastamon-sound_signal_process-matlab-/sound_signal_process-matlab--d621374ce1b3b2e3413e9ccc5ba9e6e925ea5f19/第11章 说话人识别/11.2 基于高斯混合模型(GMM)的说话人识别实验/frq2mel.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9441768557238084, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7967862226372291}}
{"text": "%{\nTest the trace-constrained least-squares problem with positive\nsemi-definite matrix variables\n\n minimize (1/2)*norm( A * X - b )^2 \n with the constraint that X is positive semi-definite ( X >= 0 )\nand optionally,\n the constraint trace(X) <= lambda\n\n%}\n\n% Try to load the problem from disk\nfileName = fullfile('reference_solutions','traceLS_problem2_noisy');\nif exist([fileName,'.mat'],'file')\n load(fileName);\n fprintf('Loaded problem from %s\\n', fileName );\nelse\n % Generate a new problem\n randn('state',sum('Trace')+5);\n rand('state',sum('Trace2')+5);\n \n N = 30; R = 2;\n \n df = R*N;\n oversample = 5;\n Left = randn(M,R);\n Right = Left;\n k = round(oversample*df); \n k = min( k, round(.8*N*N) );\n omega = randperm(N*N);\n omega = sort(omega(1:k)).';\n\n X_original = Left*Right'; % the \"original\" signal -- may not be optimal value\n b_original = X_original(omega); \n EPS = .001; % noise level\n noise = EPS * randn(k,1); % this destroys symmetry...\n b = b_original + noise;\n lambda = trace( X_original );\n objective = @(X) sum_square( X(omega) - b )/2;\n obj_original = objective(X_original);\n\n % get references via CVX\n cvx_begin\n cvx_precision best\n cvx_quiet true\n variable Xcvx(N,N)\n minimize objective(Xcvx)\n subject to\n Xcvx == semidefinite(N)\n cvx_end\n X_reference_noTraceConstraint = Xcvx; \n fprintf('Difference between convex solution (no trace constraint) and original signal: %.2e\\n', ...\n norm( Xcvx - X_original, 'fro' ) );\n \n cvx_begin\n cvx_precision best\n cvx_quiet true\n variable Xcvx(N,N)\n minimize objective(Xcvx)\n subject to\n Xcvx == semidefinite(N)\n trace(Xcvx) <= lambda\n cvx_end\n X_reference = Xcvx; % the trace norm minimizer \n obj_reference = objective(X_reference);\n fprintf('Difference between convex solution (with trace constraint) and original signal: %.2e\\n', ...\n norm( Xcvx - X_original, 'fro' ) );\n save(fileName,'X_original','X_reference','X_reference_noTraceConstraint',...\n 'omega','b','obj_original',...\n 'Left','EPS','b_original','R','obj_reference','lambda');\n fprintf('Saved data to file %s\\n', fileName);\n \nend\n\n[M,N] = size(X_reference);\nnorm_X_reference = norm(X_reference,'fro');\ner_reference = @(x) norm(x-X_reference,'fro')/norm_X_reference;\nnorm_X_reference2= norm(X_reference_noTraceConstraint,'fro');\ner_reference2 = @(x) norm(x-X_reference_noTraceConstraint,'fro')/norm_X_reference2;\nobjective = @(X) norm( X(omega) - b )^2/2;\n\n[omegaI,omegaJ] = ind2sub([M,N],omega);\nmat = @(x) reshape(x,M,N);\nvec = @(x) x(:);\n \nk = length(omega);\np = k/(M*N);\ndf = R*(M+N-R);\nfprintf('%d x %d rank %d matrix, observe %d = %.1f x df = %.1f%% entries\\n',...\n M,N,R,k,k/df,p*100);\nfprintf(' Trace norm solution and original matrix differ by %.2e\\n',...\n norm(X_reference-X_original,'fro')/norm_X_reference );\n%% Solve unconstrained version. No smoothing is necessary!\nopts = struct('maxIts',500);\nopts.errFcn{1} = @(f,x) er_reference2(x); % no trace constraint\nopts.errFcn{2} = @(f,x) sum( abs(eig(x)) > 1e-5 ); % numerical rank\n% tell it to use eigs instead of eig\n% opts.largescale = true; % ( but not recommended)\n\n% opts.symmetrize = true; % another option\n\nA = sparse( omegaI,omegaJ,b,N,N);\n[x,out] = solver_psdComp( A, opts );\n% Note: we do not expect to get zero error because there might be more\n% than one optimal solution for this problem (since there are not\n% so many constraints)\n% Check that we have a feasible solution\nfprintf('Objective is %.2e, min eigenvalue is %.2e\\n', objective(x),...\n min(eig(x)) );\n%% Solve trace constrained version. No smoothing necessary!\nopts = struct('maxIts',1500,'tol',1e-9);\nopts.errFcn{1} = @(f,x) er_reference(x); % no trace constraint\nopts.errFcn{2} = @(f,x) trace(x)-lambda;\nopts.errFcn{3} = @(f,x) sum( abs(eig(x)) > 1e-5 ); % numerical rank\n% we can also symmetrize \"omega\", but it makes little difference,\n% and gives slightly differen value than CVX, since CVX symmetrizes\n% differently:\n% opts.symmetrize = true;\nA = sparse( omegaI,omegaJ,b,N,N);\n[x,out] = solver_psdCompConstrainedTrace( A,lambda, opts );\n\nh=figure();\nsemilogy(out.err(:,1));\n\n% Check that we are within allowable bounds\nif out.err(end,1) < 1e-5\n disp('Everything is working');\nelse\n error('Failed the test');\nend\n\n%%\nclose(h)\n% TFOCS v1.3 by Stephen Becker, Emmanuel Candes, and Michael Grant.\n% Copyright 2013 California Institute of Technology and CVX Research.\n% See the file LICENSE for full license information.\n", "meta": {"author": "cvxr", "repo": "TFOCS", "sha": "164ada20401cd445930673e42bb3d2a5489f2030", "save_path": "github-repos/MATLAB/cvxr-TFOCS", "path": "github-repos/MATLAB/cvxr-TFOCS/TFOCS-164ada20401cd445930673e42bb3d2a5489f2030/examples/smallscale/test_psdCompletion.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896845856298, "lm_q2_score": 0.8652240964782012, "lm_q1q2_score": 0.7966894228920495}}
{"text": "function [theta, phi, r] = besa_transformCartesian2Spherical(X, Y, Z)\n% BESA_TRANSFORMCARTESIAN2SPHERICAL takes the cartesian coordinates X, Y \n% and Z of a 3D point and transforms them to the spherical coordinates \n% theta, phi and r. \n%\n% Parameters:\n% [X]\n% The X-coordinate of the current 3D point. It should point to the\n% right.\n% \n% [Y]\n% The Y-coordinate of the current 3D point. It should point\n% foreward.\n% \n% [Z]\n% The Z-coordinate of the current 3D point. It should point up.\n% \n% \n% Return:\n% [theta] \n% The azimuth angle with the vertical z-axis (0 degree) in the \n% x-z-plane, +90 degree lie in the positive x-axis.\n% \n% [phi] \n% The latitude angle in the horizontal x-y-plane \n% (counter-clockwise).\n%\n% [r] \n% The radius.\n\n% Copyright (C) 2015, BESA GmbH\n%\n% File name: besa_transformCartesian2Spherical.m\n%\n% Author: Todor Jordanov\n% Created: 2015-07-29\n\nSquareOfRadiusXY = X*X + Y*Y;\nRadiusXY = sqrt(SquareOfRadiusXY);\n\nif(RadiusXY == 0.0 && Z == 0.0)\n\n theta = 0.0;\n\nelse\n\n theta = atan2d(RadiusXY, Z);\n\nend\n\nif(X==0.0 && Y==0.0)\n\n phi = 0.0;\n\nelse\n\n phi = atan2d(Y, X);\n\nend\n\n% square of total radius\nSquareOfRadiusXY = SquareOfRadiusXY + Z*Z;\n\nr = sqrt(SquareOfRadiusXY);\n\n% set phi & theta to BESA ranges\nif(phi > 90.)\n\n phi = phi - 180.0;\n theta = -theta;\n\nelseif(phi < -90.) \n\n phi = phi+180.0;\n theta = -theta;\n\nend\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/besa/besa_transformCartesian2Spherical.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9585377308419051, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.796681971099136}}
{"text": "function volume = ellipsoid_volume ( m, a, v, r )\n\n%*****************************************************************************80\n%\n%% ELLIPSOID_VOLUME returns the volume of an ellipsoid.\n%\n% Discussion:\n%\n% The points X in the ellipsoid are described by an M by M\n% positive definite symmetric matrix A, an M-dimensional point V,\n% and a \"radius\" R, such that\n% (X-V)' * A * (X-V) <= R * R\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 13 August 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, the spatial dimension.\n%\n% Input, real A(M,M), the matrix that describes\n% the ellipsoid. A must be symmetric and positive definite.\n%\n% Input, real V(M), the \"center\" of the ellipse.\n% The value of V is not actually needed by this function.\n%\n% Input, real R, the \"radius\" of the ellipse.\n%\n% Output, real VOLUME, the volume of the ellipsoid.\n%\n [ u, info ] = r8po_fa ( m, a );\n \n sqrt_det = 1.0;\n for i = 1 : m\n sqrt_det = sqrt_det * u(i,i);\n end\n\n volume = r ^ m * hypersphere_unit_volume ( m ) / sqrt_det;\n\n return\nend", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/ellipsoid_monte_carlo/ellipsoid_volume.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377249197139, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7966819621677819}}
{"text": "function geometry_test0493 ( )\n\n%*****************************************************************************80\n%\n%% TEST0493 tests PARABOLA_EX, PARABOLA_EX2.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST0493\\n' );\n fprintf ( 1, ' PARABOLA_EX finds the extreme value of a parabola\\n' );\n fprintf ( 1, ' determined by three points.\\n' );\n fprintf ( 1, ' PARABOLA_EX2 finds the extreme value of a parabola\\n' );\n fprintf ( 1, ' determined by three points.\\n' );\n\n a = 2.0;\n b = -4.0;\n c = 10.0;\n\n x1 = 1.0;\n y1 = a * x1 * x1 + b * x1 + c;\n x2 = 2.0;\n y2 = a * x2 * x2 + b * x2 + c;\n x3 = 3.0;\n y3 = a * x3 * x3 + b * x3 + c;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Parabolic coefficients (A,B,C) = %f %f %f\\n', a, b, c );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' X, Y data\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' X1, Y1 = %f %f\\n', x1, y1 );\n fprintf ( 1, ' X2, Y2 = %f %f\\n', x2, y2 );\n fprintf ( 1, ' X3, Y3 = %f %f\\n', x3, y3 );\n\n a = 0.0;\n b = 0.0;\n c = 0.0;\n\n [ xmin, ymin, ierror ] = parabola_ex ( x1, y1, x2, y2, x3, y3 );\n\n if ( ierror == 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' PARABOLA_EX returns (XMIN,YMIN) = %f %f\\n', xmin, ymin );\n else\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' PARABOLA_EX returns error code %d\\n', ierror );\n end\n\n [ xmin, ymin, a, b, c, ierror ] = parabola_ex2 ( x1, y1, x2, y2, x3, y3 );\n\n if ( ierror == 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' PARABOLA_EX2 returns (XMIN,YMIN) = %f %f\\n', xmin, ymin );\n fprintf ( 1, ' and (A,B,C) = %f %f %f\\n', a, b, c );\n else\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' PARABOLA_EX2 returns error code %d\\n', ierror );\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/geometry_test0493.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8933094152856196, "lm_q1q2_score": 0.7966632086827478}}
{"text": "classdef RiceD\n%%RICED Functions to handle the Rice distribution.\n%Implemented methods are: mean, var, PDF, CDF, rand\n%\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nmethods(Static)\n \nfunction val=mean(s,sigma)\n%%MEAN Obtain the mean of the Rice distribution for given noncentrality\n% and scale parameters.\n%\n%INPUTS: s The noncentrality parameter of the distribution.\n% sigma The scale parameter of the distribution.\n%\n%OUTPUTS: val The mean of the Rice distribution.\n%\n%October 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n \n param=-s^2/(2*sigma^2);\n val=sigma*sqrt(pi/2)*exp(param/2)*((1-param)*besseli(0,-param/2)-param*besseli(1,-param/2));\nend\n\nfunction val=var(s,sigma)\n%%VAR Obtain the variance of the Rice distribution for given noncentrality\n% and scale parameters.\n%\n%INPUTS: s The noncentrality parameter of the distribution.\n% sigma The scale parameter of the distribution.\n%\n%OUTPUTS: val The variance of the Rice distribution.\n%\n%October 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n \n param=-s^2/(2*sigma^2);\n L=exp(param/2)*((1-param)*besseli(0,-param/2)-param*besseli(1,-param/2));\n val=2*sigma^2+s^2-pi*(sigma^2/2)*L^2;\nend \n \nfunction val=PDF(x,s,sigma)\n%%PDF Evaluate the Rice probability distribution function at one or more\n% desired points.\n%\n%INPUTS: x The point(s) at which the Rice PDF is to be evaluated. Note that\n% x>=0.\n% s The noncentrality parameter of the distribution.\n% sigma The scale parameter of the distribution.\n%\n%OUTPUTS: val The value(s) of the Rice PDF with parameters s and sigma\n% evaluated at x.\n%\n%The PDF of the Rice distribution is given in Chapter 2.1.4 of [1].\n%\n%REFERENCES:\n%[1] J. G. Proakis, Digital Communications. Ed. 4, Boston, MA:\n% McGraw Hill, 2001.\n%\n%September 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n %We are evaluating \n %val=(x/sigma^2).*exp(-(x.^2+s^2)/(2*sigma^2)).*besseli(0,x*s/sigma^2);\n %However, if x*s/sigma^2 is large, then this function could return\n %NaNs. large doesn't have to be all that large. For example, s=30,\n %sigma=1, x=100. means that ratio is 3000. Thus, we use besseli with\n %the third argument to get a scaled value, then take the logarithm, do\n %everything else in the logarithmic domain and take the exponent to\n %undo the logarithm.\n \n besselArg=x*s/sigma^2;\n val=exp(log(besseli(0,besselArg,1))+besselArg-(x.^2+s^2)/(2*sigma^2)+log(x/sigma^2));\nend\n\nfunction val=CDF(x,s,sigma)\n%%CDF Evaluate the cumulative distribution function of the Rice\n% distribution at desired points.\n%\n%INPUTS: x The point(s) at which the Rice CDF is to be evaluated. Note that\n% x>=0.\n% s The noncentrality parameter of the distribution.\n% sigma The scale parameter of the distribution.\n%\n%OUTPUTS: prob The value(s) of the CDF of the Rice distribution with\n% parameters k and theta evaluated at x.\n%\n%The CDF of the Rice distribution can be expressed in terms of Marcum's Q\n%function as shown in Chapter 2.1.4 of [1].\n%\n%REFERENCES:\n%[1] J. G. Proakis, Digital Communications. Ed. 4, Boston, MA:\n% McGraw Hill, 2001.\n%\n%February 2014 David F. Crouse, Naval Research Laboratory, Washington D.C.\n numPoints=length(x(:));\n val=zeros(size(x));\n \n for curPoint=1:numPoints\n val(curPoint)=1-MarcumQ(1,s/sigma,x(curPoint)/sigma);\n end\nend\n\n\nfunction vals=rand(N,s,sigma)\n%%RAND Generate Rice-distributed random variables with the given\n% parameters.\n%\n%INPUTS: N If N is a scalar, then rand returns an NXN matrix of random\n% variables. If N=[M,N1] is a two-element row vector, then rand\n% returns an MXN1 matrix of random variables.\n% s The noncentrality parameter of the distribution.\n% sigma The scale parameter of the distribution.\n%\n%OUTPUTS: vals A matrix whose dimensions are determined by N of the\n% generated Rice random variables.\n%\n%This generates Rice distributed random variables by transforming normally\n%distributed random variables using the identity given in Chapter 2.1.4 of\n%[1].\n%\n%REFERENCES:\n%[1] J. G. Proakis, Digital Communications. Ed. 4, Boston, MA:\n% McGraw Hill, 2001.\n%\n%September 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n if(isscalar(N))\n dims=[N, N];\n else\n dims=N;\n end\n\n m=s/sqrt(2);\n\n X=sigma*randn(dims)+m;\n Y=sigma*randn(dims)+m;\n\n vals=sqrt(X.^2+Y.^2);\nend\n \nend\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Statistics/Distributions/RiceD.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567176, "lm_q2_score": 0.8499711832583695, "lm_q1q2_score": 0.7966021668219303}}
{"text": "function p = gaussProb(X, mu, Sigma)\n% Multivariate Gaussian distribution, pdf\n% X(i,:) is i'th case\n% *** In the univariate case, Sigma is the variance, not the standard\n% deviation! ***\n\n% This file is from pmtk3.googlecode.com\n\n\nd = size(Sigma, 2);\nX = reshape(X, [], d); % make sure X is n-by-d and not d-by-n\nX = bsxfun(@minus, X, rowvec(mu));\nlogp = -0.5*sum((X/(Sigma)).*X, 2); \nlogZ = (d/2)*log(2*pi) + 0.5*logdet(Sigma);\nlogp = logp - logZ;\np = exp(logp); \n\nend\n", "meta": {"author": "emtiyaz", "repo": "vadam", "sha": "d8ea6bdc82ac8765b873578660e1d9ba95c701d4", "save_path": "github-repos/MATLAB/emtiyaz-vadam", "path": "github-repos/MATLAB/emtiyaz-vadam/vadam-d8ea6bdc82ac8765b873578660e1d9ba95c701d4/matlab/lib/utils/gaussProb.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541593883189, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.796585216523325}}
{"text": "function h = r8mat_house_form ( n, v )\n\n%*****************************************************************************80\n%\n%% R8MAT_HOUSE_FORM constructs a Householder matrix from its compact form.\n%\n% Discussion:\n%\n% H(v) = I - 2 * v * v' / ( v' * v )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 October 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n%\n% Input, real V(N), the vector defining the Householder matrix.\n%\n% Output, real H(N,N), the Householder matrix.\n%\n\n%\n% Compute the L2 norm of V.\n%\n beta = sum ( v(1:n).^2 );\n%\n% Form the matrix H.\n%\n h = r8mat_identity ( n );\n\n for i = 1 : n\n for j = 1 : n\n h(i,j) = h(i,j) - 2.0 * v(i) * v(j) / beta;\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/r8mat_house_form.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541610257063, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7965852142511203}}
{"text": "function [ X ] = LineFaceIntersection( faceX, faceN, lineX, lineD )\n%LINEFACEINTERSECTION Intersection of a plane and a line\n% faceX: a point on the plane\n% faceN: the normal direction of the plane\n% lineX: a point on the line\n% lineD: direction of the line\n%\n\n% A = dot(faceN,lineD,2)/lineD(1);\n% B = -dot(faceX,faceN,2) + (dot(lineX(2:3),faceN(2:3),2)) - lineX(1)/lineD(1)*(dot(lineD(2:3),faceN(2:3),2));\nA = sum(faceN.*lineD)/lineD(1);\nB = -sum(faceX.*faceN) + (sum(lineX(2:3).*faceN(2:3),2)) - lineX(1)/lineD(1)*(sum(lineD(2:3).*faceN(2:3),2));\n\nx = -B/A;\n\ny = (x-lineX(1))/lineD(1)*lineD(2) + lineX(2);\nz = (x-lineX(1))/lineD(1)*lineD(3) + lineX(3);\nX = [x y z];\nend\n\n", "meta": {"author": "zouchuhang", "repo": "LayoutNet", "sha": "95293bfb8ff787dd3b02c8a52a147a703024980f", "save_path": "github-repos/MATLAB/zouchuhang-LayoutNet", "path": "github-repos/MATLAB/zouchuhang-LayoutNet/LayoutNet-95293bfb8ff787dd3b02c8a52a147a703024980f/matlab/panoContext_code/BasicFuncPano/LineFaceIntersection.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517072737735, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.796570154960089}}
{"text": "function centroids = computeCentroids(X, idx, K)\n%COMPUTECENTROIDS returs the new centroids by computing the means of the \n%data points assigned to each centroid.\n% centroids = COMPUTECENTROIDS(X, idx, K) returns the new centroids by \n% computing the means of the data points assigned to each centroid. It is\n% given a dataset X where each row is a single data point, a vector\n% idx of centroid assignments (i.e. each entry in range [1..K]) for each\n% example, and K, the number of centroids. You should return a matrix\n% centroids, where each row of centroids is the mean of the data points\n% assigned to it.\n%\n\n% Useful variables\n[m n] = size(X);\n\n% You need to return the following variables correctly.\ncentroids = zeros(K, n);\n\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Go over every centroid and compute mean of all points that\n% belong to it. Concretely, the row vector centroids(i, :)\n% should contain the mean of the data points assigned to\n% centroid i.\n%\n% Note: You can use a for-loop over the centroids to compute this.\n%\n\nnumberOfElementsHavingCentroid_k = zeros(K,1);\nsumOfElementsHavingCentroid_k = zeros(K,n);\nfor i = 1:size(idx,1)\n\tz = idx(i);\n\tnumberOfElementsHavingCentroid_k(z) += 1;\n\tsumOfElementsHavingCentroid_k(z,:) += X(i,:);\nend\n\ncentroids = sumOfElementsHavingCentroid_k./numberOfElementsHavingCentroid_k;\n\n\n\n\n\n\n\n% =============================================================\n\n\nend\n\n", "meta": {"author": "AvaisP", "repo": "machine-learning-programming-assignments-coursera-andrew-ng", "sha": "45268fc67ee60f65c2e07dbc7a2ef7c45f0d4ecf", "save_path": "github-repos/MATLAB/AvaisP-machine-learning-programming-assignments-coursera-andrew-ng", "path": "github-repos/MATLAB/AvaisP-machine-learning-programming-assignments-coursera-andrew-ng/machine-learning-programming-assignments-coursera-andrew-ng-45268fc67ee60f65c2e07dbc7a2ef7c45f0d4ecf/machine-learning-ex7/ex7/computeCentroids.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.8962513731336202, "lm_q1q2_score": 0.7965512890521941}}
{"text": "function dist = shape_point_dist_2d ( center, p1, nside, p )\n\n%*****************************************************************************80\n%\n%% SHAPE_POINT_DIST_2D: distance ( regular shape, point ) in 2D.\n%\n% Discussion:\n%\n% The \"regular shape\" is assumed to be an equilateral and equiangular\n% polygon, such as the standard square, pentagon, hexagon, and so on.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 04 December 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real CENTER(2,1), the center of the shape.\n%\n% Input, real P1(2,1), the first vertex of the shape.\n%\n% Input, integer NSIDE, the number of sides in the shape.\n%\n% Input, real P(2,1), the point to be checked.\n%\n% Output, real DIST, the distance from the point to the shape.\n%\n\n%\n% Determine the angle subtended by a single side.\n%\n sector_angle = 360.0 / nside;\n%\n% How long is the half-diagonal?\n%\n radius = sqrt ( sum ( ( p1(1:2,1) - center(1:2,1) ).^2 ) );\n%\n% If the radius is zero, then the shape is a point and the computation is easy.\n%\n if ( radius == 0.0 )\n dist = sqrt ( sum ( ( p(1:2,1) - center(1:2,1) ).^2 ) );\n return;\n end\n%\n% If the test point is at the center, then the computation is easy.\n% The angle subtended by any side is ( 2 * PI / NSIDE ) and the\n% nearest distance is the midpoint of any such side.\n%\n if ( sqrt ( sum ( ( p1(1:2,1) - center(1:2,1) ).^2 ) ) == 0.0 )\n dist = radius * cos ( pi / nside );\n return\n end\n%\n% Determine the angle between the ray to the first corner,\n% and the ray to the test point.\n%\n angle = angle_deg_2d ( p1, center, p );\n%\n% Determine the sector of the point.\n%\n sector_index = floor ( angle / sector_angle ) + 1;\n%\n% Generate the two corner points that terminate the SECTOR-th side.\n%\n angle2 = ( sector_index - 1 ) * sector_angle;\n angle2 = degrees_to_radians ( angle2 );\n\n pa = vector_rotate_base_2d ( p1, center, angle2 );\n\n angle2 = ( sector_index ) * sector_angle;\n angle2 = degrees_to_radians ( angle2 );\n\n pb = vector_rotate_base_2d ( p1, center, angle2 );\n%\n% Determine the distance from the test point to the line segment that\n% is the SECTOR-th side.\n%\n dist = segment_point_dist_2d ( pa, pb, p );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/shape_point_dist_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.8705972751232809, "lm_q1q2_score": 0.7965102804446444}}
{"text": "function [ n_data, n, c ] = tau_values ( n_data )\n\n%*****************************************************************************80\n%\n%% TAU_VALUES returns some values of the Tau function.\n%\n% Discussion:\n%\n% TAU(N) is the number of divisors of N, including 1 and N.\n%\n% In Mathematica, the function can be evaluated by:\n%\n% DivisorSigma[1,n]\n%\n% First values:\n%\n% N TAU(N)\n%\n% 1 1\n% 2 2\n% 3 2\n% 4 3\n% 5 2\n% 6 4\n% 7 2\n% 8 4\n% 9 3\n% 10 4\n% 11 2\n% 12 6\n% 13 2\n% 14 4\n% 15 4\n% 16 5\n% 17 2\n% 18 6\n% 19 2\n% 20 6\n%\n% Formula:\n%\n% If the prime factorization of N is\n%\n% N = P1^E1 * P2^E2 * ... * PM^EM,\n%\n% then\n%\n% TAU(N) = ( E1 + 1 ) * ( E2 + 1 ) * ... * ( EM + 1 ).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Milton Abramowitz and Irene Stegun,\n% Handbook of Mathematical Functions,\n% US Department of Commerce, 1964.\n%\n% Stephen Wolfram,\n% The Mathematica Book,\n% Fourth Edition,\n% Wolfram Media / Cambridge University Press, 1999.\n%\n% Parameters:\n%\n% Input/output, integer N_DATA. The user sets N_DATA to 0 before the\n% first call. On each call, the routine increments N_DATA by 1, and\n% returns the corresponding data; when there is no more data, the\n% output value of N_DATA will be 0 again.\n%\n% Output, integer N, the argument of the Tau function.\n%\n% Output, integer C, the value of the Tau function.\n%\n n_max = 20;\n\n c_vec = [ ...\n 1, 2, 2, 3, 2, 4, 2, 4, 3, 4, ...\n 2, 12, 12, 4, 18, 24, 2, 8, 14, 28 ];\n\n n_vec = [ ...\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...\n 23, 72, 126, 226, 300, 480, 521, 610, 832, 960 ];\n\n if ( n_data < 0 )\n n_data = 0;\n end\n\n n_data = n_data + 1;\n\n if ( n_max < n_data )\n n_data = 0;\n n = 0;\n c = 0;\n else\n n = n_vec(n_data);\n c = c_vec(n_data);\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_values/tau_values.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8705972633721708, "lm_q1q2_score": 0.7965102676734738}}
{"text": "function x = hypersphere_to_cartesian ( m, n, c, r, theta )\n\n%*****************************************************************************80\n%\n%% HYPERSPHERE_TO_CARTESIAN: hypersphere to Cartesian coordinate transform.\n%\n% Discussion:\n%\n% We allow the trivial case M = 1; in that case alone, the value R\n% must be assumed to have a sign.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 04 May 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, the spatial dimension.\n% 1 <= M.\n%\n% Input, integer N, the number of points to transform.\n%\n% Input, real C(M,1), the center of the hypersphere.\n%\n% Input, real R(N,1), the radius of the points on the hypersphere.\n% Except for the trivial case M = 1, R is assumed nonnegative.\n%\n% Input, real THETA(M-1,N), the coordinate angles of the points,\n% measured in radians.\n%\n% Output, real X(M,N), the Cartesian coordinates of the points.\n%\n x = zeros ( m, n );\n%\n% Make R a row vector.\n%\n r = ( r(:) )';\n%\n% Handle special case of M = 1.\n%\n if ( m == 1 )\n x(1:1,1:n) = repmat ( c(1:1,1:1), 1, n ) ...\n + repmat ( r(1:1,1:n), 1, 1 );\n return\n end\n\n x(1:m,1:n) = repmat ( r(1:1,1:n), m, 1 );\n\n for i1 = 1 : m - 1\n x(i1,1:n) = x(i1,1:n) .* cos ( theta(i1,1:n) );\n for i2 = i1 + 1 : m\n x(i2,1:n) = x(i2,1:n) .* sin ( theta(i1,1:n) );\n end\n end\n%\n% Add the center.\n%\n x(1:m,1:n) = x(1:m,1:n) + repmat ( c(1:m,1:1), 1, n );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/hypersphere_surface/hypersphere_to_cartesian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009573133051, "lm_q2_score": 0.8705972600147105, "lm_q1q2_score": 0.796510266621799}}
{"text": "function dist = line_exp_point_dist_3d ( p1, p2, p )\n\n%*****************************************************************************80\n%\n%% LINE_EXP_POINT_DIST_3D: distance ( explicit line, point ) in 3D.\n%\n% Discussion:\n%\n% The explicit form of a line in 3D is:\n%\n% ( P1, P2 ) = ( (X1,Y1,Z1), (X2,Y2,Z2) ).\n%\n% Thanks to Francois Struempfer for pointing out a parenthesis mistake in the\n% computation of the Euclidean norm.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 June 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real P1(3,1), P2(3,1), two points on the line.\n%\n% Input, real P(3,1), the point whose distance from the line is\n% to be measured.\n%\n% Output, real DIST, the distance from the point to the line.\n%\n dim_num = 3;\n\n bot = sum ( ( p2(1:dim_num,1) - p1(1:dim_num,1) ).^2 );\n\n if ( bot == 0.0 )\n\n pn(1:dim_num,1) = p1(1:dim_num,1);\n%\n% (P-P1) dot (P2-P1) = Norm(P-P1) * Norm(P2-P1) * Cos(Theta).\n%\n% (P-P1) dot (P2-P1) / Norm(P-P1)**2 = normalized coordinate T\n% of the projection of (P-P1) onto (P2-P1).\n%\n else\n\n t = sum ( ( p(1:dim_num,1) - p1(1:dim_num,1) )' ...\n * ( p2(1:dim_num,1) - p1(1:dim_num,1) ) ) / bot;\n\n pn(1:dim_num,1) = p1(1:dim_num,1) + t * ( p2(1:dim_num,1) - p1(1:dim_num,1) );\n\n end\n%\n% Now compute the distance between the projection point and P.\n%\n dist = sqrt ( sum ( ( p(1:dim_num,1) - pn(1:dim_num,1) ).^2 ) );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/line_exp_point_dist_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995703, "lm_q2_score": 0.8670357563664174, "lm_q1q2_score": 0.7963552053471609}}
{"text": "% Exercise 4.57: Capacity of a communication channel \n% Boyd & Vandenberghe \"Convex Optimization\" \n% Joëlle Skaf - 04/24/08 \n%\n% We consider a discrete memoryless communication channel, with input \n% X(t) \\in {1,...,n}, and output Y(t) \\in {1,...,m}, for t = 1,2,... \n% The relation between the input and output is given statistically: \n% p_ij = Prob(Y(t)=i|X(t)=j), i=1,...,m, j=1,...,n\n% The matrix P is called the channel transition matrix.\n% The channel capacity C is given by \n% C = sup{ I(X;Y) | x >= 0, sum(x) = 1}, \n% I(X;Y) is the mutual information between X and Y, and it can be shown \n% that: I(X;Y) = c'*x - sum_{i=1}^m y_i*log_2(y_i)\n% where c_j = sum_{i=1}^m p_ij*log_2(p_ij), j=1,...,m\n\n% Input data \nrand('state', 0); \nn = 15;\nm = 10; \nP = rand(m,n); \nP = P./repmat(sum(P),m,1); \nc = sum(P.*log2(P))';\n\n% Channel capacity \ncvx_begin\n variable x(n) \n y = P*x; \n maximize (c'*x + sum(entr(y))/log(2))\n x >= 0;\n sum(x) == 1; \ncvx_end\nC = cvx_optval; \n\n% Results\ndisplay(['The channel capacity is: ' num2str(C) ' bits.'])\n\n", "meta": {"author": "cvxr", "repo": "CVX", "sha": "a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd", "save_path": "github-repos/MATLAB/cvxr-CVX", "path": "github-repos/MATLAB/cvxr-CVX/CVX-a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd/examples/cvxbook/Ch04_cvx_opt_probs/channel_capacity.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9740426397881662, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7963524010150839}}
{"text": "function [rmag, dec] = geodet4 (lat, alt)\n\n% geodetic to geocentric coordinates\n\n% input\n\n% lat = geodetic latitude (radians)\n% (+north, -south; -pi/2 <= lat <= +pi/2)\n% alt = geodetic altitude (kilometers)\n\n% output\n\n% rmag = geocentric position magnitude (kilometers)\n% dec = geocentric declination (radians)\n% (+north, -south; -pi/2 <= dec <= +pi/2)\n\n% global constants\n\n% req = equatorial radius (kilometers)\n% flat = flattening factor (non-dimensional)\n\n% Orbital Mechanics with Matlab\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nglobal req flat\n\n% \"normalize\" altitude\n\nhhat = alt / req;\n\nhp1 = hhat + 1;\n\n% calculate trig terms\n\ns2lat = sin(2 * lat);\n\nc2lat = cos(2 * lat);\n\ns4lat = sin(4 * lat);\n\nc4lat = cos(4 * lat);\n\n% geocentric distance (kilometers)\n\nrho = hp1 + (0.5 * (c2lat - 1)) * flat ...\n + ((1/(4 * hp1) + (1/16)) * (1 - c4lat)) * flat * flat;\n\nrmag = req * rho;\n\n% geocentric declination (radians)\n\ndec = lat + (-s2lat/hp1) * flat ...\n + (-s2lat/(2 * (hp1 * hp1)) + (1/(4 * hp1 * hp1) + 1/(4 * hp1))...\n * s4lat) * flat * flat;\n \n\n\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/39494-geodetic-and-geocentric-coordinates/geodet4.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.965899575269305, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.796347420346797}}
{"text": "function [theta, J_history] = gradientDescentMulti(X, y, theta, alpha, num_iters)\n%GRADIENTDESCENTMULTI Performs gradient descent to learn theta\n% theta = GRADIENTDESCENTMULTI(x, y, theta, alpha, num_iters) updates theta by\n% taking num_iters gradient steps with learning rate alpha\n\n% Initialize some useful values\nm = length(y); % number of training examples\nJ_history = zeros(num_iters, 1);\n\nfor iter = 1:num_iters\n\n % ====================== YOUR CODE HERE ======================\n % Instructions: Perform a single gradient step on the parameter vector\n % theta. \n %\n % Hint: While debugging, it can be useful to print out the values\n % of the cost function (computeCostMulti) and gradient here.\n %\n\n\n\n\n\n\n\n predictions = X * theta;\n updates = X' * (predictions - y);\n theta = theta - alpha * (1/m) * updates;\n\n\n\n % ============================================================\n\n % Save the cost J in every iteration \n J_history(iter) = computeCostMulti(X, y, theta);\n\nend\n\nend\n", "meta": {"author": "vugsus", "repo": "coursera-machine-learning", "sha": "4c2d45cb729355593509abcd41779d19de5a1970", "save_path": "github-repos/MATLAB/vugsus-coursera-machine-learning", "path": "github-repos/MATLAB/vugsus-coursera-machine-learning/coursera-machine-learning-4c2d45cb729355593509abcd41779d19de5a1970/mlclass-ex1/gradientDescentMulti.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7963337650496279}}
{"text": "function A = makejcf(n, e, m, X)\n%MAKEJCF A matrix with specified Jordan canonical form.\n% MAKEJCF(N, E, M) is a matrix having the Jordan canonical form\n% whose i'th Jordan block is of dimension M(i) with eigenvalue E(i),\n% and where N = SUM(M).\n% Defaults: E = 1:N, M = ONES(SIZE(E)) with M(1) so that SUM(M) = N.\n% The matrix is constructed by applying a random similarity\n% transformation to the Jordan form.\n% Alternatively, the matrix used in the similarity transformation\n% can be specified as a fifth parameter.\n% In particular, MAKEJCF(N, E, M, EYE(N)) returns the Jordan form\n% itself.\n% NB: The JCF is very sensitive to rounding errors.\n\nif nargin < 2, e = 1:n; end\nif nargin < 3, m = ones(size(e)); m(1) = m(1) + n - sum(m); end\n\nif length(e) ~= length(m)\n error('Parameters E and M must be of same dimension.')\nend\n\nif sum(m) ~= n, error('Block dimensions must add up to N.'), end\n\nA = zeros(n);\nj = 1;\nfor i=1:max(size(m))\n if m(i) > 1\n Jb = gallery('jordbloc',m(i),e(i));\n else\n Jb = e(i); % JORDBLOC fails in n = 1 case.\n end\n A(j:j+m(i)-1,j:j+m(i)-1) = Jb;\n j = j + m(i);\nend\n\nif nargin < 4\n X = randn(n);\nend\nA = X\\A*X;\n", "meta": {"author": "opencobra", "repo": "cobratoolbox", "sha": "e60274d127f65d518535fd0814d20c53dc530f73", "save_path": "github-repos/MATLAB/opencobra-cobratoolbox", "path": "github-repos/MATLAB/opencobra-cobratoolbox/cobratoolbox-e60274d127f65d518535fd0814d20c53dc530f73/external/base/utilities/matrixcomp/makejcf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7963097438914892}}
{"text": "function [ pp, normal, seed ] = plane_normal_uniform_nd ( dim_num, seed )\n\n%*****************************************************************************80\n%\n%% PLANE_NORMAL_UNIFORM_ND generates a random normal plane in ND.\n%\n% Discussion:\n%\n% The normal form of a plane is:\n%\n% PP is a point on the plane,\n% N is a normal vector to the plane.\n%\n% The point PP will be chosen at random inside the unit sphere.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 26 November 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the spatial dimension.\n%\n% Input, integer SEED, a seed for the random number generator.\n%\n% Output, integer SEED, a seed for the random number generator.\n%\n% Output, real PP(DIM_NUM), a point on the plane.\n%\n% Output, real NORMAL(DIM_NUM), the unit normal vector.\n%\n\n%\n% Pick PP as a random point inside the unit sphere in ND.\n%\n [ pp, seed ] = ball_unit_sample_nd ( dim_num, seed );\n%\n% Get values from a standard normal distribution.\n%\n [ normal, seed ] = r8vec_normal_01 ( dim_num, seed );\n%\n% Compute the length of the vector.\n%\n norm = sqrt ( sum ( normal(1:dim_num).^2 ) );\n%\n% Normalize the vector.\n%\n normal(1:dim_num) = normal(1:dim_num) / norm;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/plane_normal_uniform_nd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.7963097390632836}}
{"text": "function C=circulantMatrix(v,reverseDir)\n%%CIRCULANTMATRIX Create a circulant matrix where the first row is given by\n% v. A circulatn matrix is a matrix where each row going down\n% from the top rotates the elements of the previous row by 1.\n%\n%INPUTS: v A 1XN or NX1 vector containing the elemtns that go into the\n% first row.\n% reverseDir If true, this boolean parameter indicates that each subsequent\n% row should be left-shifted from the previous one. If this\n% parameter is omitted or an empty matrix is passed, then the\n% default is false.\n%\n%OUTPUTS: C The NXN circulant matrix whose first row is v.\n%\n%EXAMPLE:\n% CF=circulantMatrix(1:5,false)\n% CR=circulantMatrix(1:5,true)\n%The results are:\n%CF=[1,2,3,4,5;\n% 5,1,2,3,4;\n% 4,5,1,2,3;\n% 3,4,5,1,2;\n% 2,3,4,5,1];\n%CR=[1,2,3,4,5;\n% 2,3,4,5,1;\n% 3,4,5,1,2;\n% 4,5,1,2,3;\n% 5,1,2,3,4];\n%\n%October 2017 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n if(nargin<2||isempty(reverseDir))\n reverseDir=false;\n end\n\n N=length(v);\n v=v(:);\n x=[v(N:-1:1,1);flipud(v(2:end))];\n if(reverseDir)\n idx=bsxfun(@plus,mod(0:-1:-((N-1)),N)',(N:-1:1));\n else\n idx=bsxfun(@plus,(0:(N-1))',(N:-1:1));\n end\n \n C=x(idx);\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Basic_Matrix_Operations/circulantMatrix.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927012, "lm_q2_score": 0.8991213813246445, "lm_q1q2_score": 0.7962902049404429}}
{"text": "function [x,iflaw]=fmpar(N,p1,p2,p3)\n%FMPAR\tParabolic frequency modulated signal.\n%\t[X,IFLAW]=FMPAR(N,P1,P2,P3) generates a signal with\n%\tparabolic frequency modulation law.\n%\tX(T) = exp(j*2*pi(A0.T + A1/2.T^2 +A2/3.T^3)) \n%\n%\tN : the number of points in time\n%\tP1 : if NARGIN=2, P1 is a vector containing the three \n%\t coefficients [A0 A1 A2] of the polynomial instantaneous phase.\n%\t If NARGIN=4, P1 (as P2 and P3) is a time-frequency point of \n%\t the form [Ti Fi].\n%\t The coefficients (A0,A1,A2) are then deduced such that \n%\t the frequency modulation law fits these three points.\n%\tP2,P3 : same as P1 if NARGIN=4. (optional)\n%\tX : time row vector containing the modulated signal samples \n%\tIFLAW : instantaneous frequency law\n%\n%\tExamples : \n%\t [X,IFLAW]=fmpar(128,[1 0.4],[64 0.05],[128 0.4]);\n%\t subplot(211);plot(real(X));subplot(212);plot(IFLAW);\n%\t [X,IFLAW]=fmpar(128,[0.4 -0.0112 8.6806e-05]);\n%\t subplot(211);plot(real(X));subplot(212);plot(IFLAW);\n%\n%\tSee also FMCONST, FMHYP, FMLIN, FMSIN, FMODANY, FMPOWER.\n\n%\tP. Goncalves - October 1995, O. Lemoine - November 1995\n%\tCopyright (c) 1995 Rice University\n%\n% This program is free software; you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation; either version 2 of the License, or\n% (at your option) any later version.\n%\n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with this program; if not, write to the Free Software\n% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n\nif (nargin <= 1),\n error ( 'The number of parameters must be at least 2.' );\nelseif (N <= 0),\n error ('The signal length N must be strictly positive' );\nelseif nargin == 2 ;\n if length(p1) ~= 3\n error('Bad number of coefficients for P1');\n end\n a0 = p1(1) ; a1 = p1(2) ; a2 = p1(3) ;\nelseif nargin == 4 ;\n if (length(p1) ~= 2) |(length(p2) ~= 2) |(length(p3) ~= 2),\n error('Bad number of coefficients for P1, P2, P3');\n end\n if p1(1)>N | p1(1)<1,\n error ('P1(1) must be between 1 and N');\n elseif p2(1)>N | p2(1)<1,\n error ('P2(1) must be between 1 and N');\n elseif p3(1)>N | p3(1)<1,\n error ('P3(1) must be between 1 and N');\n elseif p1(2)<0,\n error ('P1(2) must be > 0');\n elseif p2(2)<0,\n error ('P2(2) must be > 0');\n elseif p3(2)<0,\n error ('P3(2) must be > 0');\n end\n Y = [p1(2) p2(2) p3(2)] ;\n X = [1 1 1;p1(1) p2(1) p3(1);p1(1)^2 p2(1)^2 p3(1)^2] ;\n coef = Y*inv(X) ; \n a0 = coef(1) ;\n a1 = coef(2) ;\n a2 = coef(3) ;\nend \n\nt=1:N;\n\nphi = 2*pi*(a0*t + a1/2*t.^2 + a2/3*t.^3) ;\niflaw = (a0 + a1*t + a2*t.^2).' ;\n\naliasing = find(iflaw<0 | iflaw>0.5) ;\nif isempty(aliasing) == 0\n disp(['!!! WARNING: signal is undersampled or has negative frequencies']) ;\nend\n\nx = exp(i*phi).';\n\n", "meta": {"author": "HeLiangHIT", "repo": "time_frequency", "sha": "09c2abe92355ff5cd867bdb169229682e9d7af7c", "save_path": "github-repos/MATLAB/HeLiangHIT-time_frequency", "path": "github-repos/MATLAB/HeLiangHIT-time_frequency/time_frequency-09c2abe92355ff5cd867bdb169229682e9d7af7c/tf_tool_box/tftb-0.2/mfiles/fmpar.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.796233768762171}}
{"text": "function [Xco Tau MT] = HC_CrankNicolson_h (Tin,TC,DE,HC,SE,DI,TS,TT,TBC,BC)\n%\n% DESCRIPTION:\n%\n% Crank-Nicolson numerical method for one dimensional unsteady state \n% heat transfer by conduction for homogenous material\n%\n% Basic PDE equation :\n%\n% dT d^2 T \n% ------ = TD ------ for 0 < x < DI and tau > 0 \n% dtau dx^2\n%\n% Principle of method :\n% ^\n% time |\n% | m-1 m m+1\n% | | | |\n% | ---o------x------o----- p+1\n% | dtau | | |\n% | ---o------o------o----- p \n% | dtau | | |\n% | ---+------+------+----- p-1\n% | | dx | dx |\n% |\n% +--------------------------------> \n% x \n% Space description:\n% DI\n% |<------------------------------>|\n% + + + + + . . . + + \n% 1 2 3 4 5 n-1 n\n% |<->|\n% SE\n%\n% Difference equation :\n%\n% T(m,p+1) - T(m,p) TD\n% ------------------- = -------( T(m-1,p+1) - 2.T(m,p+1) + T(m+1,p+1) )\n% dTau 2.dx.dx\n%\n% TD\n% + -------( T(m-1,p) - 2.T(m,p) + T(m+1,p) )\n% 2.dx.dx\n%\n% System of equations:\n%\n% (1+M).T(2,p+1) - M/2.T(3,p+1) = \n% = M/2.T(1,p) + (1-M).T(2,p) + M/2.T(3,p) + M/2.T(1,p+1)\n% . . . \n% for m <2,n-1> \n% - M/2.T(m-1,p+1) + (1+M).T(m,p+1)- M/2.T(m+1,p+1) = \n% = M/2.T(m-1,p) + (1-M).T(m,p) + M/2.T(m+1,p)\n% . . . \n% - M/2.T(n-2,p+1) + (1+M).T(n-1,p+1) = \n% = M/2.T(n-2,p) + (1-M).T(n-1,p) + M/2.T(n,p) + M/2.T(n,p+1)\n%\n% Matrix notation:\n%\n% A.T = b\n%\n% The elements of A are given by\n%\n% A(n-2,n-2) = 0 except for:\n% \n% A(1,1) = 1 + M;\n% A(1,2) = - M/2;\n% \n% A(m,m-1) = - M/2; \n% A(m,m) = 1 + M;\n% A(m,m+1) = - M/2; for m <2,n-3>\n% \n% A(n-2,n-3) = - M/2;\n% A(n-2,n-2) = 1 + M;\n%\n% and the elements of b are given by\n%\n% b(1) = M/2*Tin(1) + (1-M)*Tin(2) + M/2*Tin(3) + M/2*T(1); \n% \n% b(m) = M/2*Tin(m) + (1-M)*Tin(m+1) + M/2*Tin(m+2); for m <2,n-3>\n% \n% b(n-2) = M/2*Tin(n-2) + (1-M)*Tin(n-1) + M/2*Tin(n) + M/2*T(n); \n% \n% INPUTS:\n%\n% Tin - initialization temperatures [ K ] \n% TC - thermal conductivity [ W.m^-1.K^-1 ]\n% DE - density [ kg.m^-3 ]\n% HC - specific heat capacity [ kg.m^-3 ]\n% SE - size of element [ m ]\n% DI - distance [ m ]\n% TS - time step [ s ]\n% TT - total time of simulation [ s ]\n% TBC - type of boundary condition \n% (1 = first-type, 2 = second-type) [ - ]\n% BC - boundary condition \n% - first-type : BC(1) = T(1), BC(2) = T(n) [ K ]\n% - second-type: BC(1) = iQ(1), BC(2) = iQ(n) [ W.m^-2 ]\n% \n% OUTPUTS:\n%\n% Xco - vector of X coordinate [ m ]\n% Tau - vector of time [ s ]\n% MT - matrix of temperatures [ K ]\n% \n% AUXILIARY VARIABLE:\n%\n% r - time step number [ - ]\n% n - space point number [ - ] \n% TD - thermal diffusivity [ m^2.m^-1 ]\n% M - modul (Fourier number) [ - ]\n% A - matrix (n-2,n-2) [ - ]\n% b - vector (n-2) [ - ]\n%\n% Copyright (C) 2013, Technical University of Kosice\n% Author : Zecova Monika, Terpak Jan\n% Revision: 27.08.2013\n%\n r = round(TT/TS) + 1; \n n = round(DI/SE) + 1; \n \n Xco = 0.0:SE:DI; \n Tau = 0.0:TS:TT; \n MT = zeros(r,n);\n MT(1,:) = Tin;\n \n for j=2:r\n [T] = CrankNicolson (Tin,TC,DE,HC,SE,TS,TBC,BC);\n Tin = T; \n MT(j,:) = Tin; \n end\nend\nfunction [T] = CrankNicolson (Tin,TC,DE,HC,SE,TS,TBC,BC)\n\n TD = TC/(DE*HC);\n M = TD*TS/(SE*SE);\n\n T = Tin;\n \n if TBC == 1\n T(1) = BC(1);\n T(end) = BC(2);\n end\n \n if TBC == 2\n T(1) = T(2) - BC(1)*SE/TC;\n T(end) = T(end-1) - BC(2)*SE/TC;\n end \n \n k = length(Tin)-2;\n A = zeros(k,k);\n b = zeros(k,1);\n\n for i=1:k\n b(i) = M/2*Tin(i) + (1-M)*Tin(i+1) + M/2*Tin(i+2) ;\n end\n\n A(1,1) = (1+M);\n A(1,2) = - M/2;\n b(1) = b(1) + M/2*T(1);\n \n for i=2:k-1\n A(i,i-1) = - M/2;\n A(i,i) = 1 + M;\n A(i,i+1) = - M/2; \n end\n \n A(k,k-1) = - M/2;\n A(k,k) = 1 + M;\n b(k) = b(k) + M/2*T(end);\n\n x = A\\b;\n\n for i=2:length(Tin)-1\n T(i) = x(i-1);\n end \n\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/43146-heat-conduction-toolbox/HeatConductionToolbox/HC_CrankNicolson_h.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545289551958, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7961975645659497}}
{"text": "function [W phi]=train_rbf(X,Y,Xc,k_i,basisfunction)\n%trains a radial basis function\n%X is a N_p by N_dim matrix of training data\n%Y is a N_p by N_dim matrix of training data\n%Xc is a N_r by N_dim matrix of rbf centres\n%basisfunction may be 'gaussian' or 'polyharmonicspline'\n%k_i is a prescaler for 'gaussian' rbf and function order for\n%'polyharmonicspline'. See k_i(i)=0 for constant bias\n\n% Copyright Travis Wiens 2008\n%\n% This program is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n%\n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see .\n%\n% If you would like to request that this software be licensed under a less\n% restrictive license (i.e. for commercial closed-source use) please\n% contact Travis at travis.mlfx@nutaksas.com\n\nif nargin<4\n k_i=1;\nend\n\nif nargin<5\n basisfunction='gaussian';\nend\n\nN_r=size(Xc,1);%number of centres\n\nW=zeros(N_r,1);%weight matrix\n[z phi]=sim_rbf(Xc,X,W,k_i,basisfunction);%simulate rbf\nA=pinv(phi'*phi)*phi';%do inverse\nW=A*Y;%find weights", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/22174-rbf-acoustic-tomography/rbf_tomo_1_01/train_rbf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545333502202, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.7961975606508439}}
{"text": "function mc = moc ( a, b, n, f )\n\n%*****************************************************************************80\n%\n%% MOC estimates the modulus of continuity of a function over an interval.\n%\n% Discussion;\n%\n% The modulus of continuity function MC(T) for a function F(X) over an \n% interval [A,B] is defined as\n%\n% MC(T) = max | F(X+DX) - F(X) | for 0 <= DX <= T, and X and X+DX in [A,B].\n%\n% The modulus of continuity function is a monotone increasing function,\n% with MC(0) = 0.\n%\n% This function estimates the modulus of continuity based on a discrete\n% set of data at N equally spaced points in the interval [A,B]. \n% \n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 04 October 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A, B, the left and right endpoints of the interval.\n%\n% Input, integer N, the number of equally spaced sample points.\n%\n% Input, function F(x), a handle to the function.\n%\n% Output, real MC(N), the modulus of continuity function estimated at \n% 0, H or less, 2*H or less, ..., (N-1)*H or less.\n%\n\n% Compute the maximum difference with a separation DX of exactly 0*H, 1*H, 2*H, \n% ..., (N-1)*H.\n%\n mc1 = moc1 ( a, b, n, f );\n%\n% Compute the maximum difference with a separation DX of 0*H or less, \n% 1*H or less, 2*H or less, ..., (N-1)*H or less.\n%\n mc = zeros ( n, 1 );\n for i = 1 : n - 1\n mc(i+1) = max ( mc(i), mc1(i+1) );\n end\n\n return\nend\n ", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/moc_display/moc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418283357703, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7961834993301606}}
{"text": "function Nimg = Gscale(img,levels,gsize,sigma);\n%\n% Function to generate a gaussian-pyramid for the given input image\n%\n% Input: \n% img: input image-matrix grayscale\n% levels: number of levels of the pyramid \n% gsize: size of the gaussian kernel [w h] ([5 5] normally provides a smooth output)\n% sigma: sigma for gaussian kernel \n% Output:\n% Nimg: is a struct consisting of images from each level\n% : Nimg.img;\n% Usage:\n% im = imread('cameraman.tif');\n% Nimg = Gscale(im,3,[5 5],1.6);\n% i = 2; %select a level\n% figure; imshow(Nimg(i).img);\n%\n% Author: Pranam Janney Date: 24th July 2006 15:39\n% Email: pranamjanney@yahoo.com\n%\n% Revised Version 1.0.1 Date: 04th August 2006, 10:50\n%\n\n\n%guassian filter with a sigma=1.6\ng = fspecial('gaussian',gsize,sigma);\n\n%pyramid\nfor i = 1:levels\n if i == 1\n im = imfilter(img,g,'conv');\n Nimg(i).img = im;\n else \n %perform guassian filtering\n im = imfilter(Nimg(i-1).img,g,'conv');\n %perform downsampling (horizontal)\n im1 = im(:,1:2:size(Nimg(i-1).img,2));\n %vertical\n im2 = im1(1:2:size(Nimg(i-1).img,1),:);\n %store it in a struct format\n Nimg(i).img = im2;\n end\nend\n \n%End\n \n", "meta": {"author": "JzHuai0108", "repo": "ekfmonoslam", "sha": "443f6be744732453cdb90679abcaf5c962a6295e", "save_path": "github-repos/MATLAB/JzHuai0108-ekfmonoslam", "path": "github-repos/MATLAB/JzHuai0108-ekfmonoslam/ekfmonoslam-443f6be744732453cdb90679abcaf5c962a6295e/ekfmonoslam/imageproc/Gscale.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7961834901730489}}
{"text": "% Y = spharm_fast(theta,phi,l,m,p0)\n%\n% Orthonormal spherical harmonic function (Arfken, p. 681) for quantum\n% numbers l and m. Angles theta and phi should be given in radians.\n% p0 contains the values of the Legendre polynomial\n%\nfunction Y = spharm_fast(theta,phi,l,m,p0)\n\n% Copyright (c) 2016, Elekta Oy\n% ---------------------------------------\n% \n% Redistribution and use of the Software in source and binary forms, with or without \n% modification, are permitted for non-commercial use.\n% \n% The Software is provided \"as is\" without warranties of any kind, either express or\n% implied including, without limitation, warranties that the Software is free of defects,\n% merchantable, fit for a particular purpose. Developer/user agrees to bear the entire risk \n% in connection with its use and distribution of any and all parts of the Software under this license.\n% \n\n%p0 = legendre(l,cos(theta));\np = p0(2:end); % Values m > 1\n%\n% Arfken, p. 681. The Condon-Shortley phase is included in the\n% Legendre polynomials\n%\n%scale = sqrt((2*l+1)*prod(1:(l-m))/(4*pi*prod(1:(l+m)))); \nif m < 0\n Y = ((-1)^m)*sqrt((2*l+1)*prod(1:(l+m))/(4*pi*prod(1:(l-m))))*p(-m); \n %Y = scale*((-1)^m)*(prod(1:(l-abs(m)))/prod(1:(l+abs(m))))*p(-m);\nelseif m > 0\n Y = sqrt((2*l+1)*prod(1:(l-m))/(4*pi*prod(1:(l+m))))*p(m);\n %Y = scale*p(m);\nelse\n Y = sqrt((2*l+1)/(4*pi))*p0(1);\n %Y = scale*p0(1);\nend\nY = Y*complex(cos(m*phi),sin(m*phi));\n\n\n", "meta": {"author": "spm", "repo": "spm12", "sha": "3085dac00ac804adb190a7e82c6ef11866c8af02", "save_path": "github-repos/MATLAB/spm-spm12", "path": "github-repos/MATLAB/spm-spm12/spm12-3085dac00ac804adb190a7e82c6ef11866c8af02/toolbox/TSSS/private/spharm_fast.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475683211323, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7960863855056931}}
{"text": "function [mellin,beta]=fmt(X,fmin,fmax,N);\n%FMT Fast Fourier Mellin Transform.\n% [MELLIN,BETA]=FMT(X,FMIN,FMAX,N) computes the Fast Mellin\n% Transform of signal X.\n%\n% X : signal in time (Nx=length(X)).\n% FMIN,FMAX : respectively lower and upper frequency bounds of \n% the analyzed signal. These parameters fix the equivalent \n% frequency bandwidth (expressed in Hz). When unspecified, you\n% have to enter them at the command line from the plot of the\n% spectrum. FMIN and FMAX must be >0 and <=0.5. \n% N : number of analyzed voices. N must be even\n%\t\t\t\t (default : automatically determined).\n% MELLIN : the N-points Mellin transform of signal S.\n% BETA : the N-points Mellin variable.\n%\n% Examples : \n% sig=altes(128,0.05,0.45); \n%\t [MELLIN,BETA]=fmt(sig,0.05,0.5,128);\n% plot(BETA,real(MELLIN));\n%\n% See also IFMT, FFT, IFFT.\n\n% P. Goncalves 9-95 - O. Lemoine, June 1996. \n% Copyright (c) 1995 Rice University - CNRS (France) 1996.\n%\n% This program is free software; you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation; either version 2 of the License, or\n% (at your option) any later version.\n%\n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with this program; if not, write to the Free Software\n% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n\nif (nargin == 0),\n error('At least one parameter required');\nend;\n\n[xrow,xcol] = size(X);\n\nif (nargin==2),\n disp('FMIN will not be taken into account. Determine it with FMAX');\n disp(' from the following plot of the spectrum.'); \nelseif nargin==3,\n N=[];\nelseif (nargin==4 & rem(N,2)~=0),\n error('N must be even');\nend;\nif (xcol==0)|(xcol>2),\n error('X must have one or two columns');\nend\n\nMt = length(X); \nZ = hilbert(real(X));\nM = (Mt+rem(Mt,2))/2;\n\nif nargin<=2, % fmin,fmax,N unspecified\n STF = fft(fftshift(X)); Nstf=length(STF);\n sp = (abs(STF(1:Nstf/2))).^2; Maxsp=max(sp);\n f = linspace(0,0.5,Nstf/2+1) ; f = f(1:Nstf/2);\n plot(f,sp) ; grid;\n xlabel('Normalized frequency');\n title('Analyzed signal energy spectrum');\n indmin=min(find(sp>Maxsp/1000));\n indmax=max(find(sp>Maxsp/1000));\n fmindflt=max([0.001 0.05*fix(f(indmin)/0.05)]);\n fmaxdflt=0.05*ceil(f(indmax)/0.05);\n txtmin=['Lower frequency bound [',num2str(fmindflt),'] : '];\n txtmax=['Upper frequency bound [',num2str(fmaxdflt),'] : '];\n fmin = input(txtmin); fmax = input(txtmax);\n if fmin==[], fmin=fmindflt; end\n if fmax==[], fmax=fmaxdflt; end\nend\n\nif fmin >= fmax\n error('FMAX must be greater or equal to FMIN');\nelseif fmin<=0.0 | fmin>0.5,\n error('FMIN must be > 0 and <= 0.5');\nelseif fmax<=0.0 | fmax>0.5,\n error('FMAX must be > 0 and <= 0.5');\nend\n\nB = fmax-fmin; \t\t% Bandwidth of the signal X\nR = B/((fmin+fmax)/2);\t\t% Relative bandwidth of X\n\nNq= ceil((B*Mt*(1+2/R)*log((1+R/2)/(1-R/2)))/2);\nNmin = Nq-rem(Nq,2);\nNdflt = 2^nextpow2(Nmin);\nif nargin<=2,\n Ntxt=['Number of frequency samples (>=',num2str(Nmin),') [',num2str(Ndflt),'] : '];\n N = input(Ntxt);\nend\n\nif N~=[],\n if (N= ',num2str(Nmin)];\n disp(dispstr);\n end\nelse\n N=Ndflt; \nend\n\n\n% Geometric sampling of the analyzed spectrum\nNo2 = N/2;\nk = (1:No2);\nq = (fmax/fmin)^(1/(No2-1));\nt = (1:Mt)-M-1;\ngeo_f = fmin*(exp((k-1).*log(q)));\ntfmatx = zeros(Mt,N);\ntfmatx = exp(-2*j*pi*t'*geo_f);\nZS = Z.'*tfmatx; \nZS(No2+1:N) = zeros(1,N-No2);\n\n\n% Mellin transform computation of the analyzed signal\np = 0:(N-1);\nL = log(fmin)/log(q);\nmellin = N*log(q)*fftshift(ifft(ZS)).*exp(j*2*pi*L*(p/N-1/2));\nbeta = (p/N-1/2)./log(q);\n\n\n% Normalization\nSP = fft(hilbert(real(X))); \nindmin = 1+round(fmin*(xrow-2));\nindmax = 1+round(fmax*(xrow-2));\nSPana = SP(indmin:indmax);\nnu = (indmin:indmax)'/N; \nSPp = SPana./nu;\nNormsig = sqrt(SPp'*SPana);\n\nmellin = mellin*Normsig/norm(mellin);\n", "meta": {"author": "HeLiangHIT", "repo": "time_frequency", "sha": "09c2abe92355ff5cd867bdb169229682e9d7af7c", "save_path": "github-repos/MATLAB/HeLiangHIT-time_frequency", "path": "github-repos/MATLAB/HeLiangHIT-time_frequency/time_frequency-09c2abe92355ff5cd867bdb169229682e9d7af7c/tf_tool_box/tftb-0.2/mfiles/fmt.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678381, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.7960605766726502}}
{"text": "clear\n\n% problem specification\nm = 400; n = 500; r = 10;\nt = 1; esr = ceil(t*r); \nfprintf('[m n r esr] = [%i, %i, %i, %i]\\n',m,n,r,esr);\n\n% data\n% Xo = rand(m,r); Yo = rand(r,n);\nXo = abs(randn(m,r)); Yo = abs(randn(r,n));\n\nd = ones(r,1).*(1:r)';\nM = Xo*spdiags(d,0,r,r)*Yo;\n\n% set solver options\nopts.tol = 1e-5;\nopts.maxit = 500;\nopts.print = 1;\n\n% call solver\n\nsr = 0.5;\nOmega = randsample(m*n, sr*m*n);\nA = M(Omega);\n\n%exact rank-estimate case\nt0 = tic;\n[X,Y,Out] = mc_nmf(A,Omega,esr,m,n,opts);\ntime = toc(t0);\nrelerr = norm(X*Y-M,'fro')/norm(M,'fro');\nfprintf('RelErr = %5.2e, %4.2e Sec.\\n',relerr,time);\n%%\n[numr,numc] = size(M);\nI = randi([0 1],numr,numc);\nOmega = find(I);\nA = M(Omega);\n\n%%\nsubplot(1,2,1),imagesc(M);\nsubplot(1,2,2),imagesc(X*Y);\n%%\n\n%over-estimate case\nesr = ceil(1.5*r);\nt0 = tic;\nfprintf('[m n r esr] = [%i, %i, %i, %i]\\n',m,n,r,esr);\n[X,Y,Out] = mc_nmf(A,Omega,esr,m,n,opts);\ntime = toc(t0);\nrelerr = norm(X*Y-M,'fro')/norm(M,'fro');\nfprintf('RelErr = %5.2e, %4.2e Sec.\\n',relerr,time);", "meta": {"author": "andrewssobral", "repo": "lrslibrary", "sha": "06d457349cb5f1fc56a583cd61af9f1d5150e3a1", "save_path": "github-repos/MATLAB/andrewssobral-lrslibrary", "path": "github-repos/MATLAB/andrewssobral-lrslibrary/lrslibrary-06d457349cb5f1fc56a583cd61af9f1d5150e3a1/algorithms/mc/MC-NMF/quicktest.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.796060566734825}}
{"text": "function value = cube_monomial ( a, b, expon )\n\n%*****************************************************************************80\n%\n%% CUBE_MONOMIAL integrates a monomial over a cube in 3D.\n%\n% Discussion:\n%\n% This routine integrates a monomial of the form\n%\n% product ( 1 <= dim <= 3 ) x(dim)^expon(dim)\n%\n% The combination 0^0 should be treated as 1.\n%\n% The integration region is:\n% A(1) <= X <= B(1)\n% A(2) <= Y <= B(2)\n% A(3) <= Z <= B(3)\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 September 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A(3), B(3), the lower and upper limits.\n%\n% Input, integer EXPON(3), the exponents.\n%\n% Output, real VALUE, the integral of the monomial.\n%\n for i = 1 : 3\n\n if ( expon(i) == -1 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'CUBE_MONOMIAL - Fatal error!\\n' );\n fprintf ( 1, ' Exponent of -1 encountered.\\n' );\n error ( 'CUBE_MONOMIAL - Fatal error!' );\n end\n\n end\n\n value = 1.0;\n\n for i = 1 : 3\n\n value = value * ( b(i) ^ ( expon(i) + 1 ) - a(i) ^ ( expon(i) + 1 ) ) ...\n / ( expon(i) + 1 );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/cube_felippa_rule/cube_monomial.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.8824278633625322, "lm_q1q2_score": 0.7958799355124515}}
{"text": "#!/usr/bin/env octave\n%% Machine Learning Online Class - Exercise 1: Linear Regression\n\n% Instructions\n% ------------\n% \n% This file contains code that helps you get started on the\n% linear exercise. You will need to complete the following functions \n% in this exericse:\n%\n% warmUpExercise.m\n% plotData.m\n% gradientDescent.m\n% computeCost.m\n% gradientDescentMulti.m\n% computeCostMulti.m\n% featureNormalize.m\n% normalEqn.m\n%\n% For this exercise, you will not need to change any code in this file,\n% or any other files other than those mentioned above.\n%\n% x refers to the population size in 10,000s\n% y refers to the profit in $10,000s\n%\n\n%% Initialization\nclear all; close all; clc\n\n%% ==================== Part 1: Basic Function ====================\n% Complete warmUpExercise.m \nfprintf('Running warmUpExercise ... \\n');\nfprintf('5x5 Identity Matrix: \\n');\nwarmUpExercise()\n\nfprintf('Program paused. Press enter to continue.\\n');\npause;\n\n\n%% ======================= Part 2: Plotting =======================\nfprintf('Plotting Data ...\\n')\ndata = csvread('ex1data1.txt');\nX = data(:, 1); y = data(:, 2);\nm = length(y); % number of training examples\n\n% Plot Data\n% Note: You have to complete the code in plotData.m\nplotData(X, y);\n\nfprintf('Program paused. Press enter to continue.\\n');\npause;\n\n%% =================== Part 3: Gradient descent ===================\nfprintf('Running Gradient Descent ...\\n')\n\nX = [ones(m, 1), data(:,1)]; % Add a column of ones to x\ntheta = zeros(2, 1); % initialize fitting parameters\n\n% Some gradient descent settings\niterations = 1500;\nalpha = 0.01;\n\n% compute and display initial cost\ncomputeCost(X, y, theta)\n\n% run gradient descent\ntheta = gradientDescent(X, y, theta, alpha, iterations);\n\n% print theta to screen\nfprintf('Theta found by gradient descent: ');\nfprintf('%f %f \\n', theta(1), theta(2));\n\n% Plot the linear fit\nhold on; % keep previous plot visible\nplot(X(:,2), X*theta, '-')\nlegend('Training data', 'Linear regression')\nhold off % don't overlay any more plots on this figure\n\n% Predict values for population sizes of 35,000 and 70,000\npredict1 = [1, 3.5] *theta;\nfprintf('For population = 35,000, we predict a profit of %f\\n',...\n predict1*10000);\npredict2 = [1, 7] * theta;\nfprintf('For population = 70,000, we predict a profit of %f\\n',...\n predict2*10000);\n\nfprintf('Program paused. Press enter to continue.\\n');\npause;\n\n%% ============= Part 4: Visualizing J(theta_0, theta_1) =============\nfprintf('Visualizing J(theta_0, theta_1) ...\\n')\n\n% Grid over which we will calculate J\ntheta0_vals = linspace(-10, 10, 100);\ntheta1_vals = linspace(-1, 4, 100);\n\n% initialize J_vals to a matrix of 0's\nJ_vals = zeros(length(theta0_vals), length(theta1_vals));\n\n% Fill out J_vals\nfor i = 1:length(theta0_vals)\n for j = 1:length(theta1_vals)\n\t t = [theta0_vals(i); theta1_vals(j)]; \n\t J_vals(i,j) = computeCost(X, y, t);\n end\nend\n\n\n% Because of the way meshgrids work in the surf command, we need to \n% transpose J_vals before calling surf, or else the axes will be flipped\nJ_vals = J_vals';\n% Surface plot\nfigure;\nsurf(theta0_vals, theta1_vals, J_vals)\nxlabel('\\theta_0'); ylabel('\\theta_1');\n\n% Contour plot\nfigure;\n% Plot J_vals as 15 contours spaced logarithmically between 0.01 and 100\ncontour(theta0_vals, theta1_vals, J_vals, logspace(-2, 3, 20))\nxlabel('\\theta_0'); ylabel('\\theta_1');\nhold on;\nplot(theta(1), theta(2), 'rx', 'MarkerSize', 10, 'LineWidth', 2);\n\nfprintf('Program paused. Press enter to continue.\\n');\npause;\n", "meta": {"author": "SaveTheRbtz", "repo": "ml-class", "sha": "74ce689e21e9f3ca184e60313351b31112e5dd56", "save_path": "github-repos/MATLAB/SaveTheRbtz-ml-class", "path": "github-repos/MATLAB/SaveTheRbtz-ml-class/ml-class-74ce689e21e9f3ca184e60313351b31112e5dd56/ex1/ex1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384593, "lm_q2_score": 0.8824278540866548, "lm_q1q2_score": 0.7958799341253966}}
{"text": "function [total_error, max_error] = eq_area_error(dim,N)\n%EQ_AREA_ERROR Total area error and max area error per region of an EQ partition\n%\n%Syntax\n% [total_error, max_error] = eq_area_error(dim,N)\n%\n%Description\n% [TOTAL_ERROR, MAX_ERROR] = EQ_AREA_ERROR(dim,N) does the following:\n% 1) uses the recursive zonal equal area sphere partitioning algorithm to \n% partition the unit sphere S^dim into N regions,\n% 2) sets TOTAL_ERROR to be the absolute difference between the total area of\n% all regions of the partition, and the area of S^dim, and\n% 3) sets MAX_ERROR to be the maximum absolute difference between the area of \n% any region of the partition, and the ideal area of a region as given by\n% AREA_OF_IDEAL_REGION(dim,N), which is 1/N times the area of S^dim.\n%\n% The argument dim must be a positive integer.\n% The argument N must be a positive integer or an array of positive integers. \n% The results TOTAL_ERROR and MAX_ERROR will be arrays of the same size as N.\n%\n%Examples\n% > [total_error, max_error] = eq_area_error(2,10)\n% total_error =\n% 1.7764e-15\n% \n% max_error =\n% 4.4409e-16\n% \n% > [total_error, max_error] = eq_area_error(3,1:6)\n% total_error =\n% 1.0e-12 *\n% 0.0036 0.0036 0.1847 0.0142 0.0142 0.2132\n% \n% max_error =\n% 1.0e-12 *\n% 0.0036 0.0018 0.1954 0.0284 0.0440 0.0777\n%\n%See also\n% EQ_REGIONS, AREA_OF_SPHERE, AREA_OF_IDEAL_REGION\n\n% Copyright 2004-2005 Paul Leopardi for the University of New South Wales.\n% $Revision 1.10 $ $Date 2005-06-01 $\n% Documentation files renamed\n% $Revision 1.00 $ $Date 2005-02-12 $\n%\n% For licensing, see COPYING.\n% For references, see AUTHORS.\n% For revision history, see CHANGELOG.\n\n%\n% Check number of arguments\n%\nerror(nargchk(2,2,nargin));\nerror(nargoutchk(2,2,nargout));\n\n%\n% Flatten N into a row vector.\n%\nshape = size(N);\nn_partitions = prod(shape);\nN = reshape(N,1,n_partitions);\n\ntotal_error = zeros(size(N));\nmax_error = zeros(size(N));\nsphere_area = area_of_sphere(dim);\n\nfor partition_n = 1:n_partitions\n n = N(partition_n);\n regions = eq_regions(dim,n);\n ideal_area = area_of_ideal_region(dim,n);\n total_area = 0;\n for region_n = 1:size(regions,3)\n area = area_of_region(regions(:,:,region_n));\n total_area = total_area + area;\n region_error = abs(area - ideal_area);\n if region_error > max_error(partition_n)\n max_error(partition_n) = region_error;\n end\n end\n total_error(partition_n) = abs(sphere_area - total_area);\nend\n%\n% Reshape output to same array size as original N.\n%\ntotal_error = reshape(total_error,shape);\nmax_error = reshape(max_error,shape);\n%\n% end function\n\nfunction area = area_of_region(region)\n%AREA_OF_REGION Area of given region\n%\n% area = area_of_region(region);\n\ndim = size(region,1);\ns_top = region(dim,1);\ns_bot = region(dim,2);\nif dim > 1\n area = area_of_collar(dim, s_top, s_bot)*area_of_region(region(1:dim-1,:))/area_of_sphere(dim-1);\nelse\n if s_bot == 0\n s_bot = 2*pi;\n end\n if s_top == s_bot\n s_bot = s_top + 2*pi;\n end\n area = s_bot - s_top;\nend\n%\n% end function\n", "meta": {"author": "epfl-lts2", "repo": "gspbox", "sha": "a7d9aac5e239f1bcb37a9bb09998cc161be2732f", "save_path": "github-repos/MATLAB/epfl-lts2-gspbox", "path": "github-repos/MATLAB/epfl-lts2-gspbox/gspbox-a7d9aac5e239f1bcb37a9bb09998cc161be2732f/3rdparty/eq_sphere_partitions/eq_test/eq_area_error.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.8824278556326343, "lm_q1q2_score": 0.7958799262143463}}
{"text": "function result = fit_maxwell_pdf( x,y,W,hAx )\n% fit_maxwell_pdf - Non Linear Least Squares fit of the maxwellian distribution.\n% given the samples of the histogram of the samples, finds the \n% distribution parameter that fits the histogram samples.\n%\n% fits data to the probability of the form: \n% p(r) = sqrt(2/pi)*(a^(-3/2))*(r^2)*exp(-(r^2)/(2*a))\n% with parameter: a\n%\n% format: result = fit_maxwell_pdf( x,y,W,hAx )\n%\n% input: y - vector, samples of the histogram to be fitted\n% x - vector, position of the samples of the histogram (i.e. y = f(x,a))\n% W - matrix or scalar, a square weighting matrix of the size NxN where\n% N = length(y), or 0 to indicate no weighting is needed.\n% hAx - handle of an axis, on which the fitted distribution is plotted\n% if h is given empty, a figure is created.\n%\n% output: result - structure with the fields\n% a - fitted parameter\n% VAR - variance of the estimation\n% type- weighted LS or not weighted LS\n% iter- number of iteration for the solution\n%\n\n%\n% Algorithm\n% ===========\n%\n% We use the WLS algorithm to estimate the PDF from the samples.%\n% The maxwell distribution is given by:\n%\n% p(x,a) = sqrt(2/pi)*(a^(-3/2))*(x.^2).*exp(-(x.^2)/(2*a))\n% = Const * (a^(-3/2)) .* exp(-(x.^2)/(2*a))\n%\n% note that X is known and therefore, considered a constant vector\n%\n% The non liner WLS estimator is given by:\n%\n% a(n+1) = a(n) + inv(H'*W*H)*(H') * (y-h) = a(n) + G * err\n% \n% where: h = p(x,a)\n% H = diff( p(x,a) ) with respect to \"a\"\n% W = weighting matrix of size NxN (N = length(y))\n% a = a single parameter to be estimated\n%\n% The error estimation is given by:\n%\n% VAR( a ) = G * VAR( err ) * (G')\n%\n% or when W=I and the noise is a gaussian noise \n%\n% VAR( a ) = inv( H' * H )\n%\n\n\nif (nargin<3)\n error( 'fit_maxwell_pdf - insufficient input arguments' );\nend\n\na = x(find(y==max(y)))^2; % initial guess\ny = y(:); % both should be column vectors !\nx = x(:);\nx2 = x.^2; % save computation time\nC = sqrt(2/pi)*x2; % a constant vector\nthresh = 0.995; % convergence threshold for the loop\nlast_cnt= inf;\niter = 0;\n\n% check weight matrix input\nif (size(W,1)==length(y)) & (size(W,2)==length(y))\n weights_flag = 1;\n type = 'WLS';\nelse\n weights_flag = 0;\n type = 'LS';\nend\n\n\n% Estimation\n% =============\nif (weights_flag)\n % loop for convergence (with weighting matrix)\n % =============================================\n while (1)\n iter = iter + 1;\n h = C*(a^(-1.5)).*exp(-x2/(2*a));\n H = h.*( x2/(2*a^2) - 3/(2*a) );\n HTW = H'*W;\n e = inv( HTW * H ) * HTW * (y-h);\n a = a + e;\n control = e*e;\n if ( control > (last_cnt * thresh) )\n break;\n else\n last_cnt = control;\n end\n end\n\n % summarize results\n h = C*(a^(-1.5)).*exp(-x2/(2*a));\n H = h.*( x2/(2*a^2) - 3/(2*a) );\n HTW = H'*W;\n G = inv( HTW * H ) * HTW;\n err = ( y - h );\n result.a = a;\n result.VAR = G * var( err ) * (G');\n result.RMS = sqrt( (err')*err/ (x(2)-x(1))^2 / (length(err)-1) );\n result.iter = iter;\n result.type = type;\nelse\n\n % loop for convergence (without a weighting matrix) - assume white noise\n % ========================================================================\n while (1)\n iter = iter + 1;\n h = C*(a^(-1.5)).*exp(-x2/(2*a));\n H = h.*( x2/(2*a^2) - 3/(2*a) );\n HT = H';\n control = inv( HT * H );\n a = a + control * HT * (y-h);\n if ( control>(last_cnt * thresh) )\n break;\n else\n last_cnt = control;\n end\n end\n \n\t% summarize results\n h = C*(a^(-1.5)).*exp(-x2/(2*a));\n\tH = h.*( x2/(2*a^2) - 3/(2*a) );\n err = ( y - h );\n result.a = a;\n result.VAR = inv( (H') * H );\n result.RMS = sqrt( (err')*err/ (x(2)-x(1))^2 / (length(err)-1) );\n result.iter = iter;\n result.type = type;\nend\n\n\n% plot distribution if asked for\n% ===============================\nif (nargin>3)\n if ishandle( hAx )\n plot_maxwell( x,result,hAx,2 );\n else\n figure;\n plot_maxwell( x,result,gca,2 );\n end\nend\n", "meta": {"author": "aludnam", "repo": "MATLAB", "sha": "020b5cb02cc843e09a0ed689589382f18cce5e6d", "save_path": "github-repos/MATLAB/aludnam-MATLAB", "path": "github-repos/MATLAB/aludnam-MATLAB/MATLAB-020b5cb02cc843e09a0ed689589382f18cce5e6d/FitFunc/fit_maxwell_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850057480346, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7958152706444713}}
{"text": "function [P] = JacobiP(x,alpha,beta,N);\n\n% function [P] = JacobiP(x,alpha,beta,N)\n% Purpose: Evaluate Jacobi Polynomial of type (alpha,beta) > -1\n% (alpha+beta <> -1) at points x for order N and returns P[1:length(xp))]\n% Note : They are normalized to be orthonormal.\n\n% Turn points into row if needed.\nxp = x; dims = size(xp);\nif (dims(2)==1) xp = xp'; end;\n\nPL = zeros(N+1,length(xp)); \n\n% Initial values P_0(x) and P_1(x)\ngamma0 = 2^(alpha+beta+1)/(alpha+beta+1)*gamma(alpha+1)*...\n gamma(beta+1)/gamma(alpha+beta+1);\nPL(1,:) = 1.0/sqrt(gamma0);\nif (N==0) P=PL'; return; end;\ngamma1 = (alpha+1)*(beta+1)/(alpha+beta+3)*gamma0;\nPL(2,:) = ((alpha+beta+2)*xp/2 + (alpha-beta)/2)/sqrt(gamma1);\nif (N==1) P=PL(N+1,:)'; return; end;\n\n% Repeat value in recurrence.\naold = 2/(2+alpha+beta)*sqrt((alpha+1)*(beta+1)/(alpha+beta+3));\n\n% Forward recurrence using the symmetry of the recurrence.\nfor i=1:N-1\n h1 = 2*i+alpha+beta;\n anew = 2/(h1+2)*sqrt( (i+1)*(i+1+alpha+beta)*(i+1+alpha)*...\n (i+1+beta)/(h1+1)/(h1+3));\n bnew = - (alpha^2-beta^2)/h1/(h1+2);\n PL(i+2,:) = 1/anew*( -aold*PL(i,:) + (xp-bnew).*PL(i+1,:));\n aold =anew;\nend;\n\nP = PL(N+1,:)';\nreturn", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/JSHesthaven&TWarburton/Codes1D/JacobiP.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7958152647711088}}
{"text": "function [varargout] = funname(varargin)\n\n% SOLID_ANGLE of a planar triangle as seen from the origin\n%\n% The solid angle W subtended by a surface S is defined as the surface\n% area W of a unit sphere covered by the surface's projection onto the\n% sphere. Solid angle is measured in steradians, and the solid angle\n% corresponding to all of space being subtended is 4*pi sterradians.\n%\n% Use:\n% [w] = solid_angle(v1, v2, v3)\n% or\n% [w] = solid_angle(pnt, tri)\n% where v1, v2 and v3 are the vertices of a single triangle in 3D or\n% pnt and tri contain a description of a triangular mesh (this will\n% compute the solid angle for each triangle)\n\n% Copyright (C) 2003-2009, Robert Oostenveld\n%\n% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip\n% for the documentation and details.\n%\n% FieldTrip is free software: you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation, either version 3 of the License, or\n% (at your option) any later version.\n%\n% FieldTrip is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You should have received a copy of the GNU General Public License\n% along with FieldTrip. If not, see .\n%\n% $Id: solid_angle.m 2885 2011-02-16 09:41:58Z roboos $\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% The first section contains the plain Matlab implementation. The mex file\n% is many times faster and this function is called so frequently (for\n% large meshes), that the mex file should be used in all practical cases.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% function [w] = solid_angle(r1, r2, r3);\n%\n% if nargin==2\n% % reassign the input arguments\n% pnt = r1;\n% tri = r2;\n% npnt = size(pnt,1);\n% ntri = size(tri,1);\n% w = zeros(ntri,1);\n% % compute solid angle for each triangle\n% for i=1:ntri\n% r1 = pnt(tri(i,1),:);\n% r2 = pnt(tri(i,2),:);\n% r3 = pnt(tri(i,3),:);\n% w(i) = solid_angle(r1, r2, r3);\n% end\n% return\n% elseif nargin==3\n% % compute the solid angle for this triangle\n% cp23_x = r2(2) * r3(3) - r2(3) * r3(2);\n% cp23_y = r2(3) * r3(1) - r2(1) * r3(3);\n% cp23_z = r2(1) * r3(2) - r2(2) * r3(1);\n% nom = cp23_x * r1(1) + cp23_y * r1(2) + cp23_z * r1(3);\n% n1 = sqrt (r1(1) * r1(1) + r1(2) * r1(2) + r1(3) * r1(3));\n% n2 = sqrt (r2(1) * r2(1) + r2(2) * r2(2) + r2(3) * r2(3));\n% n3 = sqrt (r3(1) * r3(1) + r3(2) * r3(2) + r3(3) * r3(3));\n% ip12 = r1(1) * r2(1) + r1(2) * r2(2) + r1(3) * r2(3);\n% ip23 = r2(1) * r3(1) + r2(2) * r3(2) + r2(3) * r3(3);\n% ip13 = r1(1) * r3(1) + r1(2) * r3(2) + r1(3) * r3(3);\n% den = n1 * n2 * n3 + ip12 * n3 + ip23 * n1 + ip13 * n2;\n% if (nom == 0)\n% if (den <= 0)\n% w = nan;\n% return\n% end\n% end\n% w = 2 * atan2 (nom, den);\n% return\n% else\n% error('invalid input');\n% end\n\n% compile the missing mex file on the fly\n% remember the original working directory\npwdir = pwd;\n\n% determine the name and full path of this function\nfunname = mfilename('fullpath');\nmexsrc = [funname '.c'];\n[mexdir, mexname] = fileparts(funname);\n\ntry\n % try to compile the mex file on the fly\n warning('trying to compile MEX file from %s', mexsrc);\n cd(mexdir);\n\n if ispc\n mex -I. -c geometry.c\n mex -I. -c solid_angle.c ; mex solid_angle.c solid_angle.obj geometry.obj\n else\n mex -I. -c geometry.c\n mex -I. -c solid_angle.c ; mex -o solid_angle solid_angle.o geometry.o\n end\n\n cd(pwdir);\n success = true;\n\ncatch\n % compilation failed\n disp(lasterr);\n error('could not locate MEX file for %s', mexname);\n cd(pwdir);\n success = false;\nend\n\nif success\n % execute the mex file that was juist created\n funname = mfilename;\n funhandle = str2func(funname);\n [varargout{1:nargout}] = funhandle(varargin{:});\nend\n\n", "meta": {"author": "PatternRecognition", "repo": "OpenBMI", "sha": "3c42e609d5b867a8e15c780df3f8b0a8b86edcb8", "save_path": "github-repos/MATLAB/PatternRecognition-OpenBMI", "path": "github-repos/MATLAB/PatternRecognition-OpenBMI/OpenBMI-3c42e609d5b867a8e15c780df3f8b0a8b86edcb8/PR_BCI_team/Team_EarEEG/ear-EEG connecting/external/eeglab_10_0_1_0x/external/fieldtrip_partial/inverse/private/solid_angle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7958152622848134}}
{"text": "function poly_cof = r8poly_basis ( ntab, xtab )\n\n%*****************************************************************************80\n%\n%% R8POLY_BASIS computes all Lagrange basis polynomial in standard form.\n%\n% Discussion:\n%\n% The I-th Lagrange basis polynomial for a set of NTAB X values XTAB,\n% L(I,NTAB,XTAB)(X) is a polynomial of order NTAB-1 which is zero at\n% XTAB(J) for J not equal to I, and 1 when J is equal to I.\n%\n% The Lagrange basis polynomials have the property that the interpolating\n% polynomial through a set of NTAB data points (XTAB,YTAB) may be\n% represented as\n%\n% P(X) = Sum ( 1 <= I <= N ) YTAB(I) * L(I,NTAB,XTAB)(X)\n%\n% Higher order interpolation at selected points may be accomplished\n% using repeated X values, and scaled derivative values.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NTAB, the number of data points XTAB.\n%\n% Input, real XTAB(NTAB), the X values upon which the\n% Lagrange basis polynomial is to be based.\n%\n% Output, real POLY_COF(NTAB,NTAB), the polynomial\n% coefficients for the I-th Lagrange basis polynomial are stored\n% in column I. POLY_COF(1,I) is the constant term, and POLY_COF(1,NTAB)\n% is the coefficient of X**(NTAB-1).\n%\n\n%\n% Initialize POLY_COF to the identity matrix.\n%\n poly_cof(1:ntab,1:ntab) = 0.0;\n for i = 1 : ntab\n poly_cof(i,i) = 1.0;\n end\n%\n% Compute the divided difference table for the IVAL-th Lagrange basis\n% polynomial.\n%\n for i = 1 : ntab\n poly_cof(1:ntab,i) = ( data_to_dif ( ntab, xtab, poly_cof(1:ntab,i) ) )';\n end\n%\n% Convert the divided difference table coefficients to standard polynomial\n% coefficients.\n%\n for i = 1 : ntab\n poly_cof(1:ntab,i) = ( dif_to_r8poly ( ntab, xtab, poly_cof(1:ntab,i) ) )';\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/divdif/r8poly_basis.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7958152607736757}}
{"text": "% \"Powel test function which has n decision variables, has no local optima.\n%has one global optimum. all decision variables are bounded in [-4\n% 5]. One global minimum at x=[3 -1 0, 1...,3 -1 0 1] with f(x)=0\n\nfunction sum=test10(x)\nsum=0;\n\nb=numel(x)/4;\n\nfor i=1:b\n sum=sum+(x(4*i-3)+10*x(4*i-2)).^2+5*(x(4*i-1)-x(4*i)).^2+(x(4*i-2)-x(4*i-1)).^4+10*(x(4*i-3)-x(4*i)).^4;\nend\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/43326-modified-harmony-search-optimisation-with-linearly-decreasing-par-and-exponentially-decreasing-bw/test10.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.84997116805678, "lm_q1q2_score": 0.7958152584585683}}
{"text": "function H_MMSE = MMSE_CE(Y,Xp,pilot_loc,Nfft,Nps,h,SNR)\n%function H_MMSE = MMSE_CE(Y,Xp,pilot_loc,Nfft,Nps,h,ts,SNR)\n% MMSE channel estimation function\n% Inputs:\n% Y = Frequency-domain received signal\n% Xp = Pilot signal\n% pilot_loc = Pilot location\n% Nfft = FFT size\n% Nps = Pilot spacing\n% h = Channel impulse response\n% ts = Sampling time\n% SNR = Signal-to-Noise Ratio[dB]\n% output:\n% H_MMSE = MMSE channel estimate\n\n%H = fft(h,N);\nsnr = 10^(SNR*0.1);\nNp=Nfft/Nps; k=1:Np; \nH_tilde = Y(1,pilot_loc(k))./Xp(k); % LS estimate\nk=0:length(h)-1; %k_ts = k*ts; \nhh = h*h'; \ntmp = h.*conj(h).*k; %tmp = h.*conj(h).*k_ts;\nr = sum(tmp)/hh; \nr2 = tmp*k.'/hh; %r2 = tmp*k_ts.'/hh;\ntau_rms = sqrt(r2-r^2); % rms delay\ndf = 1/Nfft; %1/(ts*Nfft);\nj2pi_tau_df = j*2*pi*tau_rms*df;\nK1 = repmat([0:Nfft-1].',1,Np); \nK2 = repmat([0:Np-1],Nfft,1);\nrf = 1./(1+j2pi_tau_df*(K1-K2*Nps));\nK3 = repmat([0:Np-1].',1,Np); \nK4 = repmat([0:Np-1],Np,1);\nrf2 = 1./(1+j2pi_tau_df*Nps*(K3-K4));\nRhp = rf;\nRpp = rf2 + eye(length(H_tilde),length(H_tilde))/snr;\nH_MMSE = transpose(Rhp*inv(Rpp)*H_tilde.'); % MMSE channel estimate", "meta": {"author": "LyricYang", "repo": "MIMO_OFDM", "sha": "df25e1837bc4019f2bbcd946bc49b0942827a847", "save_path": "github-repos/MATLAB/LyricYang-MIMO_OFDM", "path": "github-repos/MATLAB/LyricYang-MIMO_OFDM/MIMO_OFDM-df25e1837bc4019f2bbcd946bc49b0942827a847/第6章 信道估计/MMSE_CE.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778012346834, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.7956347873633547}}
{"text": "% X: data matrix, each row is one observation, each column is one feature\n% d: reduced dimension\n% type: type of kernel, can be 'simple', 'poly', or 'gaussian'\n% para (input): parameter for computing the 'poly' kernel, for 'simple'\n% and 'gaussian' it will be ignored\n% Y: dimensionanlity-reduced data\n% eigVector: eigen-vector, will later be used for pre-image\n% reconstruction\n% para (output): automatically selected Gaussian kernel parameter\n\n% Copyright by Quan Wang, 2011/05/10\n% Please cite: Quan Wang. Kernel Principal Component Analysis and its\n% Applications in Face Recognition and Active Shape Models.\n% arXiv:1207.3538 [cs.CV], 2012.\n\nfunction [Y, eigVector, para]=kPCA(X,d,type,para)\n\n%% check input\nif ( strcmp(type,'simple') || strcmp(type,'poly') || ...\n strcmp(type,'gaussian') ) == 0\n Y=[];\n eigVector=[];\n para=[];\n fprintf(['\\nError: Kernel type ' type ' is not supported. \\n']);\n return;\nend\n\n%% parameters\nN=size(X,1);\nif strcmp(type,'gaussian')\n DIST=zeros(N,N);\n for k=1:size(X,2)\n [a,b]=meshgrid(X(:,k));\n DIST=DIST+(a-b).^2;\n end\n DIST=DIST.^0.5;\n DIST=DIST+diag(ones(N,1)*inf);\n para=10*median(min(DIST));\nend\n\n%% kernel PCA\nK0=kernel(X,type,para);\noneN=ones(N,N)/N;\nK=K0-oneN*K0-K0*oneN+oneN*K0*oneN;\n\n%% eigenvalue analysis\n[V,D]=eig(K/N);\neigValue=diag(D);\n% eigValue=eigValue(1:min(size(X)));\n[eigValue,IX]=sort(eigValue,'descend');\neigVector=V(:,IX);\n\n%% normailization\nnorm_eigVector=sqrt(sum(eigVector.^2));\neigVector=eigVector./repmat(norm_eigVector,size(eigVector,1),1);\n\n%% dimensionality reduction\nY=K0*eigVector(:,1:d);\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/39715-kernel-pca-and-pre-image-reconstruction/kPCA_v2.0/code/kPCA.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.8479677622198947, "lm_q1q2_score": 0.7954989210706672}}
{"text": "function n = cfn_e_size_total ( m, ell_max )\n\n%*****************************************************************************80\n%\n%% CFN_E_SIZE_TOTAL: Closed Fully Nested, Exponential Growth.\n%\n% Discussion:\n%\n% This calculation assumes that an exponential growth rule is being used,\n% that is, that the 1D rules have orders 1, 3, 7, 15, 31, and so on.\n%\n% It counts the number of points in all the product rules that compose\n% the sparse grid, and it does not reduce the count in any way to account\n% for repeated points.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 25 May 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Fabio Nobile, Raul Tempone, Clayton Webster,\n% A Sparse Grid Stochastic Collocation Method for Partial Differential\n% Equations with Random Input Data,\n% SIAM Journal on Numerical Analysis,\n% Volume 46, Number 5, 2008, pages 2309-2345.\n%\n% Parameters:\n%\n% Input, integer M, the spatial dimension.\n%\n% Input, integer ELL_MAX, the sparse grid level.\n%\n% Output, integer N, the total number of points in the grids.\n%\n n = 0;\n\n lvec = zeros ( m, 1 );\n\n ell_min = max ( ell_max + 1 - m, 0 );\n\n for ell = ell_min : ell_max\n\n more = 0;\n h = 0;\n t = 0;\n\n while ( 1 )\n\n [ lvec, more, h, t ] = comp_next ( ell, m, lvec, more, h, t );\n\n nvec = cfn_e_nvec_from_lvec ( lvec );\n ell_num = prod ( nvec(1:m) );\n n = n + ell_num;\n\n if ( ~ more ) \n break\n end\n\n end\n end\n\n return\nend\n\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/sparse_count/cfn_e_size_total.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.7954626515783451}}
{"text": "function varargout = boundedCentroidalVoronoi2d(germs, box, varargin)\n%BOUNDEDCENTROIDALVORONOI2D Create a 2D Centroidal Voronoi Tesselation in a box.\n%\n% [N, E, F] = boundedCentroidalVoronoi2d(GERMS, BOX)\n% GERMS are N-by-2 point array, BOX is given as [xmin xmax ymin ymax].\n% Algorithm is an iteration of voronoi diagram computations, using at\n% each steps the centroids of previous diagram as germs for the new\n% diagram.\n%\n% [N, E, F] = boundedCentroidalVoronoi2d(GERMS, BOX, NITER)\n% Specifies the number of iterations. Default is 10.\n%\n% [N, E, F, G] = boundedCentroidalVoronoi2d(...)\n% also returns the positions of germs/centroids for each face. If the\n% number of iteration was sufficient, location of germs should correspond\n% to centroids of faces 'fc' computed using: \n% fc(i,:) = polygonCentroid(n(f{i}, :));\n%\n% Example\n% [n, e, f] = boundedCentroidalVoronoi2d(rand(20, 2)*100, [0 100 0 100]);\n% drawGraph(n, e, f);\n%\n% See also \n% graphs, boundedVoronoi2d, centroidalVoronoi2d, clipGraph\n%\n\n% ------\n% Author: David Legland\n% E-mail: david.legland@inrae.fr\n% Created: 2007-01-12\n% Copyright 2007-2022 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas\n\n% number of iteration\nnIter = 10;\nif ~isempty(varargin)\n nIter = varargin{1};\nend\n\n% limits and size of the box\nx0 = box(1); x1 = box(2);\ny0 = box(3); y1 = box(4);\ndx = x1 - x0; dy = y1 - y0;\n\n% far points to bound the voronoi diagram\nfarPoints = [...\n x1 + 10 * dx, y1 + 10 * dy;...\n x0 - 10 * dx, y1 + 10 * dy;...\n x0 - 10 * dx, y0 - 10 * dy;...\n x1 + 10 * dx, y0 - 10 * dy];\n\n% iterate bounded voronoi tesselation\nfor i = 1:nIter\n % generate Voronoi diagram, and clip with the box\n [n, e, f] = voronoi2d([germs ; farPoints]);\n [n, e, f] = clipGraph(n, e, f, box);\n \n % centroid of each face will be used as germs for next iteration\n for j = 1:length(f)\n face = n(f{j}, :);\n germs(j, 1:2) = polygonCentroid(face);\n end\nend\n\n% result is given in n, e, and f, eventually germs\nvarargout{1} = n;\nvarargout{2} = e;\nvarargout{3} = f;\nif nargout > 3\n varargout{4} = germs;\nend\n", "meta": {"author": "mattools", "repo": "matGeom", "sha": "1fd2c937064be1ee1f4fd09fbfdf96145ebe5271", "save_path": "github-repos/MATLAB/mattools-matGeom", "path": "github-repos/MATLAB/mattools-matGeom/matGeom-1fd2c937064be1ee1f4fd09fbfdf96145ebe5271/matGeom/graphs/boundedCentroidalVoronoi2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148512, "lm_q2_score": 0.870597270087091, "lm_q1q2_score": 0.7954442911194407}}
{"text": "function z = distSqr_fast(x,y,x2,y2) %x2 = sum(x.^2,1)'; %y2 = sum(y.^2,1);\n% function z = distSqr_fast(x,y,x2,y2)\n%\n% Return matrix of all-pairs squared distances between the vectors\n% in the columns of x and y.\n%\n% INPUTS\n% \tx \tdxn matrix of vectors\n% \ty \tdxm matrix of vectors\n%\n% OUTPUTS\n% \tz \tnxm matrix of squared distances\n%\n% This routine is faster when mn. In other words y should be\n% smaller than x.\n%\n% David Martin \n% March 2003\n\n% Based on dist2.m code,\n% Copyright (c) Christopher M Bishop, Ian T Nabney (1996, 1997)\n\nif ~exist('y','var')\n y = x;\nend\n\nif ~exist('x2','var')\n x2 = sum(x.^2,1)';\nend\n\nif ~exist('y2','var')\n y2 = sum(y.^2,1);\nend\n\nif size(x,1) ~= size(y,1), \n error('size(x,1)~=size(y,1)'); \nend\n\n[d,n] = size(x);\n[d,m] = size(y);\n\n%z = x'*y\n%z = repmat(x2,1,m) ...\n% + repmat(y2,n,1) ...\n% - 2*x'*y;\n%return\n\nz = x'*y;\n\nfor i = 1:m,\n z(:,i) = x2 + y2(i) - 2*z(:,i);\nend\n\n%z = zeros(n,m);\n%for i = 1:m,\n% z(:,i) = x2 + y2(i) - 2*x'*y(:,i);\n%end\n", "meta": {"author": "quantombone", "repo": "exemplarsvm", "sha": "54c07ec4faa96fb949991ebc512eaf7446e034f7", "save_path": "github-repos/MATLAB/quantombone-exemplarsvm", "path": "github-repos/MATLAB/quantombone-exemplarsvm/exemplarsvm-54c07ec4faa96fb949991ebc512eaf7446e034f7/util/distSqr_fast.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8705972600147106, "lm_q1q2_score": 0.7954442819165433}}
{"text": "function rotatedData = rotatePoints(alignmentVector, originalData)\n\n% rotatedData = rotatePoints(alignmentVector, originalData) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% \n% Rotate the 'originalData' in the form of Nx2 or Nx3 about the origin by aligning the x-axis with the alignment vector\n% \n% Rdata = rotatePoints([1,2,-1], [Xpts(:), Ypts(:), Zpts(:)]) - rotate the (X,Y,Z)pts in 3D with respect to the vector [1,2,-1]\n% \n% Rotating using spherical components can be done by first converting using [dX,dY,dZ] = cart2sph(theta, phi, rho); alignmentVector = [dX,dY,dZ];\n% \n% Example:\n% %% Rotate the point [3,4,-7] with respect to the following:\n% %%%% Original associated vector is always [1,0,0]\n% %%%% Calculate the appropriate rotation requested with respect to the x-axis. For example, if only a rotation about the z-axis is\n% %%%% sought, alignmentVector = [2,1,0] %% Note that the z-component is zero\n% rotData = rotatePoints(alignmentVector, [3,4,-7]);\n% \n% Author: Shawn Arseneau\n% Created: Feb.2, 2006\n% \n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n alignmentDim = numel(alignmentVector);\n DOF = size(originalData,2); %---- DOF = Degrees of Freedom (i.e. 2 for two dimensional and 3 for three dimensional data)\n \n if alignmentDim~=DOF \n error('Alignment vector does not agree with originalData dimensions'); \n end\n if DOF<2 || DOF>3 \n error('rotatePoints only does rotation in two or three dimensions'); \n end\n \n \n if DOF==2 % 2D rotation... \n [rad_theta, rho] = cart2pol(alignmentVector(1), alignmentVector(2)); \n deg_theta = -1 * rad_theta * (180/pi);\n ctheta = cosd(deg_theta); stheta = sind(deg_theta);\n \n Rmatrix = [ctheta, -1.*stheta;...\n stheta, ctheta];\n rotatedData = originalData*Rmatrix; \n \n else % 3D rotation... \n [rad_theta, rad_phi, rho] = cart2sph(alignmentVector(1), alignmentVector(2), alignmentVector(3));\n rad_theta = rad_theta * -1; \n deg_theta = rad_theta * (180/pi);\n deg_phi = rad_phi * (180/pi); \n ctheta = cosd(deg_theta); stheta = sind(deg_theta);\n Rz = [ctheta, -1.*stheta, 0;...\n stheta, ctheta, 0;...\n 0, 0, 1]; %% First rotate as per theta around the Z axis\n rotatedData = originalData*Rz;\n\n [rotX, rotY, rotZ] = sph2cart(-1* (rad_theta+(pi/2)), 0, 1); %% Second rotation corresponding to phi\n rotationAxis = [rotX, rotY, rotZ];\n u = rotationAxis(:)/norm(rotationAxis); %% Code extract from rotate.m from MATLAB\n cosPhi = cosd(deg_phi);\n sinPhi = sind(deg_phi);\n invCosPhi = 1 - cosPhi;\n x = u(1);\n y = u(2);\n z = u(3);\n Rmatrix = [cosPhi+x^2*invCosPhi x*y*invCosPhi-z*sinPhi x*z*invCosPhi+y*sinPhi; ...\n x*y*invCosPhi+z*sinPhi cosPhi+y^2*invCosPhi y*z*invCosPhi-x*sinPhi; ...\n x*z*invCosPhi-y*sinPhi y*z*invCosPhi+x*sinPhi cosPhi+z^2*invCosPhi]';\n\n rotatedData = rotatedData*Rmatrix; \n end\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/22158-plot-a-plane-or-line-in-3d/rotatePoints.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.853912760387131, "lm_q1q2_score": 0.795387725396091}}
{"text": "function [phi] = evalPhi( r );\n%\n% [phi] = evalPhi( r );\n%\n% Calculates phi( r ), phi the discrete delta function (without scaling)\n% \n% Returns:\n% phi = value of unscaled discrete delta function at each point, r\n%\n% Input:\n% r = the points to evaluate the discrete delta function at\n%\n% Note: \n% This code doesn't handle wrapping across periodic boundaries.\n%\n%\n% License: This code is free to use for any purposes, provided\n% any publications resulting from the use of this code\n% reference the original code/author.\n%\n% Author: Samuel Isaacson (isaacson@math.utah.edu)\n% Date: 11/2007\n%\n% Please notify the author of any bugs, and contribute any\n% modifications or bug fixes back to the original author.\n%\n% Disclaimer:\n% This code is provided as is. The author takes no responsibility \n% for its results or effects.\n\n\nphi = zeros(length(r), 1);\naR = abs( r );\nidx1 = find( aR < 1 );\nidx2 = find( aR >= 1 );\n\nrT = aR(idx1);\nphi(idx1) = 3 - 2*rT + sqrt( 1 + 4*rT - 4*rT.*rT );\n\nrT = aR(idx2);\nphi(idx2) = 5 - 2*rT - sqrt( -7 + 12*rT - 4*rT.*rT );\n\nphi = phi / 8;\n\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/IBM/evalPhi.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.931462503162843, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.7953877138099795}}
{"text": "function centroid = polyhedron_centroid_3d ( coord, maxorder, face_num, node, ...\n node_num, order )\n\n%*****************************************************************************80\n%\n%% POLYHEDRON_CENTROID_3D computes the centroid of a polyhedron in 3D.\n%\n% Discussion:\n%\n% The centroid can be computed as the volume-weighted average of\n% the centroids of the tetrahedra defined by choosing a point in\n% the interior of the polyhedron, and using as a base every triangle\n% created by triangulating the faces of the polyhedron.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 May 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real COORD(3,NODE_NUM), the vertices.\n% The vertices may be listed in any order.\n%\n% Input, integer MAXORDER, the maximum number of vertices that make\n% up a face of the polyhedron.\n%\n% Input, integer FACE_NUM, the number of faces of the polyhedron.\n%\n% Input, integer NODE(FACE_NUM,MAXORDER). Face I is defined by\n% the vertices NODE(I,1) through NODE(I,ORDER(I)). These vertices\n% are listed in neighboring order.\n%\n% Input, integer NODE_NUM, the number of points stored in COORD.\n%\n% Input, integer ORDER(FACE_NUM), the number of vertices making up\n% each face.\n%\n% Output, real CENTROID(3), the centroid of the polyhedron.\n%\n dim_num = 3;\n%\n% Compute a point in the interior.\n% We take the area-weighted centroid of each face.\n%\n point(1:dim_num) = 0.0;\n area = 0.0;\n\n for face = 1 : face_num\n\n vert_num = order(face);\n\n v(1:dim_num,1:vert_num) = coord(1:dim_num,node(face,1:vert_num));\n\n [ polygon_area, normal ] = polygon_area_3d ( vert_num, v );\n\n polygon_centroid(1:dim_num) = polygon_centroid_3d ( vert_num, v );\n\n point(1:dim_num) = point(1:dim_num) + polygon_area * polygon_centroid(1:dim_num);\n\n area = area + polygon_area;\n\n end\n\n point(1:dim_num) = point(1:dim_num) / area;\n%\n% Now triangulate each face.\n% For each triangle, consider the tetrahedron created by including POINT.\n%\n centroid(1:dim_num) = 0.0;\n volume = 0.0;\n\n for face = 1 : face_num\n\n n3 = node(face,order(face));\n\n for vert = 1 : order(face) - 2\n\n n1 = node(face,vert);\n n2 = node(face,vert+1);\n\n tetra(1:dim_num,1:4) = [ ...\n coord(1:dim_num,n1)'; coord(1:dim_num,n2)'; coord(1:dim_num,n3)'; point(1:dim_num) ]';\n\n tetra_volume = tetrahedron_volume_3d ( tetra );\n\n tetra_centroid(1:dim_num) = tetrahedron_centroid_3d ( tetra );\n\n centroid(1:dim_num) = centroid(1:dim_num) + tetra_volume * tetra_centroid(1:dim_num);\n\n volume = volume + tetra_volume;\n\n end\n end\n\n centroid(1:dim_num) = centroid(1:dim_num) / volume;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/polyhedron_centroid_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294587, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.7953768162713887}}
{"text": "function xyPoints=getEllipseHullPoints(z,A,gammaVal,numPoints,invertA)\n%%GETELLIPSHULLPOINTS Consider an ellipsoid in 3D (x,y,z) coordinates. For\n% every fixed z coordinate, if the x-y plane at the z coordinate\n% intersects the ellipsoid, it cuts an ellipse. For example, the\n% function projEllipse2ZPlane gets the parameters of the ellipse of\n% intersection. This function gets points marking the outer limits of\n% all of those ellipses in the x-y plane (the hull of the ellipses).\n%\n%INPUTS: z A 3XN vector corresponding to the centers of the N ellipses for\n% which points should be obtained.\n% A A 3X3XN set of N positive definite matrices that specify the\n% size and shape of the ellipsoids, where a point zp is on the ith\n% ellipsoid if\n% (zp-z(:,i))'*A(:,:,i)*(zp-z(:,i))=gammaVal (if invertA is true,\n% then replace A(:,:,i) with inv(A(:,:,i))).\n% gammaVal An optional parameter specifying the size of the ellipse/\n% ellipsoid. If omitted or an empty matrix is passed, then\n% gammaVal=18.8049 is used. This is approximately the value for a\n% 99.97% confidence region if A are inverse covariance matrices of\n% a Gaussian distribution. gammaVal must be positive gammaVal must\n% be positive.\n% numPoints An optional parameter specifying how many points should be\n% generated. The default if omitted or an empty matrix is passed\n% is 500.\n% invertA If this is true, then A is inverted before use. The default if\n% omitted or an empty matrix is passed is false.\n%\n%OUTPUTS: xyPoints A 2XnumPointsXN set of the points for each of the\n% ellipsoid projection hulls.\n%\n%The 3D ellipsoid (with the coordinate system shited to put the origin at\n%the center) is defined as x'*R*x=gammaVal. We can rewrite this as \n%[r*u,z]*R*[r*u;z]=gammaVal\n%where r is a positive scalar and u is a 2X1 unit vector. The matrix R can\n%be broken up accordingly as\n%R=[Rxy, rz;\n% rz', rzz];\n%We want the maximum extent of the ellipsoid in the x-y plane for each\n%direction (as specified by u). This will provide the hull of the ellipsoid\n%points. Thus, we perform the optimization:\n% maximize (over r,z) r^2\n% such that r^2*u'*Rxy*u+2*r*z*rz'*u+z^2*rzz=gammaVal\n%where the constraint is just from rewriting the expression for the\n%definition of an ellipsoid. Writing the Lagrangian, (with lambda as the\n%Lagrangian parameter) taking derivatives and setting them equal to 0, we\n%get two additional equations. Solving those two equations with the\n%original constraint, we get expressions for r, z, and lambda. Choosing the\n%solution such that r is positive and nonzero, one gets the expressions\n%implemented in this function.\n%\n%December 2020 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<5||isempty(invertA))\n invertA=false;\nend\n\nif(nargin<4||isempty(numPoints))\n numPoints=500; \nend\n\nif(nargin<3||isempty(gammaVal))\n gammaVal=18.8049;\nend \n\nif(invertA)\n A=applyFunToEachMatrix(@inv,A);\nend\n\nnumEllipse=size(z,2);\n\ntheta=linspace(-pi,pi,numPoints);\nu=[cos(theta);\n sin(theta)];\nxyPoints=zeros(2,numPoints,numEllipse);\nfor curEllipse=1:numEllipse\n Rxyrzz=A(1:2,1:2,curEllipse)*A(3,3,curEllipse);\n rz=A(1:2,3,curEllipse);\n rzzGamma=A(3,3,curEllipse)*gammaVal;\n zXYCur=z(1:2,curEllipse);\n\n for k=1:numPoints\n uCur=u(:,k);\n \n r=sqrt(rzzGamma/(uCur'*Rxyrzz*uCur-(rz'*uCur)^2));\n xyPoints(:,k,curEllipse)=zXYCur-r*uCur;\n end\nend\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Geometry/getEllipseHullPoints.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.874077230244524, "lm_q1q2_score": 0.7953290020241527}}
{"text": "function [C, sigma] = dataset3Params(X, y, Xval, yval)\n%EX6PARAMS returns your choice of C and sigma for Part 3 of the exercise\n%where you select the optimal (C, sigma) learning parameters to use for SVM\n%with RBF kernel\n% [C, sigma] = EX6PARAMS(X, y, Xval, yval) returns your choice of C and \n% sigma. You should complete this function to return the optimal C and \n% sigma based on a cross-validation set.\n%\n\n% You need to return the following variables correctly.\nC = 1;\nsigma = 0.3;\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Fill in this function to return the optimal C and sigma\n% learning parameters found using the cross validation set.\n% You can use svmPredict to predict the labels on the cross\n% validation set. For example, \n% predictions = svmPredict(model, Xval);\n% will return the predictions on the cross validation set.\n%\n% Note: You can compute the prediction error using \n% mean(double(predictions ~= yval))\n%\n\n\nresults = eye(64,3);\nerrorRow = 0;\n\nfor C_test = [0.01 0.03 0.1 0.3 1, 3, 10 30]\n for sigma_test = [0.01 0.03 0.1 0.3 1, 3, 10 30]\n errorRow = errorRow + 1;\n model = svmTrain(X, y, C_test, @(x1, x2) gaussianKernel(x1, x2, sigma_test));\n predictions = svmPredict(model, Xval);\n prediction_error = mean(double(predictions ~= yval));\n\n results(errorRow,:) = [C_test, sigma_test, prediction_error]; \n end\nend\n\nsorted_results = sortrows(results, 3); % sort matrix by column #3, the error, ascending\n\nC = sorted_results(1,1);\nsigma = sorted_results(1,2);\n\n\n\n\n% =========================================================================\n\nend\n", "meta": {"author": "Borye", "repo": "machine-learning-coursera-1", "sha": "033fdc2e6da393eeb1179a09aafe92362021effb", "save_path": "github-repos/MATLAB/Borye-machine-learning-coursera-1", "path": "github-repos/MATLAB/Borye-machine-learning-coursera-1/machine-learning-coursera-1-033fdc2e6da393eeb1179a09aafe92362021effb/Week 7 Assignments/Support Vector Machines/mlclass-ex6/dataset3Params.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361276, "lm_q2_score": 0.8918110569397306, "lm_q1q2_score": 0.7953269407650919}}
{"text": "function [ wval, dwdx ] = r8poly_lagrange_factor ( npol, xpol, xval )\n\n%*****************************************************************************80\n%\n%% R8POLY_LAGRANGE_FACTOR evaluates the polynomial Lagrange factor at a point.\n%\n% Formula:\n%\n% W(X) = Product ( 1 <= I <= NPOL ) ( X - XPOL(I) )\n%\n% Discussion:\n%\n% Suppose F(X) is at least N times continuously differentiable in the\n% interval [A,B]. Pick NPOL distinct points XPOL(I) in [A,B] and compute\n% the interpolating polynomial P(X) of order NPOL ( and degree NPOL-1)\n% which passes through all the points ( XPOL(I), F(XPOL(I)) ).\n% Then in the interval [A,B], the maximum error\n%\n% abs ( F(X) - P(X) )\n%\n% is bounded by:\n%\n% C * FNMAX * W(X)\n%\n% where\n%\n% C is a constant,\n% FNMAX is the maximum value of the NPOL-th derivative of F in [A,B],\n% W(X) is the Lagrange factor.\n%\n% Thus, the value of W(X) is useful as part of an estimated bound\n% for the interpolation error.\n%\n% Note that the Chebyshev abscissas have the property that they minimize\n% the value of W(X) over the interval [A,B]. Hence, if the abscissas may\n% be chosen arbitrarily, the Chebyshev abscissas have this advantage over\n% other choices.\n%\n% For a set of points XPOL(I), 1 <= I <= NPOL, the IPOL-th Lagrange basis\n% polynomial L(IPOL)(X), has the property:\n%\n% L(IPOL)( XPOL(J) ) = delta ( IPOL, J )\n%\n% and may be expressed as:\n%\n% L(IPOL)(X) = W(X) / ( ( X - XPOL(IPOL) ) * W'(XPOL(IPOL)) )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 26 April 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NPOL, the number of abscissas.\n% NPOL must be at least 1.\n%\n% Input, real XPOL(NPOL), the abscissas, which should \n% be distinct.\n%\n% Input, real XVAL, the point at which the Lagrange \n% factor is to be evaluated.\n%\n% Output, real WVAL, the value of the Lagrange factor at XVAL.\n%\n% Output, real DWDX, the derivative of W with respect to XVAL.\n%\n wval = prod ( xval - xpol(1:npol) );\n\n dwdx = 0.0;\n\n for i = 1 : npol\n\n term = 1.0;\n\n for j = 1 : npol\n if ( i ~= j )\n term = term * ( xval - xpol(j) );\n end\n end\n\n dwdx = dwdx + term;\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/r8lib/r8poly_lagrange_factor.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.8902942217558213, "lm_q1q2_score": 0.7953082125654461}}
{"text": "function ry = vecroty(angle) \n% \n% Function Name: \n% \n% vecroty - Transformation matrix for a rotation around the y axis. \n% \n% Calling Sequence: \n% \n% ry = vecroty(angle); \n% \n% Parameters: \n% \n% angle\t\t: rotation angle defined in radians \n% \n% ry\t\t: (4x4) Transformation matrix. \n% \n% \n% Description: \n% \n% Return the (4x4) Transformation matrix for a rotation about the y axis \n% by the defined angle. \n% \n% The matrix is: \n% \n% [ cos(angle) 0 sin(angle) 0] \n% [ 0 1 0 0] \n% [ -sin(angle) 0 cos(angle) 0] \n% [ 0 0 0 1] \n% \n% Examples: \n% \n% Rotate the NURBS line (0.0 0.0 0.0) - (3.0 3.0 3.0) by 45 degrees \n% around the y-axis \n% \n% line = nrbline([0.0 0.0 0.0],[3.0 3.0 3.0]); \n% trans = vecroty(%pi/4); \n% rline = nrbtform(line, trans); \n% \n% See: \n% \n% nrbtform \n \n% Dr D.M. Spink \n% Copyright (c) 2000. \n \nsn = sin(angle); \ncn = cos(angle); \nry = [cn 0 sn 0; 0 1 0 0; -sn 0 cn 0; 0 0 0 1]; \n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/26390-nurbs-toolbox-by-d-m-spink/nurbs_toolbox/vecroty.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632343454895, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7952660657688548}}
{"text": "function a=randNestedParenth(n)\n%%RANDNESTEDPARENTH Obtain a random character string of randomly nested\n% parentheses. Such parantheses can represent random\n% binary trees.\n%\n%INPUTS: n The number of open-closed parenthesis pairs.\n%\n%OUTPUTS: a A (2*n)X1 character string of n parenthesis pairs, with the\n% open parenthesis always coming before the close one.\n%\n%This function implements Algorithm W of Chapter 7.2.1.6 of [1].\n%\n%EXAMPLE:\n% a=randNestedParenth(5).'\n%We transpose it to make it easier to read.\n%\n%REFERENCES\n%[1] D. E. Knuth, The Art of Computer Programming. Vol. 4A: Combinatorial\n% Algorithms, Part I, Boston: Addison-Wesley, 2011.\n%\n%October 2018 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\np=n;\nq=n;\nm=1;\n%Allocate space for the random set of nested parentheses.\na=repmat(' ',2*n,1);\n\nwhile(q~=0)\n while(1)\n upperBound=(q+p)*(q-p+1);\n X=randi(upperBound-1);\n \n if(X<(q+1)*(q-p))\n q=q-1;\n a(m)=')';\n m=m+1;\n break; \n end\n p=p-1;\n a(m)='(';\n m=m+1;\n end\nend\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Combinatorics/randNestedParenth.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.8947894710123925, "lm_q1q2_score": 0.795252000140902}}
{"text": "function rad=dms2rad(dms)\n% DMS2RAD Converts degrees-minutes-seconds to radians.\n% Vectorized.\n% Version: 12 Mar 00\n% Useage: rad=dms2rad(dms)\n% Input: dms - [d m s] array of angles in deg-min-sec, where\n% d = vector of degrees\n% m = vector of minutes\n% s = vector of seconds\n% Output: rad - vector of angles in radians\n\n% Copyright (c) 2011, Michael R. Craymer\n% All rights reserved.\n% Email: mike@craymer.com\n\nd=dms(:,1);\nm=dms(:,2);\ns=dms(:,3);\ndec=abs(d)+abs(m)./60+abs(s)./3600;\nrad=dec.*pi./180;\nind=(d<0 | m<0 | s<0);\nrad(ind)=-rad(ind);\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/15285-geodetic-toolbox/geodetic/dms2rad.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7952335161449922}}
{"text": "%................................................................\n\nfunction stiffness=formStiffness2D(GDof,numberElements,...\n elementNodes,numberNodes,nodeCoordinates,C,thickness)\n\n% compute stiffness matrix\n% for plane stress Q8 elements\n\nstiffness=zeros(GDof);\n\n% 3 by 3 quadrature\n[gaussWeights,gaussLocations]=gauss2d('3x3');\n\nfor e=1:numberElements \n numNodePerElement = length(elementNodes(e,:));\n numEDOF = 2*numNodePerElement;\n elementDof=zeros(1,numEDOF);\n for i = 1:numNodePerElement\n elementDof(2*i-1)=2*elementNodes(e,i)-1;\n elementDof(2*i)=2*elementNodes(e,i); \n end\n \n % cycle for Gauss point\n for q=1:size(gaussWeights,1) \n GaussPoint=gaussLocations(q,:); \n xi=GaussPoint(1);\n eta=GaussPoint(2);\n \n% shape functions and derivatives\n [shapeFunction,naturalDerivatives]=shapeFunctionQ8(xi,eta);\n\n% Jacobian matrix, inverse of Jacobian, \n% derivatives w.r.t. x,y \n [Jacob,invJacobian,XYderivatives]=...\n Jacobian(nodeCoordinates(elementNodes(e,:),:),naturalDerivatives);\n \n% B matrix\n B=zeros(3,numEDOF);\n B(1,1:2:numEDOF) = XYderivatives(:,1)'; \n B(2,2:2:numEDOF) = XYderivatives(:,2)';\n B(3,1:2:numEDOF) = XYderivatives(:,2)';\n B(3,2:2:numEDOF) = XYderivatives(:,1)';\n \n% stiffness matrix\n stiffness(elementDof,elementDof)=...\n stiffness(elementDof,elementDof)+...\n B'*C*thickness*B*gaussWeights(q)*det(Jacob); \n end \nend \n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/FEM/Lab10_Q8/formStiffness2D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566341987633822, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.7950998556432874}}
{"text": "function [qp]=zn2fr(input)\n% [qp]=zn2fr(input)\n% Ziegler-Nichols PID controller for processes of 2nd order.\n% This function computes parameters of the controller (q0, q1, q2, p1, p2).\n% Controller is based on forward rectangular method of discretization.\n% Transfer function of the controller is as follows:\n%\n% q0 + q1*z^-1 + q2*z^-2 q0 + q1*z^-1 + q2*z^-2\n% G(z^-1) = ------------------------ = ------------------------\n% 1 - z^-1 1 + p1*z^-1 + p2*z^-2\n%\n% where p1=-1 and p2=0.\n%\n% Transfer function of the controlled system is:\n%\n% b1*z^-1 + b2*z^-2\n% Gs(z^-1) = -----------------------\n% 1 + a1*z^-1 + a2*z^-2\n%\n% Input: input ... input parameters\n% input(1) ... a1\n% input(2) ... b1\n% input(3) ... a2\n% input(4) ... b2\n% input(5) ... sample time T0\n% Output: qp ... controller parameters \n% qp(1) ... q0\n% qp(2) ... q1\n% qp(3) ... q2\n% qp(4) ... -1 (p1 of the controller)\n% qp(5) ... 0 (p2 of the controller)\n\na1 = input(1);\nb1 = input(2);\na2 = input(3);\nb2 = input(4);\nT0 = input(5);\n\n% compute ultimate gain and frequency\n[Kpu, Tu] = ultim([b1 b2],[a1 a2],T0);\n\nKp = 0.6*Kpu;\nTi = Tu/2;\nTd = Tu/8;\n\nq0 = Kp*(1+Td/T0);\nq1 = -Kp*(1-T0/Ti+2*Td/T0);\nq2 = Kp*(Td/T0);\np1 = -1;\np2 = 0;\n\nqp=[q0; q1; q2; p1; p2];\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/8381-stcsl-standard-version/zn2fr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542840900507, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7950802153299902}}
{"text": "function ex2bvp\n%EX2BVP Example 2 of the BVP tutorial.\n% A standard linear problem with a boundary layer at the origin.\n% The differential equation y'' + 3*p*y/(p + t^2)^2 = 0 has the \n% analytical solution y(t) = t/sqrt(p + t^2). The parameter p\n% is taken to be 1e-5, a common value in tests. The solution is\n% to have specified values at t = -0.1 and +0.1, values taken from\n% this analytical solution.\n% \n% The default RelTol of 1e-3 gives an acceptable solution, but \n% reducing RelTol to 1e-4 resolves better the boundary layer. A \n% constant guess is used for RelTol = 1e-3. The same guess could be\n% used for RelTol = 1e-4, but a very much better guess is provided \n% by the solution previously computed for RelTol = 1e-3.\n\n% Copyright 2002, The MathWorks, Inc.\n\n% Evaluate the analytical solution for comparison.\ntt = -0.1:0.01:+0.1;\np = 1e-5;\nyy = tt ./ sqrt(p + tt .^2);\n\noptions = bvpset('stats','on','Fjacobian',@ex2Jac);\n\n% BVPINT is used to specify an initial guess for the mesh of 10\n% equally spaced points. A constant guess based on a straight line\n% between the boundary values for y is 0 for y(t) and 10 for y'(t).\nsolinit = bvpinit(linspace(-0.1,0.1,10),[0 10]);\n\nsol = bvp4c(@ex2ode,@ex2bc,solinit, options);\nt = sol.x;\ny = sol.y;\n\nfigure\nplot(t,y(1,:),tt,yy,'*')\naxis([-0.1 0.1 -1.1 1.1])\ntitle(['Linear boundary layer problem with RelTol = 1e-3.'])\nxlabel('t')\nylabel('y and analytical (*) solutions')\n\nfprintf('\\n');\n\n% A smaller RelTol is used to resolve better the boundary layer.\n% The previous solution provides an excellent guess.\noptions = bvpset(options,'RelTol',1e-4);\nsol = bvp4c(@ex2ode,@ex2bc,sol,options);\nt = sol.x;\ny = sol.y;\n\nfigure\nplot(t,y(1,:),tt,yy,'*')\naxis([-0.1 0.1 -1.1 1.1])\ntitle(['Linear boundary layer problem with RelTol = 1e-4.'])\nxlabel('t')\nylabel('y and analytical (*) solutions')\n\n% --------------------------------------------------------------------------\n\nfunction dydt = ex2ode(t,y)\n%EX2ODE ODE function for Example 2 of the BVP tutorial. \n% The components of y correspond to the original variables\n% as y(1) = y, y(2) = y'.\np = 1e-5;\ndydt = [ y(2)\n -3*p*y(1)/(p+t^2)^2];\n\n% --------------------------------------------------------------------------\n\nfunction dfdy = ex2Jac(t,y)\n%EX2JAC The Jacobian of the ODE function for Example 2 of the BVP tutorial. \np = 1e-5;\ndfdy = [ 0 1\n -3*p/(p+t^2)^2 0 ]; \n\n% --------------------------------------------------------------------------\n\nfunction res = ex2bc(ya,yb)\n%EX2BC Boundary conditions for Example 2 of the BVP tutorial.\n% The boundary conditions are that the solution should agree\n% with the values of an analytical solution at both a and b.\np = 1e-5;\nyatb = 0.1/sqrt(p + 0.01);\nyata = - yatb;\nres = [ ya(1) - yata\n yb(1) - yatb ];\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/3819-tutorial-on-solving-bvps-with-bvp4c/BVP_tutorial/BVP_examples_65/ex2bvp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.8976952968970956, "lm_q1q2_score": 0.7950272115404389}}
{"text": "function coeffsRet=polyIntMultiDim(coeffs,intDim,intConst)\n%%POLYINTMULTIDIM Compute the indefinite integral of a multivariate\n% polynomial with respect to a particular dimension given a\n% hypermatrix of its coefficients (including cross terms). \n%\n%INPUTS: coeffs A hypermatrix of the coefficients for the multivariate\n% polynomial. These are arranged such that\n% coeffs(a1,a2,a3...an) corresponds to the coefficient of an\n% x1^(a1-1)*x2^(a2-1)*x3^(a3-1)...xn^(an-1) term. Thus, the\n% number of indices coeffs takes is equal to the\n% dimensionality of x (not counting singleton dimensions at\n% the end of coeffs). Note that this ordering is the reverse\n% that used in the 1D polyval function that is built into\n% Matlab. The number of elements for each index in coeffs is\n% the maximum order of that dimension +1.\n% intDim The dimension of x (index of coeffs) with respect to which\n% the integral is to be taken.\n% intConst The integration constant. If this parameter is omitted or\n% an empty matrix is passed, a default value of 0 is used.\n%\n%OUTPUTS: coeffsRet The indefinite integral of the coeffs hypermatrix.\n%\n%This function is just implemented using the basic rules of polynomial\n%integration.\n%\n%As an example, consider the multivariate polynomial:\n%14+3*x1^2-18*x2+12*x1*x3-3*x2*x3\n%The integrals with respect to the first, second and third variables are\n% coeffs=zeros(3,2,2);\n% coeffs(0+1,0+1,0+1)=14;\n% coeffs(2+1,0+1,0+1)=3;\n% coeffs(0+1,1+1,0+1)=-18;\n% coeffs(1+1,0+1,1+1)=12;\n% coeffs(0+1,1+1,1+1)=-3;\n% intCoeffs1=polyIntMultiDim(coeffs,1);\n% intCoeffs2=polyIntMultiDim(coeffs,2);\n% intCoeffs3=polyIntMultiDim(coeffs,3);\n%One will see that intCoeffs1 corresponds to\n%14*x1+x1^3-18*x1*x2+6*x1^2*x3-3*x1*x2*x3\n%intCoeffs2 corresponds to\n%14*x2*+3*x1^2*x2-9*x2^2+12*x1*x2*x3-(3/2)*x2^2*x3\n%and intCoeffs3 corresponds to.\n%14*x3+3*x1^2*x3-18*x2*x3+6*x1*x3^2-(3/2)*x2*x3^2\n%\n%Note that the fucntion can be used with variables that are not present in\n%the original polynomial. In the above example,\n% intCoeffs4=polyIntMultiDim(coeffs,4);\n%provides coefficients corresponding to\n%14*x4+3*x1^2*x4-18*x2*x4+12*x1*x3*x4-3*x2*x3*x4\n%\n%August 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<3||isempty(intConst))\n intConst=0; \nend\n\ndimSizeList=size(coeffs);\nnumIdx=length(dimSizeList);\ntotalEls=prod(dimSizeList);\n\n%If the dimension of integration is a singleton dimension that has been\n%suppressed from the end of dimSizeList, then we must add in all of the\n%missing singleton dimensions.\ndimRetSizeList=[dimSizeList,ones(1,intDim-numIdx)];\n%Integration will increase the maximum degree of the term over which\n%integration is performed by one, meaning that the matrix has to be made\n%larger.\ndimRetSizeList(intDim)=dimRetSizeList(intDim)+1;\n\n%Allocate space for the return coefficients.\ncoeffsRet=zeros(dimRetSizeList);\n\n%We will now loop through all of the values in the original coefficient\n%set, adjusting them and inserting them into the proper location in the new\n%modified coefficient set, after multiplication by the appropriate\n%constant.\n\nif(intDim>numIdx)\n%This is used when integrating over a trailing singleton dimension.\n indicesFull=ones(numIdx,1);\n indicesFull(intDim)=2;\nend\nfor curEl=1:totalEls\n curCoeff=coeffs(curEl);\n indices=index2NDim(dimSizeList,curEl);\n \n if(intDim<=numIdx)\n constVal=1/indices(intDim);\n indices(intDim)=indices(intDim)+1;\n coeffsRet(nDim2Index(dimRetSizeList,indices))=constVal*curCoeff;\n else%If we are integration over a trailing singleton dimension.\n indicesFull(1:numIdx)=indices;\n coeffsRet(nDim2Index(dimRetSizeList,indicesFull))=curCoeff;\n end\nend\n\n%Add in the integration constant. It is the zeroth-order term.\ncoeffsRet(1)=intConst;\n\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Polynomials/Generic_Multivariate_Polynomials/polyIntMultiDim.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8856314753275019, "lm_q1q2_score": 0.7950272035196098}}
{"text": "function value = quad_fun ( n )\n\n%*****************************************************************************80\n%\n%% QUAD_FUN demonstrates MATLAB's PARFOR command for parallel programming.\n%\n% Discussion:\n%\n% This function estimates an integral using the composite trapezoidal rule.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 26 March 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of points to use.\n%\n% Output, real VALUE, the estimate for the integral.\n%\n a = 0.0;\n b = 1.0;\n\n value = 0.0;\n h = ( b - a ) / ( n - 1 );\n\n parfor i = 1 : n\n\n x = ( ( n - i ) * a + ( i - 1 ) * b ) / ( n - 1 );\n\n fx = f ( x );\n\n if ( i == 1 )\n value = value + 0.5 * fx * h\n elseif ( i < n )\n value = value + fx * h;\n elseif ( i == n )\n value = value + 0.5 * fx * h;\n end\n\n end\n\n return\nend\nfunction value = f ( x )\n\n%*****************************************************************************80\n%\n%% F is the function to be integrated.\n%\n% Discussion:\n%\n% The integral of F(X) from 0 to 1 is exactly PI.\n%\n% Modified:\n%\n% 17 August 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the values where the integrand is to be evaluated.\n%\n% Output, real VALUE, the integrand values.\n%\n value = 4.0 ./ ( 1 + x.^2 );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/quad_parfor/quad_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898305367524, "lm_q2_score": 0.8774767778695834, "lm_q1q2_score": 0.7949850372819994}}
{"text": "function [center,radius] = minboundsphere(xyz)\n% minboundsphere: Compute the minimum radius enclosing sphere of a set of (x,y,z) triplets\n% usage: [center,radius] = minboundsphere(xyz)\n%\n% arguments: (input)\n% xyz - nx3 array of (x,y,z) triples, describing points in R^3\n% as rows of this array.\n%\n%\n% arguments: (output)\n% center - 1x3 vector, contains the (x,y,z) coordinates of\n% the center of the minimum radius enclosing sphere\n%\n% radius - scalar - denotes the radius of the minimum\n% enclosing sphere\n%\n%\n% Example usage:\n% Sample uniformly from the interior of a unit sphere. \n% As the sample size increases, the enclosing sphere\n% should asymptotically approach center = [0 0 0], and\n% radius = 1.\n%\n% xyz = rand(10000,3)*2-1;\n% r = sqrt(sum(xyz.^2,2));\n% xyz(r>1,:) = []; % 5156 points retained\n% tic,[center,radius] = minboundsphere(xyz);toc\n% \n% Elapsed time is 0.199467 seconds.\n%\n% center = [0.00017275 8.5006e-05 0.00012015]\n%\n% radius = 0.9999\n%\n% Example usage:\n% Sample from the surface of a unit sphere. Within eps\n% or so, the result should be center = [0 0 0], and radius = 1.\n%\n% xyz = randn(10000,3);\n% xyz = xyz./repmat(sqrt(sum(xyz.^2,2)),1,3);\n% tic,[center,radius] = minboundsphere(xyz);toc\n%\n% Elapsed time is 0.614762 seconds.\n%\n% center =\n% 4.6127e-17 -2.5584e-17 7.2711e-17\n%\n% radius =\n% 1\n%\n%\n% See also: minboundrect, minboundcircle\n%\n%\n% Author: John D'Errico\n% E-mail: woodchips@rochester.rr.com\n% Release: 1.0\n% Release date: 1/23/07\n\n% not many error checks to worry about\nsxyz = size(xyz);\nif (length(sxyz)~=2) || (sxyz(2)~=3)\n error 'xyz must be an nx3 array of points'\nend\nn = sxyz(1);\n\n% start out with the convex hull of the points to\n% reduce the problem dramatically. Note that any\n% points in the interior of the convex hull are\n% never needed.\nif n>4\n tri = convhulln(xyz,{'QJ' 'Pp'});\n\n % list of the unique points on the convex hull itself\n hlist = unique(tri(:));\n\n % exclude those points inside the hull as not relevant\n xyz = xyz(hlist,:);\n \nend\n\n% now we must find the enclosing sphere of those that\n% remain.\nn = size(xyz,1);\n\n% special case small numbers of points. If we trip any\n% of these cases, then we are done, so return.\nswitch n\n case 0\n % empty begets empty\n center = [];\n radius = [];\n return\n case 1\n % with one point, the center has radius zero\n center = xyz;\n radius = 0;\n return\n case 2\n % only two points. center is at the midpoint\n center = mean(xyz,1);\n radius = norm(xyz(1,:) - center);\n return\n case 3\n % exactly 3 points. For this odd case, just use enc4,\n % appending a new point at the centroid. This is simpler\n % than other solutions that would have reduced the\n % problem to 2-d. enc4 will do that anyway.\n [center,radius] = enc4([xyz;mean(xyz,1)]);\n return\n case 4\n % exactly 4 points\n [center,radius] = enc4(xyz);\n return\nend\n\n% pick a tolerance\ntol = 10*eps*max(max(abs(xyz),[],1) - min(abs(xyz),[],1));\n\n% more than 4 points. for no more than 15 points in the hull,\n% just do an exhaustive search.\nif n <= 15\n % for 15 points, there are only nchoosek(15,4) = 1365\n % sets to look through. this is only about a second.\n asets = nchoosek(1:n,4);\n \n center = inf(1,3);\n radius = inf;\n for i = 1:size(asets,1)\n aset = asets(i,:);\n iset = setdiff(1:n,aset);\n \n % get the enclosing sphere for the current set\n [centeri,radiusi] = enc4(xyz(aset,:));\n \n % are all the inactive set points inside the circle?\n ri = sqrt(sum((xyz(iset,:) - repmat(centeri,n-4,1)).^2,2));\n \n [rmax,k] = max(ri);\n if ((rmax - radiusi) <= tol) && (radiusi < radius) \n center = centeri;\n radius = radiusi;\n end\n end\n \nelse\n % Use an active set strategy, on many different\n % random starting sets.\n center = inf(1,3);\n radius = inf;\n \n for i = 1:250\n aset = randperm(n); % a random start, but quite adequate\n iset = aset(5:n);\n aset = aset(1:4);\n \n flag = true;\n iter = 0;\n centeri = inf(1,3);\n radiusi = inf;\n while flag && (iter < 12)\n iter = iter + 1;\n \n % get the enclosing sphere for the current set\n [centeri,radiusi] = enc4(xyz(aset,:));\n \n % are all the inactive set points inside the circle?\n ri = sqrt(sum((xyz(iset,:) - repmat(centeri,n-4,1)).^2,2));\n \n [rmax,k] = max(ri);\n if (rmax - radiusi) <= tol\n % the active set enclosing sphere also enclosed\n % all of the inactive points. We are done.\n flag = false;\n else\n % it must be true that we can replace one member of aset\n % with iset(k). That k'th element was farthest out, so\n % it seems best (a greedy algorithm) to swap it in. The\n % problem with the greedy algorithm, is it gets trapped\n % in a cycle at times. but since we are restarting the\n % algorithm multiple times, this will work.\n s1 = [aset([2 3 4]),iset(k)];\n [c1,r1] = enc4(xyz(s1,:));\n if (norm(c1 - xyz(aset(1),:)) <= r1)\n centeri = c1;\n radiusi = r1;\n \n % update the active/inactive sets\n swap = aset(1);\n aset = [iset(k),aset([2 3 4])];\n iset(k) = swap;\n \n % bounce out to the while loop\n continue\n end\n s1 = [aset([1 3 4]),iset(k)];\n [c1,r1] = enc4(xyz(s1,:));\n if (norm(c1 - xyz(aset(2),:)) <= r1)\n centeri = c1;\n radiusi = r1;\n \n % update the active/inactive sets\n swap = aset(2);\n aset = [iset(k),aset([1 3 4])];\n iset(k) = swap;\n \n % bounce out to the while loop\n continue\n end\n s1 = [aset([1 2 4]),iset(k)];\n [c1,r1] = enc4(xyz(s1,:));\n if (norm(c1 - xyz(aset(3),:)) <= r1)\n centeri = c1;\n radiusi = r1;\n \n % update the active/inactive sets\n swap = aset(3);\n aset = [iset(k),aset([1 2 4])];\n iset(k) = swap;\n \n % bounce out to the while loop\n continue\n end\n s1 = [aset([1 2 3]),iset(k)];\n [c1,r1] = enc4(xyz(s1,:));\n if (norm(c1 - xyz(aset(4),:)) <= r1)\n centeri = c1;\n radiusi = r1;\n \n % update the active/inactive sets\n swap = aset(4);\n aset = [iset(k),aset([1 2 3])];\n iset(k) = swap;\n \n % bounce out to the while loop\n continue\n end\n \n % if we get through to this point, then something went wrong.\n % Active set problem. Increase tol, then try again.\n tol = 2*tol;\n \n end\n end\n \n % have we improved over the best set so far?\n if radiusi < radius\n center = centeri;\n radius = radiusi;\n end\n end\nend\n\n% =======================================\n% begin subfunctions\n% =======================================\nfunction [center,radius] = enc4(xyz)\n% minimum radius enclosing sphere for exactly 4 points in R^3\n%\n% xyz is a 4x3 array\n%\n% Note that enc4 will attempt to pass a sphere through all\n% 4 of the supplied points. When the set of points proves to \n% be degenerate, perhaps because of collinearity of 3 or\n% more of the points, or because the 4 points are coplanar,\n% then the sphere would nominally have infinite radius. Since\n% there must be a finite radius sphere to enclose any set of\n% finite valued points, enc4 will provide that sphere instead.\n%\n% In addition, there are some non-degenerate sets of points\n% for which the circum-sphere is not minimal. enc4 will always\n% try to find the minimum radius enclosing sphere.\n\n% interpoint distance matrix D\n% dfun = @(A) (A(:,[1 1 1 1]) - A(:,[1 1 1 1])').^2;\ndfun = inline('(A(:,[1 1 1 1]) - A(:,[1 1 1 1])'').^2','A');\nD = sqrt(dfun(xyz(:,1)) + dfun(xyz(:,2)) + dfun(xyz(:,3)));\n\n% Find the most distant pair. Test if their circum-sphere\n% also encloses the other points. If it does, then we are\n% done.\n[dij,ij] = max(D(:));\n[i,j] = ind2sub([4 4],ij);\nothers = setdiff(1:4,[i,j]);\nradius = dij/2;\ncenter = (xyz(i,:) + xyz(j,:))/2;\nif (norm(center - xyz(others(1),:))<=radius) && ...\n (norm(center - xyz(others(2),:))<=radius)\n % we can stop here.\n return\nend\n\n% next, we need to test each triplet of points, finding their\n% enclosing sphere. If the 4th point is also inside, then we\n% are done.\nind = 1:3;\n[center,radius,isin] = enc3_4(xyz(ind,:),xyz(4,:),D(ind,ind));\nif isin\n % the 4th point was inside this enclosing sphere.\n return\nend\n\nind = [1 2 4];\n[center,radius,isin] = enc3_4(xyz(ind,:),xyz(3,:),D(ind,ind));\nif isin\n % the 3rd point was inside this enclosing sphere.\n return\nend\n\nind = [1 3 4];\n[center,radius,isin] = enc3_4(xyz(ind,:),xyz(2,:),D(ind,ind));\nif isin\n % the second point was inside this enclosing sphere.\n return\nend\n\nind = [2 3 4];\n[center,radius,isin] = enc3_4(xyz(ind,:),xyz(1,:),D(ind,ind));\nif isin\n % the first point was inside this enclosing sphere.\n return\nend\n\n% find the circum-sphere that passes through all 4 points\n% since we have passed all the other tests, we need not\n% worry here about singularities in the system of\n% equations.\nA = 2*(xyz(2:4,:)-repmat(xyz(1,:),3,1));\nrhs = sum(xyz(2:4,:).^2 - repmat(xyz(1,:).^2,3,1),2);\ncenter = (A\\rhs)';\nradius = norm(center - xyz(1,:));\n\n\n% =======================================\nfunction [center,radius,isin] = enc3_4(xyz,xyztest,Di)\n% minimum radius enclosing sphere for exactly 3 points in R^3\n%\n% xyz - a 3x3 array, with each row as a point in R^3\n%\n% xyztest - 1x3 vector, a point to be tested if it is\n% inside the generated enclosing sphere.\n% \n% Di - 3x3 array of interpoint distances\n\n% test the farthest pair of points. do they form a diameter\n% of the sphere?\nif Di(1,2)>=max(Di(1,3),Di(2,3))\n center = mean(xyz([1 2],:),1);\n radius = Di(1,2)/2;\n isin = (norm(xyz(3,:) - center)<=radius) && (norm(xyztest - center)<=radius);\nelseif Di(1,3)>=max(Di(1,2),Di(2,3))\n center = mean(xyz([1 3],:),1);\n radius = Di(1,3)/2;\n isin = (norm(xyz(2,:) - center)<=radius) && (norm(xyztest - center)<=radius);\nelseif Di(2,3)>=max(Di(1,2),Di(1,3))\n center = mean(xyz([2 3],:),1);\n radius = Di(2,3)/2;\n isin = (norm(xyz(1,:) - center)<=radius) && (norm(xyztest - center)<=radius);\nend\nif isin\n % we found the minimal enclosing sphere already\n return\nend\n\n% If we drop down to here, no singularities should\n% happen (I've already caught any degeneracies.)\n\n% We transform the three points into a plane, then\n% compute the enclosing sphere in that plane.\n\n% translate to the origin\nxyz0 = xyz(1,:);\nxyzt = xyz(2:3,:) - [xyz0;xyz0];\n\nrot = orth(xyzt');\n\n% uv is composed of 2 points, in 2-d, plus we\n% have the origin (after the translation)\nuv = xyzt*rot;\n\nA = 2*uv;\nrhs = sum(uv.^2,2);\ncenter = (A\\rhs)';\nradius = norm(center - uv(1,:));\n\n% rotate and translate back\ncenter = center*rot' + xyz0;\n\n% test if the 4th point is enclosed also\nisin = (norm(xyztest - center)<=radius);\n\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/34767-a-suite-of-minimal-bounding-objects/MinBoundSuite/minboundsphere.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8688267660487572, "lm_q1q2_score": 0.7948904379814702}}
{"text": "function [p,s]=v_minspane(x)\n%V_MINSPANE calculate minimum spanning tree using euclidean distance [p,s]=X\n%\n% Inputs: x(n,d) d-dimensional data points, one per row\n%\n% Outputs: p(n-1,1) indices of the parent of each node within the tree\n% (data point n is the root)\n% s(n-1,1) list of the edges in ascending order of euclidean\n% distance. Thus the shortest edge goes from node\n% s(1) to node p(s(1))\n%\n% The minimum spanning tree (or shortest spanning tree ) defines a set of\n% n-1 links that interconnect n points (or nodes) with the minimum total\n% length. We represent these links in the form of a tree with node n as\n% the root. Each node (except node n) has a unique parent node that is\n% given in the output vector p; it is possible for several nodes to share\n% the same parent.\n% It can be useful to know which of the links are the longest, so the output\n% argument lists them in ascending order. s could be calculated directly by\n% calculaing the length, l, of each link as follows:\n% l=sqrt(sum((x(1:n-1,:) - x(p,:)).^2),2);\n% [v,s]=sort(l);\n\n% Copyright (C) Mike Brookes 2000-2009\n% Version: $Id: v_minspane.m 10865 2018-09-21 17:22:45Z dmb $\n%\n% VOICEBOX is a MATLAB toolbox for speech processing.\n% Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% This program is free software; you can redistribute it and/or modify\n% it under the terms of the GNU General Public License as published by\n% the Free Software Foundation; either version 2 of the License, or\n% (at your option) any later version.\n%\n% This program is distributed in the hope that it will be useful,\n% but WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n% GNU General Public License for more details.\n%\n% You can obtain a copy of the GNU General Public License from\n% http://www.gnu.org/copyleft/gpl.html or by writing to\n% Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n[np,nd]=size(x);\n\n% first do delauny tessalation to find feasible edges\n\nt=delaunayn(x); % nd+1 vertices per polytope\nnt=size(t,1);\ncn=v_choosenk(nd+1,2);\nnf=size(cn,1);\nee=zeros(nt,nf,2); % space for all the edges\nee(:,:,1)=t(:,cn(:,1));\nee(:,:,2)=t(:,cn(:,2));\nee=reshape(ee,[],2);\nmk=ee(:,1)>ee(:,2);\nee(mk,:)=ee(mk,2:-1:1); % make all edges in ascending order\n% ees=sparse(ee(:,1),ee(:,2),1); % remove duplicates\n[er,ec]=find(sparse(ee(:,1),ee(:,2),1)); % remove duplicates\nee=[er,ec];\nne=size(ee,1);\n\n% now apply Kruskal shortest spanning tree algorithm\n\nsz=sum((x(ee(:,1),:)-x(ee(:,2),:)).^2,2); % length^2 of each edge\n[vz,mz]=sort(sz);\nee=ee(mz,:); % sort edges into ascenging length order\nts=ones(ne,1); % size of each component\ntp=zeros(np,1); % root node links\nei=zeros(np-1,1); % index of shortest spanning tree edges\nk=0;\nfor i=1:ne\n i1=ee(i,1);\n j=tp(i1);\n while j % find root node for ee(i,1)\n i1=j;\n j=tp(i1);\n end\n i2=ee(i,2);\n j=tp(i2);\n while j % find root node for ee(i,2)\n i2=j;\n j=tp(i2);\n end\n if i1~=i2 % if they are different, merge them\n k=k+1;\n ei(k)=i; % add to the shortest spanning tree\n if ts(i1)>ts(i2)\n tp(i2)=i1; % make i2 a sub tree of i1\n ts(i1)=ts(i1)+ts(i2);\n else\n tp(i1)=i2; % make i1 a sub tree of i2\n ts(i2)=ts(i1)+ts(i2);\n end\n end\nend\nee=ee(ei,:); % refine the edges to include only those in the minimum spanning tree\n\n% now arrange as a tree with point np as the head\n\neet=sparse(ee(:,1),ee(:,2),1:np-1,np,np);\np=zeros(np-1,1); % points to parent node\ns=zeros(np-1,1); % sorted index\nchn=np; % start with the root node of the tree\n[rf,cf]=find(eet(:,chn)); % find any nodes that connect to it\n[rg,cg]=find(eet(chn,:));\nwhile ~isempty(rf) || ~isempty(rg)\n p(rf)=chn(cf); % set the parents\n rcf=rf(:)+np*(chn(cf(:))-1);\n s(eet(rcf))=rf(:);\n eet(rcf)=0; % delete the edges linking them to their parents\n p(cg)=chn(rg);\n rcg=chn(rg(:))+np*(cg(:)-1);\n s(eet(rcg))=cg(:);\n eet(rcg)=0;\n chn=[rf(:); cg(:)]; % now search for their children\n [rf,cf]=find(eet(:,chn));\n [rg,cg]=find(eet(chn,:));\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "sap-voicebox", "sha": "28f2654b7584f724277ec81de533debe28ff51ac", "save_path": "github-repos/MATLAB/ImperialCollegeLondon-sap-voicebox", "path": "github-repos/MATLAB/ImperialCollegeLondon-sap-voicebox/sap-voicebox-28f2654b7584f724277ec81de533debe28ff51ac/voicebox/v_minspane.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356994, "lm_q2_score": 0.8723473879530491, "lm_q1q2_score": 0.7948652441927265}}
{"text": "%% A 10x10 tridiagonal matrix, with 2 on the diagonal, -1 on the off diagonal.\n\nA = blktridiag(2,-1,-1,10);\n\n% The sparsity pattern is correct\nspy(A)\n\n% and the elements are as designated\nfull(A)\n\n%% A lower block bidiagonal matrix with replicated blocks\n\n% with 2x2 blocks of ones on the main diagonal, and\n% 2x2 blocks of twos on the sub-diagonal\n\nA = blktridiag(ones(2),2*ones(2),zeros(2),5);\n\nspy(A)\nfull(A)\n\n%% A block tridiagonal matrix with replicated blocks\n\nAmd = reshape(1:9,3,3);\nAsub = reshape(11:19,3,3);\nAsup = reshape(21:29,3,3);\nA = blktridiag(Amd,Asub,Asup,4);\n\nspy(A)\nfull(A)\n\n%% A tridiagonal matrix with random elements\n\nAmd = rand(1,1,7);\nAsub = rand(1,1,6);\nAsup = rand(1,1,6);\nA = blktridiag(Amd,Asub,Asup);\n\nspy(A)\nfull(A)\n\n%% A block tridiagonal matrix with distinct elements\n\nAmd = reshape(1:27,[3 3 3]);\nAsub = reshape(101:118,[3 3 2]);\nAsup = reshape(201:218,[3 3 2]);\nA = blktridiag(Amd,Asub,Asup);\n\nspy(A)\nfull(A)\n\n%% A block tridiagonal matrix with 2x3 fixed non-square blocks\n\nAmd = rand(2,3);\nAsub = 2*ones(2,3);\nAsup = ones(2,3);\nA = blktridiag(Amd,Asub,Asup,3);\n\nspy(A)\nfull(A)\n\n%% A block tridiagonal matrix with varying 3x2 non-square blocks\nAmd = reshape(1:18,[3 2 3]);\nAsub = reshape(101:112,[3 2 2]);\nAsup = reshape(201:212,[3 2 2]);\nA = blktridiag(Amd,Asub,Asup);\n\nspy(A)\nfull(A)\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/10603-block-tri-diagonal-matrices/BLKTRIDIAG/demo/blktridiag_demo.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.911179705187943, "lm_q2_score": 0.8723473663814338, "lm_q1q2_score": 0.7948652161209134}}
{"text": "function lagrange_nd_test07 ( )\n\n%*****************************************************************************80\n%\n%% LAGRANGE_ND_TEST07 tests LAGRANGE_ND_COMPLETE in 3D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 21 January 2014\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LAGRANGE_ND_TEST07\\n' );\n fprintf ( 1, ' LAGRANGE_COMPLETE determines\\n' );\n fprintf ( 1, ' the Lagrange interpolating polynomials L(x)\\n' );\n fprintf ( 1, ' for ND points in D dimensions, assuming that\\n' );\n fprintf ( 1, ' the number of points exactly coincides with\\n' );\n fprintf ( 1, ' R = Pi(D,N), the number of monomials of degree N or less\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The data points are the grid nodes of a tetrahedron.\\n' );\n\n d = 3;\n n = 2;\n r = mono_upto_enum ( d, n );\n nd = 10;\n xd = [ 0.0, 0.0, 0.0; ...\n 1.0, 0.0, 0.0; ...\n 2.0, 0.0, 0.0; ...\n 0.0, 1.0, 0.0; ...\n 1.0, 1.0, 0.0; ...\n 0.0, 2.0, 0.0; ...\n 0.0, 0.0, 1.0; ...\n 1.0, 0.0, 1.0; ...\n 0.0, 1.0, 1.0; ...\n 0.0, 0.0, 2.0 ]';\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Spatial dimension D = %d\\n', d );\n fprintf ( 1, ' Maximum degree N = %d\\n', n );\n fprintf ( 1, ' Number of monomials R = %d\\n', r );\n fprintf ( 1, ' Number of data points ND = %d\\n', nd );\n\n r8mat_transpose_print ( d, nd, xd, ' Data points XD:' );\n\n [ po, pc, pe ] = lagrange_complete ( d, n, r, nd, xd );\n%\n% Print the polynomials.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Lagrange polynomials for XD data points:\\n' );\n fprintf ( 1, '\\n' );\n for i = 1 : nd\n o = po(i);\n label = sprintf ( ' P(%d)(x) =', i );\n polynomial_print ( d, o, pc(i,1:o), pe(i,1:o), label );\n end\n%\n% Evaluate the polynomials at XD.\n%\n value = zeros ( nd, nd );\n\n for j = 1 : nd\n o = po(j);\n label = sprintf ( ' P(%d)(x) =', j );\n value(1:nd,j) = polynomial_value ( d, o, pc(j,1:o), pe(j,1:o), nd, xd ); \n end\n\n err = r8mat_is_identity ( nd, value );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Frobenius norm of Lagrange matrix error = %g\\n', err );\n\n return\nend\n\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/lagrange_nd/lagrange_nd_test07.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640645, "lm_q2_score": 0.8723473614033683, "lm_q1q2_score": 0.7948652073769035}}
{"text": "function c = min_errorbar_scale(stderrs,significance)\n% c = min_errorbar_scale(stderrs,significance) \n% returns the minimum scale factor c such that any pair of non-overlapping\n% error bars represents statistical significance exceeding the given level.\n% stderrs is a vector.\n% significance is a scalar.\n%\n% See \"Judging significance from error bars\" by Tom Minka (2002) \n% http://research.microsoft.com/~minka/papers/minka-errorbars.pdf\n%\n% Examples:\n% min_errorbar_scale(ones(10,1)) % returns 1.16\n% min_errorbar_scale(0:10) % returns 1.64\n\n% Written by Tom Minka\n\n% Algorithm:\n% We want c*(stderr(i)+stderr(j)) >= z*sqrt(stderr(i)^2+stderr(j)^2)\n% for all pairs (i,j). Therefore\n% c = max_(i,j) z*sqrt(stderr(i)^2+stderr(j)^2)/(stderr(i) + stderr(j));\n\nif nargin < 2\n significance = 0.95;\nend\n\nz = erfinv(2*significance - 1)*sqrt(2);\n\nn = length(stderrs);\nratio = zeros(n,1);\nfor i = 1:length(stderrs)\n exact = sqrt(stderrs(i).^2 + stderrs.^2);\n approx = stderrs(i) + stderrs;\n ratio(i) = max(exact./approx);\nend\nc = z*max(ratio);\n", "meta": {"author": "andrewssobral", "repo": "lrslibrary", "sha": "06d457349cb5f1fc56a583cd61af9f1d5150e3a1", "save_path": "github-repos/MATLAB/andrewssobral-lrslibrary", "path": "github-repos/MATLAB/andrewssobral-lrslibrary/lrslibrary-06d457349cb5f1fc56a583cd61af9f1d5150e3a1/libs/+lightspeed/graphics/min_errorbar_scale.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768557238083, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.7948323001832656}}
{"text": "function point = projPointOnLine3d(point, line)\n%PROJPOINTONLINE3D Project a 3D point orthogonally onto a 3D line.\n%\n% PT2 = projPointOnLine3d(PT, LINE).\n% Computes the (orthogonal) projection of 3D point PT onto the 3D line\n% LINE. \n% \n% Function works also for multiple points and lines. In this case, it\n% returns multiple points.\n% Point PT1 is a N-by-3 array, and LINE is a N-by-6 array.\n% Result PT2 is a N-by-3 array, containing coordinates of orthogonal\n% projections of PT1 onto lines LINE. \n%\n%\n% See also \n% projPointOnLine, distancePointLine3d\n\n% ------\n% Author: David Legland \n% E-mail: david.legland@inrae.fr\n% Created: 2012-08-23\n% Copyright 2012-2022 INRA - TPV URPOI - BIA IMASTE\n\n% direction vector of the line\nvx = line(:, 4);\nvy = line(:, 5);\nvz = line(:, 6);\n\n% difference of point with line origin\ndx = point(:,1) - line(:,1);\ndy = point(:,2) - line(:,2);\ndz = point(:,3) - line(:,3);\n\n% Position of projection on line, using dot product\ndelta = vx .* vx + vy .* vy + vz .* vz;\ntp = (dx .* vx + dy .* vy + dz .* vz) ./ delta;\n\n% convert position on line to cartesian coordinates\npoint = [line(:,1) + tp .* vx, line(:,2) + tp .* vy, line(:,3) + tp .* vz];\n", "meta": {"author": "mattools", "repo": "matGeom", "sha": "1fd2c937064be1ee1f4fd09fbfdf96145ebe5271", "save_path": "github-repos/MATLAB/mattools-matGeom", "path": "github-repos/MATLAB/mattools-matGeom/matGeom-1fd2c937064be1ee1f4fd09fbfdf96145ebe5271/matGeom/geom3d/projPointOnLine3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567177, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.794724528198949}}
{"text": "function [J, grad] = cofiCostFunc(params, Y, R, num_users, num_movies, ...\n num_features, lambda)\n %COFICOSTFUNC Collaborative filtering cost function\n % [J, grad] = COFICOSTFUNC(params, Y, R, num_users, num_movies, ...\n % num_features, lambda) returns the cost and gradient for the\n % collaborative filtering problem.\n %\n\n % Unfold the U and W matrices from params\n X = reshape(params(1:num_movies*num_features), num_movies, num_features);\n Theta = reshape(params(num_movies*num_features+1:end), ...\n num_users, num_features);\n\n\n % You need to return the following values correctly\n J = 0;\n X_Gradient = zeros(size(X));\n Theta_Gradient = zeros(size(Theta));\n\n % ====================== YOUR CODE HERE ======================\n % Instructions: Compute the cost function and gradient for collaborative\n % filtering. Concretely, you should first implement the cost\n % function (without regularization) and make sure it is\n % matches our costs. After that, you should implement the \n % gradient and use the checkCostFunction routine to check\n % that the gradient is correct. Finally, you should implement\n % regularization.\n %\n % Notes: X - num_movies x num_features matrix of movie features\n % Theta - num_users x num_features matrix of user features\n % Y - num_movies x num_users matrix of user ratings of movies\n % R - num_movies x num_users matrix, where R(i, j) = 1 if the \n % i-th movie was rated by the j-th user\n %\n % You should set the following variables correctly:\n %\n % X_grad - num_movies x num_features matrix, containing the \n % partial derivatives w.r.t. to each element of X\n % Theta_grad - num_users x num_features matrix, containing the \n % partial derivatives w.r.t. to each element of Theta\n %\n\n J_Temporary = power ((X * Theta' - Y), 2);\n J = sum (sum (J_Temporary (R == 1))) / 2 + ((lambda / 2) .* sum (sum (power (Theta, 2)))) + ((lambda / 2) .* sum (sum (power (X, 2))));\n\n X_Gradient = ((X * Theta' - Y) .* R) * Theta + lambda .* X;\n Theta_Gradient = ((X * Theta' - Y) .* R)' * X + lambda .* Theta;\n\n % =============================================================\n\n grad = [X_Gradient(:); Theta_Gradient(:)];\n\nend", "meta": {"author": "UtkarshPathrabe", "repo": "Machine-Learning-Stanford-University-Coursera", "sha": "0e5855855b5ddd475775b75bad69b47c2ebe84ef", "save_path": "github-repos/MATLAB/UtkarshPathrabe-Machine-Learning-Stanford-University-Coursera", "path": "github-repos/MATLAB/UtkarshPathrabe-Machine-Learning-Stanford-University-Coursera/Machine-Learning-Stanford-University-Coursera-0e5855855b5ddd475775b75bad69b47c2ebe84ef/Programming Exercises/machine-learning-ex8/ex8/cofiCostFunc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995703, "lm_q2_score": 0.8652240947405564, "lm_q1q2_score": 0.7946912299511192}}
{"text": "function S = randsym(n, N)\n% Generates random symmetric matrices with normal entries.\n% \n% function S = randsym(n)\n% function S = randsym(n, N)\n%\n% S is an n-by-n-by-N array where each slice S(:, :, i) for i = 1..N is a\n% random symmetric matrix with upper triangular entries distributed\n% independently following a normal distribution (Gaussian, zero mean, unit\n% variance).\n%\n% By default, N = 1.\n%\n% See also: randrot randskew randherm randskewh\n\n% This file is part of Manopt: www.manopt.org.\n% Original author: Nicolas Boumal, Oct. 23, 2018.\n% Contributors: \n% Change log: \n% Oct. 23, 2018 (NB):\n% This is not technically necessary for the rotations factory,\n% but it is counter-intuitive to have access to a function called\n% randskew yet not have one for randsym.\n% June 19, 2019 (NB):\n% Now handles the case n = 1 properly.\n\n if nargin < 2\n N = 1;\n end\n \n if n == 1\n S = randn(1, 1, N);\n return;\n end\n\n % Subindices of the (strictly) upper triangular entries of an n-by-n\n % matrix.\n [I, J] = find(triu(ones(n), 1));\n \n K = repmat(1:N, n*(n-1)/2, 1);\n \n % Indices of the strictly upper triangular entries of all N slices of\n % an n-by-n-by-N array.\n L = sub2ind([n n N], repmat(I, N, 1), repmat(J, N, 1), K(:));\n \n % Allocate memory for N random symmetric matrices of size n-by-n and\n % populate each upper triangular entry with a random number following a\n % normal distribution and copy them on the corresponding lower\n % triangular side.\n S = zeros(n, n, N);\n S(L) = randn(size(L));\n S = S + multitransp(S);\n \n % Now populate the diagonal entries:\n \n % Subindices of the diagonal entries of an n-by-n matrix.\n [I, J] = find(eye(n));\n \n K = repmat(1:N, n, 1);\n \n % Indices of the diagonal entries of all N slices of an n-by-n-by-N\n % array.\n L = sub2ind([n n N], repmat(I, N, 1), repmat(J, N, 1), K(:));\n \n S(L) = randn(size(L));\n \nend\n", "meta": {"author": "NicolasBoumal", "repo": "manopt", "sha": "b8b54a6af8b965f7ae572972ba0d15787427744b", "save_path": "github-repos/MATLAB/NicolasBoumal-manopt", "path": "github-repos/MATLAB/NicolasBoumal-manopt/manopt-b8b54a6af8b965f7ae572972ba0d15787427744b/manopt/manifolds/rotations/randsym.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.8757869819218865, "lm_q1q2_score": 0.7946122342012296}}
{"text": "function [ w, cvx_optval ] = fdla( A ) %#ok\n\n% Computes the fastest distributed linear averaging (FDLA) edge weights\n%\n% [W,S] = FDLA(A) gives a vector of the fastest distributed linear averaging\n% edge weights for a graph described by the incidence matrix A (n x m).\n% Here n is the number of nodes and m is the number of edges in the graph;\n% each column of A has exactly one +1 and one -1.\n%\n% The FDLA edge weights are given by the SDP:\n%\n% minimize s\n% subject to -s*I <= I - L - (1/n)11' <= s*I\n%\n% where the variables are edge weights w in R^m and s in R.\n% Here L is the weighted Laplacian defined by L = A*diag(w)*A'.\n% The optimal value is s, and is returned in the second output.\n%\n% For more details see the references:\n% \"Fast linear iterations for distributed averaging\" by L. Xiao and S. Boyd\n% \"Convex Optimization of Graph Laplacian Eigenvalues\" by S. Boyd\n%\n% Written for CVX by Almir Mutapcic 08/29/06\n\n[n,m] = size(A); %#ok\nI = eye(n,n);\nJ = I - (1/n) * ones(n,n);\ncvx_begin sdp\n variable w(m,1) % edge weights\n variable s % epigraph variable\n variable L(n,n) symmetric\n minimize( s )\n subject to\n L == A * diag(w) * A'; %#ok\n -s * I <= J - L <= s * I; %#ok\ncvx_end\n", "meta": {"author": "yu-jiang", "repo": "radpbook", "sha": "88b9fa7d0a541099cdd1ac29383c89e087d1d895", "save_path": "github-repos/MATLAB/yu-jiang-radpbook", "path": "github-repos/MATLAB/yu-jiang-radpbook/radpbook-88b9fa7d0a541099cdd1ac29383c89e087d1d895/tools/cvx-w64/cvx/examples/graph_laplacian/fdla.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.963779943094681, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7945998684869423}}
{"text": "function varargout = xyy2xyz(varargin)\n%XYY2XYZ Convert chromaticity coordinates to XYZ tristimulus values.\n% [X,Y,Z] = XYY2XYZ(x,y,Y) converts the chromaticity coordinates (x\n% and y) and the Y tristimulus value to the tristimulus values X, Y,\n% and Z. Y, x, y, X, Y, and Z are all arrays with the same size.\n%\n% XYZ = XYY2XYZ(xyY) performs the conversion on a Px3 input matrix\n% where P(:,1) contains the x values, P(:,2) contains the y values,\n% and P(:,3) contains the Y values. The output matrix is also Px3.\n\n% Written by Steve Eddins to accompany Digital Image Processing Using\n% MATLAB, 3rd edition, Gatesmark Press, 2020,\n% http://imageprocessingplace.com.\n%\n% Copyright 2019 The MathWorks, Inc.\n% License: https://github.com/mathworks/matlab-color-tools/blob/master/license.txt\n\nif nargin == 3\n style = \"separate\";\n x = varargin{1};\n y = varargin{2};\n Y = varargin{3};\nelseif nargin == 1\n style = \"3-column\";\n xyY = varargin{1};\n x = xyY(:,1);\n y = xyY(:,2);\n Y = xyY(:,3);\nend\n\nX = Y .* x ./ y;\nZ = Y .* (1 - x - y) ./ y;\n\n% Handle the numerical edge case where y is 0.\nX(y == 0) = 0;\nZ(y == 0) = 0;\n\nif style == \"3-column\"\n varargout{1} = [X Y Z];\nelse\n varargout{1} = X;\n varargout{2} = Y;\n varargout{3} = Z;\nend\n", "meta": {"author": "dipum", "repo": "dipum-toolbox", "sha": "9ce653c4c0c4b7c56e46194c24bf152db4ab6832", "save_path": "github-repos/MATLAB/dipum-dipum-toolbox", "path": "github-repos/MATLAB/dipum-dipum-toolbox/dipum-toolbox-9ce653c4c0c4b7c56e46194c24bf152db4ab6832/dipum/mathworksLicensedFunctions/xyy2xyz.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.7945797402462541}}
{"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n%\n% \n% Problem 8\n% Solve the difference equation \n% y[n]+1.5y[n-1]+0.5y[n-2]=x[n]+x[n-1] , x[n]=0.8^n u[n]\n\n\n\nsyms n z Y\nx=0.8^n;\nX=ztrans(x,z);\nX1=z^(-1)*X;\nY1=z^(-1)*Y;\nY2=z^(-2)*Y;\nG=Y+1.5*Y1+0.5*Y2-X-X1;\nSOL=solve(G,Y);\ny=iztrans(SOL,n)\n\n% a)\nn_s=0:20;\ny_s=subs(y,n,n_s);\nstem(n_s,y_s);\nlegend('Solution y[n]')\nxlim([-.5 20.5])\nylim([0 1.1])\n\n% b)\nxn=x;\nxn_1=0.8^(n-1);\nyn=y;\nyn_1=subs(y,n,n-1);\nyn_2=subs(y,n,n-2);\ntest=yn+1.5*yn_1+0.5*yn_2-xn-xn_1\nsimplify(test)\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/10/c108f.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377296574669, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7945691233533758}}
{"text": "function coeff = fourier_comp(func,m,L)\n%FOURIER_COMP Numerically evaluate Fourier series coefficient.\n% coeff = fourier_comp(func,m,L) tries to approximate the function func\n% from -L to L with m term Fourier series using quad (MATLAB functions).\n% func is a function handle, should accept a vector argument x and return a\n% vector result y\n% This function return a structure with these fields:\n% coeff.a0\n% coeff.an\n% coeff.bn\n% The Fourier series for function f(x) is given below.\n% inf \n% -----\n% \\\n% f(x) = a0/2 + \\ an * sin(n*pi*x/L) + bn * con(n*pi*x/L) \n% /\n% /\n% -----\n% n = 1\n% \n% Example:\n% \n% f = @(x)x.*cos(x);\n% coeff = fourier_comp(f,3,pi)\n% coeff = \n% a0: 0\n% an: [-0.5000 1.3333 -0.7500]\n% bn: [1.4136e-016 0 7.0679e-017]\n% \n% See also\n% fourier_gui\n% \n% Author: Amin Bashi\n% Created: Jul 2009\n% Copyright 2009\n\n% func must be the function handle\n\nfor n = 1:m\n an(n) = quad(@fa,-L,L)/L;\n bn(n) = quad(@fb,-L,L)/L;\nend\na0 = quad(func,-L,L)/L;\ncoeff.a0 = a0;\ncoeff.an = an;\ncoeff.bn = bn;\n function y = fa(t)\n y = func(t).*sin(n*pi*t/L);\n end\n function y = fb(t)\n y = func(t).*cos(n*pi*t/L);\n end\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/24779-fourier-series-calculator/fourier_comp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145179, "lm_q2_score": 0.8519528019683105, "lm_q1q2_score": 0.7944062123865715}}
{"text": "function a = toeplitz_5diag ( n, d1, d2, d3, d4, d5 )\n\n%*****************************************************************************80\n%\n%% TOEPLITZ_5DIAG returns a pentadiagonal Toeplitz matrix.\n%\n% Formula:\n%\n% if ( I - J == 2 )\n% A(I,J) = D1\n% elseif ( I - J == 1 )\n% A(I,J) = D2\n% elseif ( I - J == 0 )\n% A(I,J) = D3\n% elseif ( I - J == -1 )\n% A(I,J) = D4\n% elseif ( I - J == -2 )\n% A(I,J) = D5\n% else\n% A(I,J) = 0.0\n%\n% Example:\n%\n% N = 5, D1 = 1, D2 = -10, D3 = 0, D4 = 10, D5 = 1\n%\n% 0 10 1 . .\n% -10 0 10 1 .\n% 1 -10 0 10 1\n% . 1 -10 0 10\n% . . 1 -10 0\n%\n% Properties:\n%\n% A is generally not symmetric: A' /= A.\n%\n% A is Toeplitz: constant along diagonals.\n%\n% A is banded, with bandwidth 5.\n%\n% A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\n%\n% The special data D1 = 1, D2 = -10, D3 = 0, D4 = 10, D5 = 1 corresponds\n% to a matrix of Rutishauser.\n%\n% The matrix has eigenvalues lying approximately on the complex line\n% segment 2 * cos ( 2 * t ) + 20 * I * sin ( t ).\n%\n% The family of matrices is nested as a function of N.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 21 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% RM Beam, RF Warming,\n% The asymptotic spectra of banded Toeplitz and quasi-Toeplitz matrices,\n% SIAM Journal on Scientific and Statistical Computing,\n% Volume 14, Number 4, 1993, pages 971-1006.\n%\n% Heinz Rutishauser,\n% On test matrices,\n% Programmation en Mathematiques Numeriques,\n% Centre National de la Recherche Scientifique,\n% 1966, pages 349-365.\n%\n% Parameters:\n%\n% Input, integer N, the order of A. N should be at least 3.\n%\n% Input, D1, D2, D3, D4, D5, values that define the nonzero diagonals\n% of the matrix.\n%\n% Output, real A(N,N), the matrix.\n%\n a = zeros ( n, n );\n\n for i = 1 : n\n for j = 1 : n\n\n if ( i - j == 2 )\n a(i,j) = d1;\n elseif ( i - j == 1 )\n a(i,j) = d2;\n elseif ( i - j == 0 )\n a(i,j) = d3;\n elseif ( i - j == -1 )\n a(i,j) = d4;\n elseif ( i - j == -2 )\n a(i,j) = d5;\n else\n a(i,j) = 0.0;\n end\n\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/toeplitz_5diag.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145179, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.7944062106340517}}
{"text": "function [ Grid,varargout ] = CavityGridOperators( N )\n%CAVITYGRIDOPERATORS generates the grid and operators\n[Grid]=CollocationGrid_q(N); % grid coordiuantes and indices\n\nif nargout==2\n varargout{1}= CreateOperators_psi( Grid.D,eye(N+1)); % derivative matrices\nend\n\n[~,Grid.wc] = clencurt(N);\n Grid.W = kron(Grid.wc,Grid.wc); % integration coefficients for computation of Kinetic Energy\n\nend\n\nfunction [Grid]=CollocationGrid_q(N)\n\n [Grid.D,Grid.x] = cheb(N);\n [xx,yy]=meshgrid(Grid.x,Grid.x); Grid.xx=xx(:);Grid.yy=yy(:); \n \n \n \n% Index positions for walls and interior\n Grid.Walls = find(abs(xx)==1 | abs(yy)==1);\n Grid.LeftWall = find(xx==-1); Grid.RightWall=find(xx==1);\n Grid.BottomWall=find(yy==-1); Grid.TopWall=find(yy==1);\n Grid.Interior = setdiff((1:length(Grid.xx)),Grid.Walls);\n\n \n % operators\n I = eye(N+1);\n Grid.D2 = (diag(1-Grid.x.^2)*Grid.D^2 - 4*diag(Grid.x)*Grid.D - 2*I);\n Grid.D4 = (diag(1-Grid.x.^2)*Grid.D^4 - 8*diag(Grid.x)*Grid.D^3 - 12*Grid.D^2); % Trefethen style\n \n\n % Propagation function\n Grid.S0 = (1-Grid.xx.^2).*(1-Grid.yy.^2);\n Grid.S1 = Grid.S0;\n Grid.S1(Grid.Walls)=1;\n \n % plot on cheb grid\n Grid.cplot = @(X) contourf(reshape(xx,N+1,N+1),reshape(yy,N+1,N+1),reshape(X,N+1,N+1),50,'LineStyle','None');\n\nend\n\n function [x,w] = clencurt(N)\n theta = pi*(0:N)'/N; x = cos(theta);\n w = zeros(1,N+1); ii = 2:N; v = ones(N-1,1);\n if mod(N,2)==0 \n w(1) = 1/(N^2-1); w(N+1) = w(1);\n for k=1:N/2-1, v = v - 2*cos(2*k*theta(ii))/(4*k^2-1); end\n v = v - cos(N*theta(ii))/(N^2-1);\n else\n w(1) = 1/N^2; w(N+1) = w(1);\n for k=1:(N-1)/2, v = v - 2*cos(2*k*theta(ii))/(4*k^2-1); end\n end\n w(ii) = 2*v/N;\n end\n \n function [ Operators_psi ] = CreateOperators_psi( D,I)\n%CREATEOPERATORS_q creates the Operator acting on psi(x)\nOperators_psi.Dx = kron(D,I);\nOperators_psi.Dy = kron(I,D);\nD2= D^2; D4=D2^2;\nOperators_psi.del2 = kron(D2,I)+kron(I,D2);\n\nOperators_psi.del4 = kron(D4,I)+kron(I,D4)+2*kron(D2,I)*kron(I,D2);\n\n\n\nend", "meta": {"author": "arbabiha", "repo": "KoopmanMPC_for_flowcontrol", "sha": "4581c284bed5420fee7a7e9a58590fe93a196c97", "save_path": "github-repos/MATLAB/arbabiha-KoopmanMPC_for_flowcontrol", "path": "github-repos/MATLAB/arbabiha-KoopmanMPC_for_flowcontrol/KoopmanMPC_for_flowcontrol-4581c284bed5420fee7a7e9a58590fe93a196c97/thehood/CavityGridOperators.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603709, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7944062021781361}}
{"text": "function p = hen_polynomial_value ( m, n, x )\n\n%*****************************************************************************80\n%\n%% HEN_POLYNOMIAL_VALUE evaluates Hen(i,x).\n%\n% Discussion:\n%\n% Hen(i,x) is the normalized probabilist's Hermite polynomial of degree I.\n%\n% These polynomials satisfy the orthonormality condition:\n%\n% Integral ( -oo < X < +oo ) exp ( - 0.5 * X^2 ) * Hen(M,X) Hen(N,X) dX \n% = delta ( N, M )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 February 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Milton Abramowitz, Irene Stegun,\n% Handbook of Mathematical Functions,\n% National Bureau of Standards, 1964,\n% ISBN: 0-486-61272-4,\n% LC: QA47.A34.\n%\n% Frank Olver, Daniel Lozier, Ronald Boisvert, Charles Clark,\n% NIST Handbook of Mathematical Functions,\n% Cambridge University Press, 2010,\n% ISBN: 978-0521192255,\n% LC: QA331.N57.\n%\n% Parameters:\n%\n% Input, integer M, the number of evaluation points.\n%\n% Input, integer N, the highest order polynomial to compute.\n% Note that polynomials 0 through N will be computed.\n%\n% Input, real X(M,1), the evaluation points.\n%\n% Output, real P(M,N+1), the values of the polynomials of index 0 through N.\n%\n p = zeros ( m, n + 1 );\n\n p(1:m,1) = 1.0;\n\n if ( n == 0 )\n return\n end\n\n p(1:m,2) = x(1:m,1);\n \n for j = 2 : n\n p(1:m,j+1) = x(1:m,1) .* p(1:m,j) - ( j - 1 ) * p(1:m,j-1);\n end\n%\n% Normalize.\n%\n d = diag ( 1.0 ./ sqrt ( gamma ( 1:n+1) .* sqrt ( 2.0 * pi ) ) );\n\n p = p * d;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/hermite_polynomial/hen_polynomial_value.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.8705972717658209, "lm_q1q2_score": 0.7943644361176617}}
{"text": "function varargout = gabrielGraph(pts)\n%GABRIELGRAPH Gabriel Graph of a set of points.\n%\n% EDGES = gabrielGraph(PTS)\n% Computes the Gabriel graph of the input set of points PTS. The Gabriel\n% graph is based on the euclidean Delaunay triangulation, and keeps only\n% edges whose circumcircle does not contain any other input point than\n% the edge extremities.\n%\n% [NODES, EDGES] = gabrielGraph(PTS)\n% Also returns the initial set of points;\n%\n% Example\n% pts = rand(100, 2);\n% edges = gabrielGraph(pts);\n% figure; drawPoint(pts);\n% hold on; axis([0 1 0 1]); axis equal;\n% drawGraph(pts, edges);\n%\n% See also \n% graphs, drawGraph, delaunayGraph\n%\n\n% ------\n% Author: David Legland\n% E-mail: david.legland@inrae.fr\n% Created: 2012-01-22, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2012-2022 INRA - Cepia Software Platform\n\n% compute Delaunay triangulation\nif verLessThan('matlab', '8.1')\n % Code for versions before R2013a\n dt = DelaunayTri(pts); %#ok\nelse\n % Code for versions R2013a and later\n dt = delaunayTriangulation(pts);\nend\n\n% extract edges (N-by-2 array)\neds = dt.edges();\n\n% radius of the circle circumscribed to each edge\nrads = edgeLength([pts(eds(:,1), :) pts(eds(:,2), :)]) / 2;\n\n% extract middle point of each edge\nmidPts = midPoint(pts(eds(:,1), :), pts(eds(:,2), :));\n\n% distance between midpoints and all points\n% closest points should be edge vertices\ndists = minDistancePoints(midPts, pts);\n\n% geometric tolerance (adapted to point set extent)\ntol = max(max(pts) - min(pts)) * eps;\n\n% keep only edges whose circumcircle does not contain any other point\nkeep = dists >= rads - tol;\nedges = eds(keep, :);\n\n% format output depending on number of output arguments\nif nargout < 2\n varargout = {edges};\nelse\n varargout = {pts, edges};\nend\n", "meta": {"author": "mattools", "repo": "matGeom", "sha": "1fd2c937064be1ee1f4fd09fbfdf96145ebe5271", "save_path": "github-repos/MATLAB/mattools-matGeom", "path": "github-repos/MATLAB/mattools-matGeom/matGeom-1fd2c937064be1ee1f4fd09fbfdf96145ebe5271/matGeom/graphs/gabrielGraph.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.7943644330541938}}
{"text": "function fx = p01_fun ( option, nvar, x )\n\n%*****************************************************************************80\n%\n%% P01_FUN evaluates the function for problem 1.\n%\n% Title:\n%\n% The Freudenstein-Roth function\n%\n% Description:\n%\n% One way to use a continuation code as a nonlinear root finder\n% is to start with a set of nonlinear equations G(X), and an\n% approximate root A, and create a \"homotopy\" function F(X,Y)\n% with the properties that F(A,0.0) = 0 and F(X,1.0) = G(X).\n% Thus, the homotopy function F has a known exact solution\n% from which we can start with no difficulty. If the continuation\n% code can take us from Y = 0 to Y = 1, then we have found\n% an X so that F(X,1.0) = 0, so we have found a solution to G(X)=0.\n%\n% The Freudenstein-Roth function F(X) is derived in this way\n% from a homotopy of G(X):\n%\n% F ( X(1), X(2), X(3) ) =\n% G ( X(1), X(2) ) - ( 1 - X(3) ) * G ( Y1, Y2 )\n%\n% where Y1 and Y2 are some fixed values, and\n%\n% G(1) = X(1) - X(2)*X(2)*X(2) + 5*X(2)*X(2) - 2*X(2) - 13\n% G(2) = X(1) + X(2)*X(2)*X(2) + X(2)*X(2) - 14*X(2) - 29\n%\n% Options 1, 2, 3:\n%\n% The starting point is X0 = ( 15, -2, 0 ).\n%\n% A great deal of information is available about the homotopy curve\n% generated by this starting point:\n%\n% The function F(X) has the form\n%\n% F(1) = X(1) - X(2)**3 + 5*X(2)**2 - 2*X(2) - 13 + 34*(X(3)-1)\n% F(2) = X(1) + X(2)**3 + X(2)**2 - 14*X(2) - 29 + 10*(X(3)-1)\n%\n% There is a closed form representation of the curve in terms of the\n% second parameter:\n%\n% X(1) = (-11*X(2)**3 + 4*X(2)**2 + 114*X(2) + 214) / 6\n% X(2) = X(2)\n% X(3) = ( X(2)**3 - 2*X(2)**2 - 6*X(2) + 4) / 12\n%\n% The first option simply requests the production of solution points\n% along the curve until a point is reached whose third component is\n% exactly 1.\n%\n% Options 2 and 3 use the same starting point, and also stop when the\n% third component is 1. However, these options in addition search\n% for limit points in the first and third components of the solution,\n% respectively.\n%\n% The target solution has X(3) = 1, and is ( 5, 4, 1 ).\n%\n% Limit points for X1:\n%\n% ( 14.28309, -1.741377, 0.2585779 )\n% ( 61.66936, 1.983801, -0.6638797 )\n%\n% Limit points for X3:\n%\n% (20.48586, -0.8968053, 0.5875873)\n% (61.02031, 2.230139, -0.6863528)\n%\n% The curve has several dramatic bends.\n%\n%\n% Options 4, 5, and 6:\n%\n% The starting point is (4, 3, 0).\n%\n% The function F(X) has the form\n%\n% F(1) = X(1) - X(2)**3 + 5*X(2)**2 - 2*X(2) - 13 + 3*(X(3)-1)\n% F(2) = X(1) + X(2)**3 + X(2)**2 - 14*X(2) - 29 - 31*(X(3)-1)\n%\n% There is a closed form representation of the curve in terms of the\n% second parameter:\n%\n% X(1) = (14*X(2)**3 -79*X(2)**2 +52*X(2) + 245) / 17\n% X(2) = X(2)\n% X(3) = ( X(2)**3 - 2*X(2)**2 - 6*X(2) + 9) / 17\n%\n% The correct value of the solution at X(3)=1 is:\n%\n% (5, 4, 1)\n%\n% In option 5, limit points in the first component are sought,\n% and in option 6, limit points in the third component are\n% sought.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 September 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Ferdinand Freudenstein, Bernhard Roth,\n% Numerical Solutions of Nonlinear Equations,\n% Journal of the Association for Computing Machinery,\n% Volume 10, 1963, Pages 550-556.\n%\n% Parameters:\n%\n% Input, integer OPTION, the option index.\n%\n% Input, integer NVAR, the number of variables.\n%\n% Input, real X(NVAR), the argument of the function.\n%\n% Output, real FX(NVAR-1), the value of the function at X.\n%\n\n% Get the starting point, Y.\n%\n y = p01_start ( option, nvar );\n%\n% G is the function value at the starting point,\n% F the function value at the current point.\n%\n gy = p01_gx ( y );\n\n gx = p01_gx ( x );\n%\n% The parameter X3 generates the homotopy curve.\n%\n fx(1:nvar-1) = gx(1:nvar-1) + ( x(3) - 1.0 ) * gy(1:nvar-1);\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_con/p01_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.8705972768020108, "lm_q1q2_score": 0.7943644282749952}}
{"text": "function value = i4_rise ( x, n )\n\n%*****************************************************************************80\n%\n%% I4_RISE computes the rising factorial function [X]^N.\n%\n% Discussion:\n%\n% [X]^N = X * ( X + 1 ) * ( X + 2 ) * ... * ( X + N - 1 ).\n%\n% Note that the number of ways of arranging N objects in M ordered\n% boxes is [M]^N. (Here, the ordering of the objects in each box matters).\n% Thus, 2 objects in 2 boxes have the following 6 possible arrangements:\n%\n% -|12, 1|2, 12|-, -|21, 2|1, 21|-.\n%\n% Moreover, the number of non-decreasing maps from a set of\n% N to a set of M ordered elements is [M]^N / N!. Thus the set of\n% nondecreasing maps from (1,2,3) to (a,b,c,d) is the 20 elements:\n%\n% aaa, abb, acc, add, aab, abc, acd, aac, abd, aad\n% bbb, bcc, bdd, bbc, bcd, bbd, ccc, cdd, ccd, ddd.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 21 November 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer X, the argument of the rising factorial function.\n%\n% Input, integer N, the order of the rising factorial function.\n% If N = 0, RISE = 1, if N = 1, RISE = X. Note that if N is\n% negative, a \"falling\" factorial will be computed.\n%\n% Output, integer VALUE, the value of the rising factorial function.\n%\n value = 1;\n\n arg = x;\n\n if ( 0 < n )\n\n for i = 1 : n\n value = value * arg;\n arg = arg + 1;\n end\n\n elseif ( n < 0 )\n\n for i = -1 : -1 : n\n value = value * arg;\n arg = arg - 1;\n end\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/i4_rise.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147438, "lm_q2_score": 0.8705972667296309, "lm_q1q2_score": 0.7943644232305478}}
{"text": "function Z = xkron(X,Y)\n%XKRON Kronecker tensor product.\n%\n% XKRON(X,Y), where X and Y are matrices, is the Kronecker tensor product\n% of X and Y. The result is a large matrix formed by taking all possible\n% products between the elements of X and those of Y.\n%\n% For example, if X is 2-by-3, and Y is any N-dimensional array, then\n% KRON(X,Y) is\n%\n% [ X(1,1)*Y X(1,2)*Y X(1,3)*Y\n% X(2,1)*Y X(2,2)*Y X(2,3)*Y ]\n%\n% If either X or Y is sparse, and neither X nor Y has dimension\n% greater than 2, then only nonzero elements are multiplied in the\n% computation, and the result is sparse.\n%\n% XKRON works also when X and/or Y are N-dimensional arrays. There does\n% not seem to be a unique definition of an N-dimensional Kronecker tensor\n% product, so I simply picked the one I found most logical.\n%\n% If X is 3-by-4-by-2, and Y is any N-dimensional array, then\n%\n% cat( 3, [ X(1,1,1)*Y X(1,2,1)*Y X(1,3,1)*Y X(1,4,1)*Y ; ...\n% X(2,1,1)*Y X(2,2,1)*Y X(2,3,1)*Y X(2,4,1)*Y ; ...\n% X(3,1,1)*Y X(3,2,1)*Y X(3,3,1)*Y X(3,4,1)*Y ], ...\n% [ X(1,1,2)*Y X(1,2,2)*Y X(1,3,2)*Y X(1,4,2)*Y ; ...\n% X(2,1,2)*Y X(2,2,2)*Y X(2,3,2)*Y X(2,4,2)*Y ; ...\n% X(3,1,2)*Y X(3,2,2)*Y X(3,3,2)*Y X(3,4,2)*Y ] )\n\n% Author: Peter J. Acklam\n% Time-stamp: 2002-03-03 13:50:29 +0100\n% E-mail: pjacklam@online.no\n% URL: http://home.online.no/~pjacklam\n\n xs = size(X);\n ys = size(Y);\n xd = length(xs);\n yd = length(ys);\n\n if ( issparse(X) | issparse(Y) ) & ( xd <= 2 ) & ( yd <= 2 )\n\n % When at least one input is sparse, and neither argument has\n % dimension greater than 2, the result is sparse.\n\n mx = xs(1); nx = xs(2);\n my = ys(1); ny = ys(2);\n\n [ix, jx, sx] = find(X);\n [iy, jy, sy] = find(Y);\n ix = ix(:); jx = jx(:); sx = sx(:);\n iy = iy(:); jy = jy(:); sy = sy(:);\n kx = ones(size(sx));\n ky = ones(size(sy));\n t = my*(ix-1)';\n ik = t(ky,:)+iy(:,kx);\n t = ny*(jx-1)';\n jk = t(ky,:)+jy(:,kx);\n Z = sparse(ik, jk, sy*sx.', mx*my, nx*ny);\n\n else\n\n dz = max(xd, yd);\n xs = [ xs ones(1,dz-xd) ];\n ys = [ ys ones(1,dz-yd) ];\n\n v = reshape( reshape( 1:2*dz, dz, 2 )', 1, 2*dz );\n Z = reshape( Y(:)*X(:).', [ ys xs ] );\n Z = reshape( permute( Z, v ), xs.*ys );\n\n end\n", "meta": {"author": "CovertLab", "repo": "WholeCell", "sha": "6cdee6b355aa0f5ff2953b1ab356eea049108e07", "save_path": "github-repos/MATLAB/CovertLab-WholeCell", "path": "github-repos/MATLAB/CovertLab-WholeCell/WholeCell-6cdee6b355aa0f5ff2953b1ab356eea049108e07/lib/util/matutil/xkron.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.8705972616934408, "lm_q1q2_score": 0.794364422781302}}
{"text": "function geometry_test20325 ( )\n\n%*****************************************************************************80\n%\n%% TEST20325 tests TETRAHEDRON_SIZE_3D, TETRAHEDRON_SHAPE_3D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 July 2007\n%\n% Author:\n%\n% John Burkardt\n%\n dim_num = 3;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST20325\\n' );\n fprintf ( 1, ' For the tetrahedron,\\n' );\n fprintf ( 1, ' TETRAHEDRON_SIZE_3D returns dimension information;\\n' );\n fprintf ( 1, ' TETRAHEDRON_SHAPE_3D returns face and order info.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' We will use this information to compute the\\n' );\n fprintf ( 1, ' areas and centers of each face.\\n' );\n\n [ point_num, edge_num, face_num, face_order_max ] = ...\n tetrahedron_size_3d ( );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Number of points = %d\\n', point_num );\n fprintf ( 1, ' Number of edges = %d\\n', edge_num );\n fprintf ( 1, ' Number of faces = %d\\n', face_num );\n fprintf ( 1, ' Maximum face order = %d\\n', face_order_max );\n\n [ point_coord, face_order, face_point ] = ...\n tetrahedron_shape_3d ( point_num, face_num, face_order_max );\n\n shape_print_3d ( point_num, face_num, face_order_max, ...\n point_coord, face_order, face_point );\n%\n% Compute the area of each face.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Face Order Area\\n' );\n fprintf ( 1, '\\n' );\n\n for face = 1 : face_num\n\n for j = 1 : face_order(face)\n point = face_point(j,face);\n v(1:dim_num,j) = point_coord(1:dim_num,point);\n end\n\n [ area, normal ] = polygon_area_3d ( face_order(face), v );\n\n fprintf ( 1, ' %6d %5d %8f\\n', face, face_order(face), area );\n\n end\n%\n% Find the center of each face.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Face Center\\n' );\n fprintf ( 1, '\\n' );\n\n for i = 1 : face_num\n\n vave(1:dim_num) = 0.0;\n\n for j = 1 : face_order(i)\n k = face_point(j,i);\n vave(1:dim_num) = vave(1:dim_num) + point_coord(1:dim_num,k)';\n end\n\n vave(1:dim_num) = vave(1:dim_num) / face_order(i);\n\n fprintf ( 1, ' %6d %10f %10f %10f\\n', i, vave(1:dim_num) );\n\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/geometry_test20325.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.8705972600147106, "lm_q1q2_score": 0.7943644212495679}}
{"text": "function v = r8vec_house_column ( n, a, k )\n\n%*****************************************************************************80\n%\n%% R8VEC_HOUSE_COLUMN defines a Householder premultiplier that \"packs\" a column.\n%\n% Discussion:\n%\n% The routine returns a vector V that defines a Householder\n% premultiplier matrix H(V) that zeros out the subdiagonal entries of\n% column K of the matrix A.\n%\n% H(V) = I - 2 * v * v'\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 January 2015\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix A.\n%\n% Input, real A(N,1), column K of the matrix A.\n%\n% Input, integer K, the column of the matrix to be modified.\n%\n% Output, real V(N,1), a vector of unit L2 norm which defines an\n% orthogonal Householder premultiplier matrix H with the property\n% that the K-th column of H*A is zero below the diagonal.\n%\n\n%\n% Destroy all row vectors!\n%\n a = a(:);\n\n v(1:n,1) = 0.0;\n\n if ( k < 1 || n <= k )\n return\n end\n\n s = sqrt ( sum ( a(k:n,1).^2 ) );\n\n if ( s == 0.0 )\n return\n end\n\n if ( a(k,1) < 0.0 )\n v(k,1) = a(k,1) - abs ( s ) ;\n else\n v(k,1) = a(k,1) + abs ( s );\n end\n v(k+1:n,1) = a(k+1:n,1);\n\n s = sqrt ( sum ( v(k:n,1).^2 ) );\n v(k:n,1) = v(k:n,1) / s;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_mat/r8vec_house_column.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.8670357598021708, "lm_q1q2_score": 0.7942997909088729}}
{"text": "function [ pn, dist ] = circle_imp_point_near_2d ( r, center, p )\n\n%*****************************************************************************80\n%\n%% CIRCLE_IMP_POINT_NEAR_2D: nearest ( implicit circle, point ) in 2D.\n%\n% Discussion:\n%\n% This routine finds the distance from a point to an implicitly\n% defined circle, and returns the point on the circle that is\n% nearest to the given point.\n%\n% If the given point is the center of the circle, than any point\n% on the circle is \"the\" nearest.\n%\n% An implicit circle in 2D satisfies the equation:\n%\n% ( X - CENTER(1) )**2 + ( Y - CENTER(2) )**2 = R**2\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 10 April 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R, the radius of the circle.\n%\n% Input, real CENTER(2), the center of the circle.\n%\n% Input, real P(2), the point to be checked.\n%\n% Output, real PN(2), the nearest point on the circle.\n%\n% Output, real DIST, the distance of the point to the circle.\n%\n ndim = 2;\n\n if ( p(1:ndim) == center(1:ndim) )\n dist = r;\n pn(1:ndim) = center(1:ndim) + r / sqrt ( ndim );\n return\n end\n\n r2 = sqrt ( sum ( ( p(1:ndim) - center(1:ndim) ).^2 ) );\n\n dist = abs ( r2 - r );\n\n pn(1:ndim) = center(1:ndim) + r * ( p(1:ndim) - center(1:ndim) ) / r2;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_triangulation/circle_imp_point_near_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.7942997846138194}}
{"text": "%% DEMO of vectorization of elementwise matrix vector multiplication in MATLAB\n% D(i,:,:) is a 3x3 or 2x2 matrix on the i-th element\n% D can be the tensorial diffusion coefficient of a PDE\n% v(i,:) is a 3x1 or 2x1 vector on the i-th element\n% v can be the elementwise gradient of a certain nodal basis, e.g., \n% v(i,:) = Dphi(i,:,k) which is the k-th nodal basis's gradient\n% We want to compute b(i,:) = D(i,:,:)*v(i,:)\n% Even though MATLAB greatly improves the efficiency of for loop after 2016b\n% using built-in vectorization operation is still faster.\n% Depending on your computer the speed up is about 100x to 150x.\n%\n% see also Maxwell\n\n%% set up mesh and gradient matrix\n[node,elem] = cubemesh([0,1,0,1,0,1],1/32);\ncenter = (node(elem(:,1),:) + node(elem(:,2),:) + ...\n node(elem(:,3),:) + node(elem(:,4),:))/4;\nDlambda = gradbasis3(node,elem);\nfprintf('\\nSize of gradient of lambda (%d, %d, %d)\\n', size(Dlambda));\nNT = size(elem,1);\n\n%% set up coefficient matrix (unfortunately arrayfun is not vectorization)\ntic;\nc = @(p) [1+p(:,1).^2/10 p(:,1).*p(:,2) 0.*p(:,1); ...\n p(:,1).*p(:,2) 1+p(:,2).^2/10 0*p(:,2); ...\n 0*p(:,2) 0*p(:,2) 1+p(:,3).^2/10];\ntmp = arrayfun(@(rowidx) c(center(rowidx,:)), 1:size(center,1), 'UniformOutput',0);\nc2elem = cat(3,tmp{:});\nc2elem = permute(c2elem,[3,1,2]); \n% permute switch the element idx to the 1st dim\n% if the Dlambda tensor has D(:,:,j) corresponds to the j-th element\n% then this operation is not neccessary\nfprintf('Time to generate elementwise coefficient matrix %5.4g s\\n',toc);\n\n%% benchmark the elementwise product\ntic;\nb = zeros(NT,3,4);\nfor j = 1:4\n for i = 1:size(elem,1)\n b(i,:,j) = Dlambda(i,:,j)*squeeze(c2elem(i,:,:));\n end\nend\nt1 = toc;\nfprintf('Time to perform elementwise operation %5.4g s\\n',t1);\n\n\n%% benchmark the vectorized routine\ntic;\nb = zeros(NT,3,4);\nfor j = 1:4\n b(:,:,j) = sum(bsxfun(@times, c2elem, Dlambda(:,:,j)), 2);\nend\nt2= toc;\nfprintf('Time to perform vectorized operation %5.4g s\\n',t2);\nfprintf('Speed up factor is %4d.\\n', floor(t1/t2));\n\n%% benchmark the vectorized routine\n% label for K 1 4 6\n% 4 2 5\n% 5 6 3\n\ntic;\nK(:,4) = center(:,1).*center(:,2);\nK(:,3) = 1+center(:,3).^2/10;\nK(:,1) = 1+center(:,1).^2/10;\nK(:,2) = 1+center(:,2).^2/10;\ntoc;\n\ntic;\n% b1 = K1*D1 + K4*D2 + K6*D3\n% b2 = K4*D1 + K2*D2 + K5*D3\n% b3 = K5*D1 + K6*D2 + K3*D3\nb = zeros(NT,3,4);\nfor j = 1:4\n b(:,1,j) = K(:,1).*Dlambda(:,1,j) + K(:,4).*Dlambda(:,3,j);\n b(:,2,j) = K(:,4).*Dlambda(:,1,j) + K(:,2).*Dlambda(:,2,j);\n b(:,3,j) = K(:,3).*Dlambda(:,3,j);\nend\nt3= toc;\nfprintf('Time to perform vectorized operation %5.4g s\\n',t3);\nfprintf('Speed up factor is %4d.\\n', floor(t1/t3));\n\n", "meta": {"author": "lyc102", "repo": "ifem", "sha": "29f31c812001ca8d93dad08e67208ca60e8716d4", "save_path": "github-repos/MATLAB/lyc102-ifem", "path": "github-repos/MATLAB/lyc102-ifem/ifem-29f31c812001ca8d93dad08e67208ca60e8716d4/research/polyFEM/demoTensorProd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921841290738, "lm_q2_score": 0.8615382094310355, "lm_q1q2_score": 0.7942708923809857}}
{"text": "function lp = lagrange_derivative ( nd, xd, ni, xi ) \n\n%*****************************************************************************80\n%\n%% LAGRANGE_DERIVATIVE evaluates the derivative of the Lagrange basis polynomials.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 November 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer ND, the number of data points.\n%\n% Input, real XD(ND,1), the data nodes.\n%\n% Input, integer NI, the number of evaluation points.\n%\n% Input, real XI(NI,1), the evaluation points.\n%\n% Output, real LP(NI,ND), the value, at the I-th point XI, of the\n% Jth basis function.\n%\n lp = zeros ( ni, nd );\n \n for i = 1 : ni\n for j = 1 : nd\n\n for j1 = 1 : nd\n\n if ( j1 ~= j )\n p = 1.0;\n for j2 = 1 : nd\n if ( j2 == j1 )\n p = p / ( xd(j) - xd(j2) );\n elseif ( j2 ~= j )\n p = p * ( xi(i) - xd(j2) ) / ( xd(j) - xd(j2) );\n end\n end\n lp(i,j) = lp(i,j) + p;\n end\n\n end\n\n end\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/fem1d_lagrange/lagrange_derivative.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218262741297, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7942708843599218}}
{"text": "%%****************************************************************\n%% orthbasis: Compute an orthonomal basis from \n%% the power basis {I,A,A^2, .... ,A^m}\n%% via an Arnoldi-type iteration. \n%%\n%% [Q,H,C] = orthbasis(A,m);\n%% \n%% Output: Q = a cell array containing the orthonormal basis\n%% obtained from {I,A,A^2, .... ,A^m}. \n%%\n%% use in chebymat.m, igmres.m\n%%\n%% SDPT3: version 3.0 \n%% Copyright (c) 1997 by\n%% K.C. Toh, M.J. Todd, R.H. Tutuncu\n%% Last modified: 2 Feb 01\n%%****************************************************************\n\n function [Q,H,C] = orthbasis(A,m);\n\n N = length(A); \n C(1,1) = 1/sqrt(N); \n Q = cell(1,m+1); \n Q{1} = eye(N)/sqrt(N); \n for k = 1:m\n V = A*Q{k}; \n Vold = V; \n for j = 1:k\n H(j,k) = sum(sum(conj(Q{j}).*V)); \n V = V - H(j,k)*Q{j};\n end; \n if (norm(V,'fro') < norm(Vold,'fro')); \n for j = 1:k\n s(j,1) = sum(sum(conj(Q{j}).*V));\n V = V - s(j)*Q{j}; \n end; \n H(1:k,k) = H(1:k,k) + s; \n end; \n nrm = norm(V,'fro'); \n H(k+1,k) = nrm;\n Q{k+1} = V/nrm; \n C(1:k+1,k+1) = ([0; C(1:k,k)] - [C(1:k,1:k)*H(1:k,k); 0])/nrm; \n end; \n%%================================================================\n\n\n\n", "meta": {"author": "zarathustr", "repo": "LibQPEP", "sha": "99e5c23e746ace0bac4a86742c31db6fcf7297ba", "save_path": "github-repos/MATLAB/zarathustr-LibQPEP", "path": "github-repos/MATLAB/zarathustr-LibQPEP/LibQPEP-99e5c23e746ace0bac4a86742c31db6fcf7297ba/MATLAB/sdpt3/Examples/orthbasis.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409308, "lm_q2_score": 0.8499711794579722, "lm_q1q2_score": 0.7942089583847386}}
{"text": "function quad = fibonacci_lattice_q1 ( k, f )\n\n%*****************************************************************************80\n%\n%% FIBONACCI_LATTICE_Q1 applies a Fibonacci lattice integration rule in 2D.\n%\n% Discussion:\n%\n% This is a modification of the algorithm in FIBONACCI_LATTICE_Q.\n% It uses a nonlinear transformation on the integrand, which makes\n% the lattice rule more suitable for nonperiodic integrands.\n%\n% The transformation replaces the integration variable X by\n%\n% PHI(X) = 3*X^2 - 2*X**3\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 November 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Ian Sloan, Stephen Joe,\n% Lattice Methods for Multiple Integration,\n% Oxford, 1994,\n% ISBN: 0198534728,\n% LC: QA311.S56\n%\n% Parameters:\n%\n% Input, integer K, the index of the Fibonacci number to be used.\n% K must be at least 3.\n%\n% Input, external real F, the name of the user-supplied routine\n% which evaluates the function, of the form:\n% function f ( dim_num, x )\n% integer dim_num\n% real f\n% real x(dim_num)\n% f = ...\n%\n% Output, real QUAD, the estimated integral.\n%\n dim_num = 2;\n\n quad = 0.0;\n\n m = fibonacci ( k );\n\n z(1) = 1;\n z(2) = fibonacci ( k - 1 );\n\n for j = 0 : m - 1\n x(1:dim_num) = mod ( j * z(1:dim_num) / m, 1.0 );\n dphi = 1.0;\n for i = 1 : dim_num\n y(i) = ( 3.0 - 2.0 * x(i) ) * x(i) * x(i);\n dphi = dphi * 6.0 * ( 1.0 - x(i) ) * x(i);\n end\n quad = quad + f ( dim_num, y ) * dphi;\n end\n\n quad = quad / m;\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/lattice_rule/fibonacci_lattice_q1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.794208957939303}}
{"text": "classdef DirichletD\n%%DIRICHLETD Functions to handle the Dirichlet distribution.\n%Implemented methods are: mean, cov, PDF, rand\n%\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nmethods(Static)\n \nfunction val=mean(alph)\n%%MEAN Obtain the mean of the Dirichlet distribution for the given\n% concentration parameters.\n%\n%INPUTS: alph An NX1 vector of positive, real concentration parameters.\n% The length of alpha determines the length of the random\n% vector. If one wishes for the mean of all of the parameters\n% to be equal, then just set alph to all ones.\n%\n%OUTPUTS: val The mean of the Dirichlet distribution under consideration.\n%\n%October 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n val=alph/sum(alph);\nend\n\nfunction covMat=cov(alph)\n%%VAR Obtain the covariance matrix of the Dirichlet distribution for the\n% given concentration parameters.\n%\n%INPUTS: alph An NX1 vector of positive, real concentration parameters. The\n% length of alpha determines the length of the random vector.\n% If one wishes for the mean of all of the parameters to be\n% equal, then just set alph to all ones.\n%\n%OUTPUTS: covMat The covariance matrix of the Dirichlet distribution under\n% consideration.\n%\n%Note that since the elements of the Dirichlet random variable must sum to\n%one (i.e. are somewhat dependent), the covariance matrix is singular.\n%\n%October 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n numVals=length(alph);\n alpha0=sum(alph);\n denom=alpha0^2*(alpha0+1);\n \n %First, fill in the diagonal elements.\n covMat=diag(alph.*(alpha0-alph)/denom);\n \n %Then, fill in the off-diagonal elements.\n for curRow=1:numVals\n for curCol=(curRow+1):numVals\n covMat(curRow,curCol)=-alph(curRow)*alph(curCol)/denom;\n covMat(curCol,curRow)=covMat(curRow,curCol);\n end\n end\nend\n \nfunction val=PDF(X,alph)\n%%PDF Evaluate the PDF of the Dirichlet distribution at a particular vector\n% for the given concentration parameters.\n%\n%INPUTS: X An NX1 dirichlet random variable. Its elements must sum to one.\n% alph An NX1 vector of positive, real concentration parameters. If one\n% wishes for the mean of all of the parameters to be equal, then\n% just set alph to all ones.\n%\n%OUTPUTS: val The value of the Dirichlet distribution at X given alph.\n%\n%The Dirichlet distribution is given in Appendix B of [1].\n%\n%REFERENCES:\n%[1] C. M. Bishop, Pattern Recognition and Machine Learning. Cambridge,\n% United Kingdom: Springer, 2007.\n%\n%October 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n C=gamma(sum(alph))/prod(gamma(alph));\n val=C*prod(X.^(alph-1));\nend\n\nfunction val=rand(alph)\n%%RAND Generate a Dirichlet random vector with concentration vector\n% parameter vector alpha.\n%\n%INPUTS: alph An NX1 vector of positive, real concentration parameters. The\n% length of alpha determines the length of the random vector\n% generated. If one wishes for the mean of all of the\n% parameters to be equal, then just set alph to all ones.\n%\n%OUTPUTS: val An NX1 Dirichlet random vector.\n%\n%Dirichlet random vectors have elements that sum to one and whose\n%elements are bounded between 0 and 1. Thus, Dirichlet random vectors are\n%useful for generating weights for random mixture distributions.\n%\n%The Dirichlet random vector is generated by transforming a set of gamma\n%distributed random variables. The relationship between the Dirichlet\n%distribution and the gamma distribution is discussed in [1].\n%\n%REFERENCES:\n%[1] B. A. Frigyik, A. Kapila, and M. R. Gupta, \"Introduction to the\n% Dirichlet Distribution and Related processes\", University of\n% Washington Technical Report, No. UWEETR-20-0006, Dec. 2010.\n% https://www.ee.washington.edu/techsite/papers/documents/UWEETR-2010-0006.pdf\n%\n%October 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n numVals=length(alph);\n gVals=zeros(numVals,1);\n for curVal=1:numVals\n gVals(curVal)=randGamma(1,alph(curVal),1);\n end\n \n val=gVals/sum(gVals);\nend\n \nend\nend\n\n%LICENSE:\n%\n%The source code is in the public domain and not licensed or under\n%copyright. The information and software may be used freely by the public.\n%As required by 17 U.S.C. 403, third parties producing copyrighted works\n%consisting predominantly of the material produced by U.S. government\n%agencies must provide notice with such work(s) identifying the U.S.\n%Government material incorporated and stating that such material is not\n%subject to copyright protection.\n%\n%Derived works shall not identify themselves in a manner that implies an\n%endorsement by or an affiliation with the Naval Research Laboratory.\n%\n%RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE\n%SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY THE NAVAL\n%RESEARCH LABORATORY FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS\n%OF RECIPIENT IN THE USE OF THE SOFTWARE.\n", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Statistics/Distributions/DirichletD.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.8740772302445241, "lm_q1q2_score": 0.7942022125387219}}
{"text": "function sysdfod=dfod3(n,T,r)\n%\n% sysdfod=dfod3(n,T,r): digital fractional - order differentiator (r > 0)\n% and integrator (r < 0) in form of the IIR filter; \n% Recommended restriction for order r: (-1 < r < 1)\n% Output: =>\n% Discrete system in the form of the IIR filter of the given order 'n'\n% obtained by power series expansion of the trapezoidal (Tustin) rule.\n%\n% Inputs: <=\n% n: order of truncation (min. n = 20 is recommended) --> filter order\n% T: sampling period in [sec]\n% r: approximated fractional order (s^r), r is an arbitrary real number\n%\n% Copyright (c), 2011, Ivo Petras (ivo.petras@tuke.sk)\n%\n% Note: It requires a Matlab Control System Toolbox (->FILT function<-)\n% \n% Example: fractional half order integrator for T=0.1 sec and n = 20 :\n% >> FHOI=dfod3(20, 0.1, -0.5); bode(FHOI); figure; step(FHOI);\n\nbcN(1)=1.0; bcD(1)=1.0;\nfor i=1:n\n bcN(i+1)=((-1)^i)*(gamma(abs(r)+1)./(gamma(i+1).*gamma(abs(r)-i+1))); \n bcD(i+1)=gamma(abs(r)+1)./(gamma(i+1).*gamma(abs(r)-i+1));\nend\nif r>=0\n sysdfod=((2/T)^r)*(filt(bcN,bcD,T));\nend\nif r<0\n sysdfod=((2/T)^r)*(filt(bcD,bcN,T));\nend\n%", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/31358-digital-fractional-order-differentiator-and-integrator-new-iir-type/dfod3.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305339244013, "lm_q2_score": 0.8244619328462579, "lm_q1q2_score": 0.7941469077758448}}
{"text": "%% Examples of Numerical Solutions of PDEs\n% We shall use a sequence of examples to introduce basic components of\n% numerical solutions of PDEs.\n\n%% Smooth solutions on regular domains\n% We solve the Poisson equation $-\\Delta u =1$ in the unit square $\\Omega =\n% (0,1)\\times (0,1)$ with homogenous Dirichlet boundary condition\n% $u|_{\\partial \\Omega}=0$ using linear finite element discrization on a\n% sequence of uniform and structured grids.\n\nclose all; clear all\nfigure(1); set(gcf,'Units','normal'); set(gcf,'Position',[0,0,0.45,0.3]);\nnode = [0,0; 1,0; 1,1; 0,1]; % nodes\nelem = [2,3,1; 4,1,3]; % elements\nsubplot(1,3,1); showmesh(node,elem)\n[node,elem] = uniformrefine(node,elem);\nsubplot(1,3,2); showmesh(node,elem)\n[node,elem] = uniformrefine(node,elem);\nsubplot(1,3,3); showmesh(node,elem)\n\n%%\nsquarePoisson\n% See squarePoisson for details of computation.\n\n%% Smooth solutions on irregular domains\n% We solve the Poisson equation in a Lake-type domain. This example shows\n% the flexibility of FEM to complex domains.\n\nload lakemesh\nf = inline('ones(size(x,1),1)'); % right hand side\ng_D = inline('zeros(size(x,1),1)'); % Dirichlet boundary condition\nu = Poisson(node,elem,[],f,g_D,[]); % Poisson equation\n% graphic\nfigure(1); set(gcf,'Units','normal'); set(gcf,'Position',[0,0,0.45,0.3]);\nsubplot(1,2,1); showmesh(node,elem); pause(0.05)\nsubplot(1,2,2); showsolution(node,elem,u,[0,90]);axis equal; colorbar;\n\n%% Tutorial of iFEM \n\n%% Features of iFEM\n% \n% * Simple data structures\n% * Mesh adaptation in two- and three-dimensions\n% * Fast solvers of algebraic equations\n% * Easy to use, Easy to code, Easy to debug\n% * Efficient programming\n\n%% Basic Data Stucture\n%\n% *Mesh: node and elem.* \n%\n% Two matrices |node(1:N,1:d)| and |elem(1:NT,1:d+1)| are used to represent\n% a d-dimensional triangulation embedded in $R^d$, where |N| is the number\n% of vertices and |NT| is the number of elements. \n% \n% |node(k,1)| and |node(k,2)| are the x- and y-coordinates of the k-th node\n% for points in 2-D. In 3-D, |node(k,3)| gives the additional z-coordinates\n% of the k-th node.\n%\n% |elem(t,1:d+1)| are the global indices of |d+1| vertices which form the\n% abstract $d$-simplex |t|. By convention, the vertices of a simplex is ordered\n% such that the signed volume is positive. Therefore in 2-D, three vertices\n% of a triangle is ordered counterclockwise and in 3-D, the ordering of\n% vertices follows the right-hand rule.\n% \n% Related functions: ,\n% , \n%\n% Documentation: \n\nclear all; close all;\n\n%%\n% *Example: L-shape domain in 2-D.*\n\nnode = [1,0; 1,1; 0,1; -1,1; -1,0; -1,-1; 0,-1; 0,0]; \nelem = [1,2,8; 3,8,2; 8,3,5; 4,5,3; 7,8,6; 5,6,8]; \nfigure(1)\nshowmesh(node,elem)\naxis on\nfindnode(node)\nfindelem(node,elem)\n\n%%\n% *Example: Cube in 3-D.*\n\nnode = [-1,-1,-1; 1,-1,-1; 1,1,-1; -1,1,-1; -1,-1,1; 1,-1,1; 1,1,1; -1,1,1]; \nelem = [1,2,3,7; 1,6,2,7; 1,5,6,7; 1,8,5,7; 1,4,8,7; 1,3,4,7];\nfigure(2)\nshowmesh3(node,elem,[],'FaceAlpha',0.25);\nview([-53,8]);\naxis on\nfindnode3(node)\nfindelem3(node,elem)\n\n%%\n% *Boundary: bdEdge or bdFace.* \n%\n% For 2-D triangulations, we use |bdEdge(1:NT,1:3)| to record the type of\n% three edges of each element. Similarly in 3-D, we use |bdFace(1:NT,1:4)|\n% to record the type of four faces of each element. \n% The value is the type of boundary condition listed as follows.\n%\n% * 0: non-boundary, i.e., an interior edge or face.\n% * 1: first type, i.e., a Dirichlet boundary edge or face. \n% * 2: second type, i.e., a Neumann boundary edge or face. \n% * 3: third type, i.e., a Robin boundary edge or face.\n%\n% We label three edges of a triangle such that |bdEdge(t,i)| is the edge\n% opposite to the i-th vertex. Similarly |bdFace(t,i)| is the face opposite\n% to the i-th vertex.\n%\n% Related functions: ,\n% , \n% .\n%\n% Documentation: \n\nnode = [1,0; 1,1; 0,0];\nelem = [1 2 3];\nedge = [2 3; 1 3; 1 2];\nsubplot(1,2,1);\nshowmesh(node,elem);\nfindedge(node,edge);\nfindnode(node);\nnode = [1,1,1; 0,0,0; 1,1,0; 1,0,0];\nelem = [1,2,3,4];\nsubplot(1,2,2);\nshowmesh3(node,elem,[],'FaceAlpha',0.35); view([-10,18]);\nfindnode3(node);\nfindelem3(node,[2,3,4; 1,3,4; 1,2,4; 1,2,3])\n\n%% Finite Element Method\n%\n%\n%% \n% * Example 1: The Poisson equation in 2-D\n% * Example 2: The Poisson equation: complex domains\n% * Example 2: The Poisson equation in 3-D with multigrid solvers\n\n%% Adaptive Finite Element Method\n%\n%\n%% \n% * Example 1: The Poisson equation on a 2-D L-shaped domain\n% * Example 2: The Poisson equation in 3-D with jump diffusion coefficients\n\n%% Time-dependent Problems\n%% \n% * Example 1: Heat equation\n% * Example 2: Moving interface\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/iFEM/doc/temp/examples.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8902942232112239, "lm_q1q2_score": 0.7939742270693447}}
{"text": "function [node,elem] = cubehexmesh(cube,h)\n%% CUBEHEXMESH uniform mesh of cube\n%\n% [node,elem] = cubehexmesh([x0,x1,y0,y1,z0,z1],h) generates a uniform\n% cubic mesh of the cube [x0,x1]*[y0,y1]*[z0,z1] with mesh size h.\n%\n% Example\n% [node,elem] = cubehexmesh([0 1 0 2 0 3],0.5);\n%\n% See also: squarequadmesh, cubehexgradmesh\n%\n% Copyright (C) Long Chen. See COPYRIGHT.txt for details. \n\nx0 = cube(1); x1 = cube(2); \ny0 = cube(3); y1 = cube(4);\nz0 = cube(5); z1 = cube(6);\n[z,x,y] = ndgrid(z0:h:z1,x0:h:x1,y0:h:y1);\nnode = [x(:),y(:),z(:)];\n% findnode3(node); view([83 10]);\n\n%% Generate elements\nni = size(x,1); % number of rows\nnj = size(x,2); % number of columns\nnk = size(x,3); % number of pages\nnij = ni*nj; % number of elements in one page\nN = size(node,1);\nnodeidx = reshape(1:N,ni,nj,nk);\nt2nidxMap = nodeidx(1:ni-1,1:nj-1,1:nk-1);\ns = t2nidxMap(:);\nelem = [s s+ni s+ni+nij s+nij s+1 s+ni+1 s+ni+nij+1 s+nij+1]; \n% s+1 s+ni*nj\n% | /\n% s - s + ni ", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/iFEM/mesh/cubehexmesh.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.8688267864276108, "lm_q1q2_score": 0.793826645840823}}
{"text": "function K = curvature_2D(X,Y,degree)\n% CURVATURE_2D estimate curvature of a curve defined by points\n%\n% K = CURVATURE_2D(X, Y, DEGREE)\n%\n% DEGREE is the degree of the polynom used for the interpolation\n%\n\n%\n% Created by Alexandre Gramfort on 2008-12-15.\n% Copyright (c) 2007 Alexandre Gramfort. All rights reserved.\n%\n\n% $Id: curvature_2D.m 2 2009-06-16 19:24:10Z gramfort $\n% $LastChangedBy: gramfort $\n% $LastChangedDate: 2009-06-16 15:24:10 -0400 (Mar, 16 jui 2009) $\n% $Revision: 2 $\n\nif nargin<3\n % default values\n degree = 5; % degree of polynum used for interpolation\nend\n\n% Find a parametrization of the curve\nt = cumsum(sqrt(diff(X).^2 + diff(Y).^2));\nt = [0,t];\nt = t / t(end); % normalize between 0 and 1\n\n% compute coefficients of interpolation functions\nx0 = polyfit(t, X, degree);\ny0 = polyfit(t, Y, degree);\n\n% compute coefficients of first and second derivatives. In the case of a\n% polynom, it is possible to compute coefficient of derivative by\n% multiplying with a matrix.\nderive = diag(degree:-1:0);\nxp = circshift(x0*derive, [0 1]);\nyp = circshift(y0*derive, [0 1]);\nxs = circshift(xp*derive, [0 1]);\nys = circshift(yp*derive, [0 1]);\n\n% compute values of first and second derivatives for needed points \nxprime = polyval(xp, t);\nyprime = polyval(yp, t);\nxsec = polyval(xs, t);\nysec = polyval(ys, t);\n\n% compute value of curvature\nK = (xprime.*ysec - xsec.*yprime)./ ...\n power(xprime.*xprime + yprime.*yprime, 3/2);\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/lagextraction/private/curvature_2D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159725, "lm_q2_score": 0.8688267813328977, "lm_q1q2_score": 0.7938266411859031}}
{"text": "% Return the total number of edges given the adjacency matrix\n% INPUTs: adjacency matrix, nxn\n% OUTPUTs: m - total number of edges/links\n%\n% Note: Valid for both directed and undirected, simple or general graph\n% Other routines used: selfLoops.m, isSymmetric.m\n% GB, last updated Sep 19, 2012\n\nfunction m = numEdges(adj)\n\nsl=selfLoops(adj); % counting the number of self-loops\n\nif isSymmetric(adj) && sl==0 % undirected simple graph\n m=sum(sum(adj))/2;\n \nelseif isSymmetric(adj) && sl>0\n m=(sum(sum(adj))-sl)/2+sl; % counting the self-loops only once\n\nelseif not(isSymmetric(adj)) % directed graph (not necessarily simple)\n m=sum(sum(adj));\n \nend", "meta": {"author": "aeolianine", "repo": "octave-networks-toolbox", "sha": "e70f79eb62a54ef96934d900830f9177caf732c9", "save_path": "github-repos/MATLAB/aeolianine-octave-networks-toolbox", "path": "github-repos/MATLAB/aeolianine-octave-networks-toolbox/octave-networks-toolbox-e70f79eb62a54ef96934d900830f9177caf732c9/numEdges.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.8688267643505194, "lm_q1q2_score": 0.7938266256695027}}
{"text": "%% Example A.1: Linear Advection in a Periodic Domain\n% \n% The linear advection problem with periodic boundary conditions\n%\n% $$u_t + u_x = 0, \\qquad u(x,0)=u_0(x), \\qquad u(0,t)=u(1,t)$$\n%\n% is well suited for studying error mechanisms in numerical schemes for\n% hyperbolic conservation laws. In particular, to study dissipative and\n% oscillatory errors, we will use initial data consisting of a combination\n% of a smooth, squared cosine wave and double step function.\n\n%%\n% We consider two first-order methods (Lax-Friedrichs and the upwind\n% method) and two second-order methods (Lax-Wendroff and MacCormack)\nT = 10;\nN = 100; h=1/N; x=h*(1:N);\nu0 = (abs(x-.25)<=0.15).*(cos(pi*(10/3)*(x-0.25))).^2 + ...\n 1.0*(abs(x-0.75)<0.15);\nxx = linspace(0,1,1001);\nuf = (abs(xx-.25)<=0.15).*(cos(pi*(10/3)*(xx-0.25))).^2 + ...\n 1.0*(abs(xx-0.75)<0.15);\n\nmethod = {'LxF', 'upwind', 'LxW', 'McC'};\nname = {'Lax-Friedrichs', 'Upwind', 'Lax-Wendroff', 'MacCormack'};\nfor i=1:4\n u=finvol('linearfunc',u0,T,h,1,'periodic',method{i},.9);\n subplot(2,2,i);\n plot(xx,uf,'-',x,u,'o','MarkerSize',2); axis([0 1 -0.2 1.3]);\n title(name{i});\nend\n%%\n% We see that the two first-order schemes smear both the smooth part and\n% the discontinuous path of the advected profile and that the\n% Lax-Friedrichs method is more diffusive than the upwind method. The\n% second-order schemes, on the other hand, preserve the smooth profile\n% quite accurately, but introduce spurious oscillations around the two\n% discontinuities.", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/OperatorSplitting/AppendixA/demoA_1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.896251362048962, "lm_q2_score": 0.885631470799559, "lm_q1q2_score": 0.7937484119775303}}
{"text": "function v = r8vec_house_column ( n, a, k )\n\n%*****************************************************************************80\n%\n%% R8VEC_HOUSE_COLUMN defines a Householder premultiplier that \"packs\" a column.\n%\n% Discussion:\n%\n% The routine returns a vector V that defines a Householder\n% premultiplier matrix H(V) that zeros out the subdiagonal entries of\n% column K of the matrix A.\n%\n% H(V) = I - 2 * v * v'\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 April 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix A.\n%\n% Input, real A(N), column K of the matrix A.\n%\n% Input, integer K, the column of the matrix to be modified.\n%\n% Output, real V(N), a vector of unit L2 norm which defines an\n% orthogonal Householder premultiplier matrix H with the property\n% that the K-th column of H*A is zero below the diagonal.\n%\n v(1:n) = 0.0;\n\n if ( k < 1 | n <= k )\n return\n end\n\n s = sqrt ( sum ( a(k:n).^2 ) );\n\n if ( s == 0.0 )\n return\n end\n\n v(k) = a(k) + abs ( s ) * r8_sign ( a(k) );\n v(k+1:n) = a(k+1:n);\n\n v(k:n) = v(k:n) / sqrt ( v(k:n).^2 );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/test_eigen/r8vec_house_column.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242073, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7936849401946793}}
{"text": "function [theta, J_history] = gradientDescentMulti(X, y, theta, alpha, num_iters)\n%GRADIENTDESCENTMULTI Performs gradient descent to learn theta\n% theta = GRADIENTDESCENTMULTI(x, y, theta, alpha, num_iters) updates theta by\n% taking num_iters gradient steps with learning rate alpha\n\n% Initialize some useful values\nm = length(y); % number of training examples\nJ_history = zeros(num_iters, 1);\n\nfor iter = 1:num_iters\n\n % ====================== YOUR CODE HERE ======================\n % Instructions: Perform a single gradient step on the parameter vector\n % theta. \n %\n % Hint: While debugging, it can be useful to print out the values\n % of the cost function (computeCostMulti) and gradient here.\n %\n\n predictions = X * theta;\n updates = X' * (predictions - y);\n theta = theta - alpha * (1/m) * updates;\n\n\n\n % ============================================================\n\n % Save the cost J in every iteration \n J_history(iter) = computeCostMulti(X, y, theta);\n\nend\n\nend\n", "meta": {"author": "vkosuri", "repo": "CourseraMachineLearning", "sha": "b11d4152c323a084fa3bc942e108ed456b77cbd3", "save_path": "github-repos/MATLAB/vkosuri-CourseraMachineLearning", "path": "github-repos/MATLAB/vkosuri-CourseraMachineLearning/CourseraMachineLearning-b11d4152c323a084fa3bc942e108ed456b77cbd3/home/week-2/exercises/machine-learning-ex1/ex1/gradientDescentMulti.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632856092014, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.7936849384632553}}
{"text": "%book : Signals and Systems Laboratory with MATLAB \n%by Alex Palamides & Anastasia Veloni\n\n% Fourier Series properties \n\n\n%time shifting \n\nt0=0;\nT=10;\nw=2*pi/T;\nsyms t\nx=t*exp(-5*t) \nk=-5:5;\na=(1/T)*int(x*exp(-j*k*w*t),t,t0,t0+T);\na1=eval(a);\nsubplot(211);\nstem(k,abs(a1));\ntitle(' Coefficients of x(t)=te^-^5^t');\nlegend('Magnitude');\nsubplot(212);\nstem(k,angle(a1));\nlegend('Angle');\n\nfigure\nt1=3;\nright= exp(-j*k*w*t1).*a;\nright =eval(right);\nsubplot(211);\nstem(k,abs(right));\nlegend('Magnitude');\ntitle('Right part');\nsubplot(212);\nstem(k,angle(right));\nlegend('Angle');\n\nfigure\nx=(t-t1).*exp(-5*(t-t1));\na=(1/T)*int(x*exp(-j*k*w*t),t,t0+t1,t0+T+t1);\ncoe=eval(a);\nsubplot(211);\nstem(k,abs(coe));\nlegend('Magnitude');\ntitle(' Coefficient of (t-3)exp(-5(t-3)) ');\nsubplot(212);\nstem(k,angle(coe));\nlegend('Angle');\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/5/c59b.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.8558511396138366, "lm_q1q2_score": 0.7936849351334084}}
{"text": "function y=PSNR(noisyImage,restoredImage)\n \n% Compute the PSNR of two gray scale image\n% Traditional progarmming using loops \n% Class input : [0,1] \n% july, 25 , 2012\n% KHMOU Youssef\n \nN=size(noisyImage);\nif length(N)> 2\n error('Input must be grayscale image');\nend\nif size(noisyImage)~=size(restoredImage)\n error('The images must have the same size');\nend\n \n%if ~isa(noisyImage,'double') \n% noisyImage=double(noisyImage)./255.00;\n%end\n%if ~isa(restoredImage,'double')\n% restoredImage=double(restoredImage)./255.00;\n%end\n \n% begin\n \nd1=max(noisyImage(:));\nd2=max(restoredImage(:));\nd=max(d1,d2);\n\nMSE=0;\nfor i=1:N(1)\n for j=1:N(2)\n if isnan(noisyImage(i,j)) || isinf(restoredImage(i,j))...\n || isnan(restoredImage(i,j)) || isinf(noisyImage(i,j))\n continue;\n end\n MSE=MSE+((abs(noisyImage(i,j)-restoredImage(i,j))).^2);\n end\nend\n \nMSE=MSE./(N(1)*N(2));\n \ny=10*log10((d.^2) /MSE)\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/37691-psnr-for-rgb-images/PSNR.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.8652240756264638, "lm_q1q2_score": 0.7936723476658148}}
{"text": "function [x,y] = EquiNodes2D(N);\n\n% function [x,y] = EquiNodes2D(N);\n% Purpose : Compute (x,y) nodes in equilateral triangle for polynomial of order N\n\n% total number of nodes\nNp = (N+1)*(N+2)/2;\n\n% Create equidistributed nodes on equilateral triangle\nL1 = zeros(Np,1); L2 = zeros(Np,1); L3 = zeros(Np,1);\nsk = 1;\nfor n=1:N+1\n for m=1:N+2-n\n L1(sk) = (n-1)/N; L3(sk) = (m-1)/N;\n sk = sk+1;\n end\nend\nL2 = 1.0-L1-L3;\n\nx = -L2+L3; y = (-L2-L3+2*L1)/sqrt(3.0);\nreturn\n", "meta": {"author": "wme7", "repo": "Aero-matlab", "sha": "9430008f2e3b84f28633775a44dff534e780fbac", "save_path": "github-repos/MATLAB/wme7-Aero-matlab", "path": "github-repos/MATLAB/wme7-Aero-matlab/Aero-matlab-9430008f2e3b84f28633775a44dff534e780fbac/JSHesthaven&TWarburton/Codes2D/EquiNodes2D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.8539127585282745, "lm_q1q2_score": 0.793661015769458}}
{"text": "function value = r4_atanh ( x )\n\n%*****************************************************************************80\n%\n%% R4_ATANH evaluates the arc-hyperbolic tangent of an R4 argument.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 September 2011\n%\n% Author:\n%\n% Original FORTRAN77 version by Wayne Fullerton.\n% MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Wayne Fullerton,\n% Portable Special Function Routines,\n% in Portability of Numerical Software,\n% edited by Wayne Cowell,\n% Lecture Notes in Computer Science, Volume 57,\n% Springer 1977,\n% ISBN: 978-3-540-08446-4,\n% LC: QA297.W65.\n%\n% Parameters:\n%\n% Input, real X, the argument.\n%\n% Output, real VALUE, the arc-hyperbolic tangent of X.\n%\n persistent atnhcs;\n persistent dxrel;\n persistent nterms;\n persistent sqeps;\n\n if ( isempty ( nterms ) )\n atnhcs = [ ...\n 0.094395102393195492E+00;\n 0.049198437055786159E+00;\n 0.002102593522455432E+00;\n 0.000107355444977611E+00;\n 0.000005978267249293E+00;\n 0.000000350506203088E+00;\n 0.000000021263743437E+00;\n 0.000000001321694535E+00;\n 0.000000000083658755E+00;\n 0.000000000005370503E+00;\n 0.000000000000348665E+00;\n 0.000000000000022845E+00;\n 0.000000000000001508E+00;\n 0.000000000000000100E+00;\n 0.000000000000000006E+00 ];\n nterms = r4_inits ( atnhcs, 15, 0.1 * r4_mach ( 3 ) );\n dxrel = sqrt ( r4_mach ( 4 ) );\n sqeps = sqrt ( 3.0 * r4_mach ( 3 ) );\n end\n\n y = abs ( x );\n\n if ( y <= sqeps )\n value = x;\n elseif ( y <= 0.5 )\n value = x * ( 1.0 ...\n + r4_csevl ( 8.0 * x * x - 1.0, atnhcs, nterms ) );\n elseif ( y < 1.0 )\n value = 0.5 * log ( ( 1.0 + x ) / ( 1.0 - x ) );\n else\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'R4_ATANH - Fatal error!\\n' );\n fprintf ( 1, ' 1 <= |X|.\\n' );\n error ( 'R4_ATANH - Fatal error!' )\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/fn/r4_atanh.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.85776809953619, "lm_q1q2_score": 0.7936327419287886}}
{"text": "function halton_dataset ( )\n\n%*****************************************************************************80\n%\n%% HALTON_DATASET generates a Halton dataset and writes it to a file.\n%\n% Discussion:\n%\n% This program is meant to be used interactively. It's also\n% possible to prepare a simple input file beforehand and use it\n% in batch mode.\n%\n% The program requests input values from the user:\n%\n% * NDIM, the spatial dimension,\n% * N, the number of points to generate,\n% * STEP, the index of the first subsequence element to be computed.\n% * SEED(1:NDIM), the Halton sequence index corresponding\n% to STEP = 0.\n% * LEAP(1:NDIM), the successive jumps in the Halton sequence.\n% * BASE(1:NDIM), the Halton bases (usually distinct primes).\n%\n% The program generates the data, writes it to the file\n%\n% halton_NDIM_N.txt\n%\n% where \"NDIM\" and \"N\" are the numeric values specified by the user,\n% and then asks the user for more input. To indicate that no further\n% computations are desired, it is enough to input a nonsensical\n% value, such as -1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 October 2008\n%\n% Author:\n%\n% John Burkardt\n%\n timestamp ( );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'HALTON_DATASET\\n' );\n fprintf ( 1, ' MATLAB version\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Generate a Halton dataset.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' This program is meant to be used interactively.\\n' );\n fprintf ( 1, ' It is also possible to prepare a simple input \\n' );\n fprintf ( 1, ' file beforehand and use it in batch mode.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The program requests input values from the user:\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' * NDIM, the spatial dimension,\\n' );\n fprintf ( 1, ' * N, the number of points to generate,\\n' );\n fprintf ( 1, ' * STEP, the index of the first subsequence element.\\n' );\n fprintf ( 1, ' * SEED(1:NDIM), the Halton sequence element\\n' );\n fprintf ( 1, ' corresponding to STEP = 0\\n' );\n fprintf ( 1, ' * LEAP(1:NDIM), the successive jumps in the\\n' );\n fprintf ( 1, ' Halton sequence.\\n' );\n fprintf ( 1, ' * BASE(1:M), the Halton bases,\\n' );\n fprintf ( 1, ' usually distinct primes.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The program generates the data, writes it to the file\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' halton_NDIM_N.txt\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' where \"NDIM\" and \"N\" are the numeric values specified\\n' );\n fprintf ( 1, ' by the user, and then asks the user for more input.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' To indicate that no further computations are \\n' );\n fprintf ( 1, ' desired, it is enough to input a nonsensical value, \\n' );\n fprintf ( 1, ' such as -1.\\n' );\n\n while ( 1 )\n\n fprintf ( 1, ' *\\n' );\n fprintf ( 1, ' *\\n' );\n fprintf ( 1, '* Ready to generate a new dataset:\\n' );\n fprintf ( 1, ' *\\n' );\n fprintf ( 1, ' *\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' NDIM is the spatial dimension.\\n' );\n fprintf ( 1, ' (Try ''2'' if you have no preference.)\\n' );\n fprintf ( 1, ' Any value less than 1 terminates execution.\\n' );\n ndim = input ( ' Enter NDIM: ' );\n\n fprintf ( 1, ' User input NDIM = %d\\n', ndim );\n\n if ( ~halham_ndim_check ( ndim ) )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'HALTON_DATASET\\n' );\n fprintf ( 1, ' The input value of NDIM = %d\\n', ndim );\n fprintf ( 1, ' is interpreted as a request for termination.\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n break\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' N is the number of points.\\n' );\n fprintf ( 1, ' (Try ''25'' if you have no preference.)\\n' );\n fprintf ( 1, ' Any value less than 1 terminates execution.\\n' );\n n = input ( ' Enter N: ' );\n\n fprintf ( 1, ' User input N = %d\\n', n );\n\n if ( ~halham_n_check ( n ) )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'HALTON_DATASET\\n' );\n fprintf ( 1, ' The input value of N = %d\\n', n );\n fprintf ( 1, ' is interpreted as a request for termination.\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n break\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' STEP is the index of the first subsequence element.\\n' );\n fprintf ( 1, ' (Try ''0'' or ''1'' if you have no preference.)\\n' );\n fprintf ( 1, ' Any value less than 0 terminates execution.\\n' );\n step = input ( ' Enter STEP: ' );\n\n fprintf ( 1, ' User input STEP = %d\\n', step );\n\n if ( ~halham_step_check ( step ) )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'HALTON_DATASET\\n' );\n fprintf ( 1, ' The input value of STEP = %d\\n', step );\n fprintf ( 1, ' is interpreted as a request for termination.\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n break\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' SEED(1:NDIM) is the starting element index\\n' );\n fprintf ( 1, ' for each coordinate.\\n' );\n fprintf ( 1, ' (Try ''[0,0,...,0]'' if you have no preference.)\\n' );\n fprintf ( 1, ' (Any value less than 0 terminates execution.)\\n' );\n seed = [];\n seed(1:ndim) = input ( ' Enter SEED(1:NDIM): ' );\n\n fprintf ( 1, '\\n' );\n i4vec_transpose_print ( ndim, seed, 'SEED:' );\n\n if ( ~halham_seed_check ( ndim, seed ) )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'HALTON_DATASET\\n' );\n fprintf ( 1, ' The negative input value of at least one entry of\\n' );\n fprintf ( 1, ' SEED is interpreted as a request for termination.\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' LEAP(1:NDIM) is the leaping multiplier\\n' );\n fprintf ( 1, ' for each coordinate.\\n' );\n fprintf ( 1, ' (Try ''[1,1,...,1]'' if you have no preference.)\\n' );\n fprintf ( 1, ' (Another choice is a prime bigger than all the bases.)\\n' );\n fprintf ( 1, ' (Any value less than 1 terminates execution.)\\n' );\n leap = [];\n leap(1:ndim) = input ( ' Enter LEAP(1:NDIM): ' );\n\n fprintf ( 1, '\\n' );\n i4vec_transpose_print ( ndim, leap, 'LEAP:' );\n\n if ( ~halham_leap_check ( ndim, leap ) )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'HALTON_DATASET\\n' );\n fprintf ( 1, ' The input value of at least one entry of\\n' );\n fprintf ( 1, ' LEAP is interpreted as a request for termination.\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' BASE(1:NDIM) is the base for each coordinate,\\n' );\n fprintf ( 1, ' usually distinct primes.\\n' );\n fprintf ( 1, ' (Try ''[2,3,5,7,11,13,...]'' if you have no preference.)\\n' );\n fprintf ( 1, ' (Any value less than 2 terminates execution.)\\n' );\n base = [];\n base(1:ndim) = input ( ' Enter BASE: ' );\n\n fprintf ( 1, '\\n' );\n i4vec_transpose_print ( ndim, base, 'BASE:' );\n\n if ( ~halton_base_check ( ndim, base ) )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'HALTON_DATASET\\n' );\n fprintf ( 1, ' The input value of at least one entry of\\n' );\n fprintf ( 1, ' BASE is interpreted as a request for termination.\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n end\n\n r = i4_to_halton_sequence ( ndim, n, step, seed, leap, base );\n\n file_out_name = ...\n strcat ( 'halton_', num2str ( ndim ), '_', num2str ( n ), '.txt' );\n\n halham_write ( ndim, n, step, seed, leap, base, r, file_out_name );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The data was written to the file \"%s\".\\n', ...\n file_out_name );\n\n end\n\n fprintf ( 1, '\\n' );\n timestamp ( );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/halton_dataset/halton_dataset.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.8976953023710936, "lm_q1q2_score": 0.7935979158201176}}
{"text": "function turn = angle_turn_2d ( p1, p2, p3 )\n\n%*****************************************************************************80\n%\n%% ANGLE_TURN_2D computes a turning angle in 2D.\n%\n% Discussion:\n%\n% This routine is most useful when considering the vertices of a\n% polygonal shape. We wish to distinguish between angles that \"turn\n% in\" to the shape, (between 0 and 180 degrees) and angles that\n% \"turn out\" (between 180 and 360 degrees), as we traverse the boundary.\n%\n% If we compute the interior angle and subtract 180 degrees, we get the\n% supplementary angle, which has the nice property that it is\n% negative for \"in\" angles and positive for \"out\" angles, and is zero if\n% the three points actually lie along a line.\n%\n% Assuming P1, P2 and P3 define an angle, the TURN can be\n% defined to be either:\n%\n% * the supplementary angle to the angle formed by P1=P2=P3, or\n%\n% * the angle between the vector ( P3-P2) and the vector -(P1-P2),\n% where -(P1-P2) can be understood as the vector that continues\n% through P2 from the direction P1.\n%\n% The turning will be zero if P1, P2 and P3 lie along a straight line.\n%\n% It will be a positive angle if the turn from the previous direction\n% is counterclockwise, and negative if it is clockwise.\n%\n% The turn is given in radians, and will lie between -PI and PI.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 March 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real P1(2), P2(2), P3(2), the points that form\n% the angle.\n%\n% Output, real TURN, the turn angle, between -PI and PI.\n%\n p(1) = ( p3(1) - p2(1) ) * ( p1(1) - p2(1) ) ...\n + ( p3(2) - p2(2) ) * ( p1(2) - p2(2) );\n\n p(2) = ( p3(1) - p2(1) ) * ( p1(2) - p2(2) ) ...\n - ( p3(2) - p2(2) ) * ( p1(1) - p2(1) );\n\n if ( p(1) == 0.0 & p(2) == 0.0 )\n turn = 0.0;\n else\n turn = pi - r8_atan ( p(2), p(1) );\n end\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/angle_turn_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593496, "lm_q2_score": 0.8840392848011834, "lm_q1q2_score": 0.7935978943255086}}
{"text": "function area = polygon_area_3d_2 ( n, v, area )\n\n%*****************************************************************************80\n%\n%% POLYGON_AREA_3D_2 computes the area of a polygon in 3D.\n%\n% Discussion:\n%\n% The computation is not valid unless the vertices of the polygon\n% lie in a plane, so that the polygon that is defined is \"flat\".\n%\n% The polygon does not have to be \"regular\", that is, neither its\n% sides nor its angles need to be equal.\n%\n% The area is computed as the sum of the areas of the triangles \n% formed by the last node with consecutive pairs of nodes (1,2),\n% (2,3), ..., and (N-2,N-1).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 October 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Adrian Bowyer and John Woodwark,\n% A Programmer's Geometry,\n% Butterworths, 1983.\n%\n% Parameters:\n%\n% Input, integer N, the number of vertices of the polygon.\n%\n% Input, real V(3,N), the coordinates of the vertices.\n%\n% Output, real AREA, the area of the polygon.\n%\n area_vector(1:3) = 0.0;\n\n for i = 1 : n - 2\n\n t(1:3,1:3) = [ v(1:3,i)'; v(1:3,i+1)'; v(1:3,n)' ]';\n\n area_vector_triangle = triangle_area_vector_3d ( t );\n\n area_vector(1:3) = area_vector(1:3) + area_vector_triangle(1:3);\n\n end\n\n area = 0.5 * sqrt ( sum ( area_vector(1:3).^2 ) );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/geometry/polygon_area_3d_2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.8519528076067261, "lm_q1q2_score": 0.793562101233618}}
{"text": "function rotated=uniform_rotation_3D(v)\n% This function perform a unformly random rotation 3D.\n% It is clear that in 2 dimensions that this means the \n% rotation angle is uniformly distributed between (0, 2pi).\n% However, it is NOT correct and does NOT carry over to \n% higher dimensions. \n%\n% More information see Le?n, Carlos A.; Mass?, Jean-Claude; \n% Rivest, Louis-Paul (February 2006), \"A statistical model \n% for random rotations\", Journal of Multivariate Analysis 97 \n% (2): 412?430, doi:10.1016/j.jmva.2005.03.009, ISSN 0047-259X\n\n% Arguments (input):\n% v - 3*1 vector needs to be rotated\n%\n%\n% arguments (output):\n% rotated - 3*1 vector after unformly random rotation\n%\n% \n% References: J. Arvo (1992), Fast Random Rotation Matrices\n%\n% Author: Yaming Wang. ETH Zurich.\n% email: yaming.wang@sed.ethz.ch\n% Release: 1.00\n% Release data: 18.09.2012\n\nrot_1=2*pi*rand(1);\nmatrix_1=[cos(rot_1),sin(rot_1),0;...\n -sin(rot_1),cos(rot_1),0;...\n 0,0,1];\n\nrot_2a=2*pi*rand(1);\nrot_2b=rand(1);\n\nHouseholder_v=[cos(rot_2a)*sqrt(rot_2b)\n sin(rot_2a)*sqrt(rot_2b)\n sqrt(1-rot_2b)];\n\n% Householder matrix\nmatrix_2=eye(3)-2*Householder_v*Householder_v';\n\nrotated=-matrix_2*matrix_1*v;\n\nfprintf(1,'rotation finished.\\n');\n\n\n% ====================================================\n% end of function\n% ====================================================", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/43550-uniformrotation3d/uniform_rotation_3D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.947381048137938, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.7935452749637473}}
{"text": "\n% LegendrePoly.m by David Terr, Raytheon, 5-10-04\n\n% Given nonnegative integer n, compute the \n% Legendre polynomial P_n. Return the result as a vector whose mth\n% element is the coefficient of x^(n+1-m).\n% polyval(LegendrePoly(n),x) evaluates P_n(x).\n\n\nfunction pk = LegendrePoly(n)\n\nif n==0 \n pk = 1;\nelseif n==1\n pk = [1 0]';\nelse\n \n pkm2 = zeros(n+1,1);\n pkm2(n+1) = 1;\n pkm1 = zeros(n+1,1);\n pkm1(n) = 1;\n\n for k=2:n\n \n pk = zeros(n+1,1);\n\n for e=n-k+1:2:n\n pk(e) = (2*k-1)*pkm1(e+1) + (1-k)*pkm2(e);\n end\n \n pk(n+1) = pk(n+1) + (1-k)*pkm2(n+1);\n pk = pk/k;\n \n if k 500, Very Good!\n% cvx_solver('Gurobi');\n\nhRunTime = tic();\n\ncvx_begin('quiet')\n% cvx_begin()\n % cvx_precision('best');\n variable vX(numCols, 1);\n minimize( 0.5 * sum_square(mA * vX - vB) + (0.5 * paramLambda * square_pos(norm(vX))) );\n subject to\n vX >= 0;\ncvx_end\n\nrunTime = toc(hRunTime);\n\n% vX = mX(:);\n\ndisp([' ']);\ndisp([solverString, ' Solution Summary']);\ndisp(['The ', solverString, ' Solver Status - ', cvx_status]);\ndisp(['The Optimal Value Is Given By - ', num2str(hObjFun(vX))]);\ndisp(['The Optimal Argument Is Given By - [ ', num2str(vX(:).'), ' ]']);\ndisp(['The Run Time Is Given By - ', num2str(runTime), ' [Sec]']);\ndisp([' ']);\n\nsCvxSol.vXCvx = vX;\nsCvxSol.cvxOptVal = hObjFun(vX);\n\n\n%% Solution by Projected Gradient Descent\n\nsolverIdx = solverIdx + 1;\ncLegendString{solverIdx} = ['Projected Gradient Method'];\n\nhRunTime = tic();\n\n[vX, mX] = ProjectedGd(zeros(numCols, 1), hG, hP, numIterations, stepSizeGd);\n\nrunTime = toc(hRunTime);\n\ndisp([' ']);\ndisp([cLegendString{solverIdx}, ' Solution Summary']);\ndisp(['The Optimal Value Is Given By - ', num2str(hObjFun(vX))]);\ndisp(['The Optimal Argument Is Given By - [ ', num2str(vX(:).'), ' ]']);\ndisp(['The Run Time Is Given By - ', num2str(runTime), ' [Sec]']);\ndisp([' ']);\n\n[mObjFunValMse, mSolMse] = UpdateAnalysisData(mObjFunValMse, mSolMse, mX, hObjFun, sCvxSol, solverIdx);\n\n\n%% Solution by Projected Gradient Descent with Momentum\n\nsolverIdx = solverIdx + 1;\ncLegendString{solverIdx} = ['Projected Gradient Descent with Momentum'];\n\nhRunTime = tic();\n\n[vX, ~, mX] = ProjectedGdMomentum(zeros(numCols, 1), zeros(numCols, 1), hG, hP, numIterations, stepSizeGd, stepSizeMomentum);\n\nrunTime = toc(hRunTime);\n\ndisp([' ']);\ndisp([cLegendString{solverIdx}, ' Solution Summary']);\ndisp(['The Optimal Value Is Given By - ', num2str(hObjFun(vX))]);\ndisp(['The Optimal Argument Is Given By - [ ', num2str(vX(:).'), ' ]']);\ndisp(['The Run Time Is Given By - ', num2str(runTime), ' [Sec]']);\ndisp([' ']);\n\n[mObjFunValMse, mSolMse] = UpdateAnalysisData(mObjFunValMse, mSolMse, mX, hObjFun, sCvxSol, solverIdx);\n\n\n%% Solution by Projected Gradient Descent with Nesterov Acceleration\n\nsolverIdx = solverIdx + 1;\ncLegendString{solverIdx} = ['Projected Gradient Descent with Nesterov Acceleration'];\n\nhRunTime = tic();\n\n[vX, ~, mX] = ProjectedGdAccel(zeros(numCols, 1), zeros(numCols, 1), hG, hP, numIterations, stepSizeGd, stepSizeAccel);\n\nrunTime = toc(hRunTime);\n\ndisp([' ']);\ndisp([cLegendString{solverIdx}, ' Solution Summary']);\ndisp(['The Optimal Value Is Given By - ', num2str(hObjFun(vX))]);\ndisp(['The Optimal Argument Is Given By - [ ', num2str(vX(:).'), ' ]']);\ndisp(['The Run Time Is Given By - ', num2str(runTime), ' [Sec]']);\ndisp([' ']);\n\n[mObjFunValMse, mSolMse] = UpdateAnalysisData(mObjFunValMse, mSolMse, mX, hObjFun, sCvxSol, solverIdx);\n\n\n%% Solution by Projected Gradient Descent with FISTA\n\nsolverIdx = solverIdx + 1;\ncLegendString{solverIdx} = ['Projected Gradient Descent with FISTA Acceleration'];\n\nhRunTime = tic();\n\n[vX, ~, mX] = ProjectedGdFista(zeros(numCols, 1), zeros(numCols, 1), hG, hP, numIterations, stepSizeGd);\n% [vX, mX] = SolveLsFista(zeros(numCols, 1), mA, vB, paramLambda, numIterations, stepSizeGd);\n\nrunTime = toc(hRunTime);\n\ndisp([' ']);\ndisp([cLegendString{solverIdx}, ' Solution Summary']);\ndisp(['The Optimal Value Is Given By - ', num2str(hObjFun(vX))]);\ndisp(['The Optimal Argument Is Given By - [ ', num2str(vX(:).'), ' ]']);\ndisp(['The Run Time Is Given By - ', num2str(runTime), ' [Sec]']);\ndisp([' ']);\n\n[mObjFunValMse, mSolMse] = UpdateAnalysisData(mObjFunValMse, mSolMse, mX, hObjFun, sCvxSol, solverIdx);\n\n\n%% Display Results\n\nfigureIdx = figureIdx + 1;\n\nhFigure = figure('Position', figPosLarge);\n\nhAxes = subplot(2, 1, 1);\nhLineSeries = plot(1:numIterations, 10 * log10(mObjFunValMse));\nset(hLineSeries, 'LineWidth', lineWidthNormal);\nset(get(hAxes, 'Title'), 'String', ['Objective Function Value vs. Optimal Value (CVX)'], ...\n 'FontSize', fontSizeTitle);\nset(get(hAxes, 'XLabel'), 'String', 'Iteration Number', ...\n 'FontSize', fontSizeAxis);\nset(get(hAxes, 'YLabel'), 'String', '$ 10 \\log_{10} {\\left( \\left| f \\left( x \\right) - f \\left( {x}_{CVX} \\right) \\right| \\right)}^{2} $', ...\n 'FontSize', fontSizeAxis, 'Interpreter', 'latex');\nset(hAxes, 'XLim', [1, numIterations]);\nhLegend = ClickableLegend(cLegendString);\n\nhAxes = subplot(2, 1, 2);\nhLineSeries = plot(1:numIterations, 10 * log10(mSolMse));\nset(hLineSeries, 'LineWidth', lineWidthNormal);\nset(get(hAxes, 'Title'), 'String', ['Solution Error Norm'], ...\n 'FontSize', fontSizeTitle);\nset(get(hAxes, 'XLabel'), 'String', 'Iteration Number', ...\n 'FontSize', fontSizeAxis);\nset(get(hAxes, 'YLabel'), 'String', '$ 10 \\log_{10} \\left( {\\left\\| x - {x}_{CVX} \\right\\|}_{2}^{2} \\right) $', ...\n 'FontSize', fontSizeAxis, 'Interpreter', 'latex');\nset(hAxes, 'XLim', [1, numIterations]);\nhLegend = ClickableLegend(cLegendString);\n\nif(generateFigures == ON)\n % saveas(hFigure,['Figure', num2str(figureIdx, figureCounterSpec), '.png']);\n print(hFigure, ['Figure', num2str(figureIdx, figureCounterSpec), '.png'], '-dpng', '-r0'); % 0\n if size(elec_labels,1) > size(elec_labels,2)\n elec_labels = cellstr(strcat(num2str(elec_labels)));\n else\n elec_labels = cellstr(strcat(num2str(elec_labels')));\n end\n end\n \n A = [ (X-xo) (Y-yo) (Z-zo) ]; B = A; % define electrode vectors A,B, given centroid (xo,yo,zo)\n rows = 50; % progress indicator\n for a = 1:length(X)\n fprintf('.'); if( a == rows ) fprintf('\\n'); rows = rows + 50; end % progress indicator\n \n Aa = A(a,:);\n A_len = sqrt( sum( Aa.^2 ) ); % length of electrode vector A\n \n for b = 1:length(X)\n \n Bb = B(b,:);\n B_len = sqrt ( sum(Bb.^2) ); % length of electrode vector B\n \n if( Aa == Bb )\n arc_len = 0; % no distance from electrode to itself\n else\n r = (A_len + B_len)/2; % estimate sphere radius from A_len and B_len\n theta = acos( dot(Aa,Bb) / (A_len * B_len) ); % Angle between A & B, in radians\n arc_len = r * theta; % arc length = radius * theta\n end\n \n distances(a, b) = arc_len;\n labels(a, b) = strcat(elec_labels(a), ', ', elec_labels(b));\n end\n end\n fprintf('\\n');\n", "meta": {"author": "PatternRecognition", "repo": "OpenBMI", "sha": "3c42e609d5b867a8e15c780df3f8b0a8b86edcb8", "save_path": "github-repos/MATLAB/PatternRecognition-OpenBMI", "path": "github-repos/MATLAB/PatternRecognition-OpenBMI/OpenBMI-3c42e609d5b867a8e15c780df3f8b0a8b86edcb8/PR_BCI_team/Team_EarEEG/ear-EEG connecting/external/eeglab_10_0_1_0x/external/bioelectromagnetism_ligth/elec_distance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7933892824714142}}
{"text": "function breadth = polyhedronMeanBreadth(vertices, edges, faces)\n%POLYHEDRONMEANBREADTH Mean breadth of a convex polyhedron\n%\n% BREADTH = polyhedronMeanBreadth(V, E, F)\n% Return the mean breadth (average of polyhedron caliper diameter over\n% all direction) of a convex polyhedron.\n%\n% The mean breadth is computed using the sum, over the edges of the\n% polyhedron, of the edge dihedral angles multiplied by the edge length, \n% the final sum being divided by (4*PI).\n%\n% Note: the function assumes that the faces are correctly oriented. The\n% face vertices should be indexed counter-clockwise when considering the\n% supporting plane of the plane, with the outer normal oriented outwards\n% of the polyhedron.\n%\n% Typical values for classical polyhedra are:\n% cube side a breadth = (3/2)*a\n% cuboid sides a, b, c breadth = (a+b+c)/2\n% tetrahedron side a breadth = 0.9123*a\n% octaedron side a beradth = 1.175*a\n% dodecahedron, side a breadth = 15*arctan(2)*a/(2*pi)\n% icosaehdron, side a breadth = 15*arcsin(2/3)*a/(2*pi)\n%\n% Example\n% [v e f] = createCube;\n% polyhedronMeanBreadth(v, e, f)\n% ans = \n% 1.5\n%\n% See also\n% meshes3d, meshEdgeFaces, meshDihedralAngles, checkMeshAdjacentFaces\n% trimeshMeanBreadth\n%\n% References\n% Stoyan D., Kendall W.S., Mecke J. (1995) \"Stochastic Geometry and its\n% Applications\", John Wiley and Sons, p. 26\n% Ohser, J., Muescklich, F. (2000) \"Statistical Analysis of\n% Microstructures in Materials Sciences\", John Wiley and Sons, p.352\n\n% ------\n% Author: David Legland\n% e-mail: david.legland@inra.fr\n% Created: 2010-10-04, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2010 INRA - Cepia Software Platform.\n\n\n% compute dihedral angle of each edge\nalpha = meshDihedralAngles(vertices, edges, faces);\n\n% compute length of each edge\nlengths = meshEdgeLength(vertices, edges);\n\n% compute product of length by angles \nbreadth = sum(alpha.*lengths)/(4*pi);\n", "meta": {"author": "rpng", "repo": "lips", "sha": "a97157e586b509c9c2e3e01e64e4347f36d0b63e", "save_path": "github-repos/MATLAB/rpng-lips", "path": "github-repos/MATLAB/rpng-lips/lips-a97157e586b509c9c2e3e01e64e4347f36d0b63e/lips_matlab/matlab/functions/matGeom/meshes3d/polyhedronMeanBreadth.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7932954942477775}}
{"text": "function w = map ( code, element_order )\n\n%*****************************************************************************80\n%\n%% MAP returns the interpolation matrix for any available element.\n%\n% Formula:\n%\n% For an element of order ELEMENT_ORDER, we suppose we are given \n% ELEMENT_ORDER items of data Q associated with the nodes.\n%\n% Let PHI(J)(R,S) be the Lagrange basis polynomial associated with\n% node J. PHI(J)(R,S) is 1 at node J, and 0 at each of the other nodes.\n%\n% Let P(R,S) be the polynomial of ELEMENT_ORDER terms which interpolates the\n% data Q, that is,\n%\n% P(R(J),S(J)) = Q(J)\n%\n% where the coordinates of node J are (R(J),S(J)). Then we know\n% that we can write\n%\n% P(R,S) = sum ( 1 <= J <= ELEMENT_ORDER ) Q(J) * PHI(J)(R,S)\n%\n% But P(R,S) also has a standard representation as\n%\n% P(R,S) = sum ( 1 <= I <= ELEMENT_ORDER ) A(I) * R**REXP(I) * S**SEXP(I)\n%\n% where REXP(I) and SEXP(I) are the exponents of R and S and\n% the A(I) are the appropriate coefficients.\n%\n% The interpolation matrix W allows us to immediately compute\n% the standard basis coefficients A from the data Q to be interpolated\n% using the formula:\n%\n% A(I) = sum ( 1 <= J <= ELEMENT_ORDER ) W(I,J) * Q(J)\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 February 2003\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, character CODE(*), identifies the element.\n% Legal values include 'Q4', 'Q8', 'Q9', 'Q12', 'Q16', 'QL',\n% 'T3', 'T6' and 'T10'.\n%\n% Input, integer ELEMENT_ORDER, the order associated with the code.\n%\n% Output, real W(ELEMENT_ORDER,ELEMENT_ORDER), the interpolation matrix.\n%\n\n%\n% Get the (R,S) location of the nodes.\n%\n [ r, s, area ] = node_reference ( code );\n%\n% Get the associated monomials.\n%\n [ rexp, sexp ] = poly ( code );\n%\n% Set up the Vandermonde matrix.\n% Factors of the form 0**0 are to be understood as 1.\n%\n for i = 1 : element_order\n for j = 1 : element_order\n\n if ( rexp(j) == 0 )\n rfact = 1.0;\n else\n rfact = r(i)^rexp(j);\n end\n\n if ( sexp(j) == 0 )\n sfact = 1.0;\n else\n sfact = s(i)^sexp(j);\n end\n\n w(i,j) = rfact * sfact;\n\n end\n end\n%\n% Factor the Vandermonde matrix.\n%\n [ w_lu, pivot, info ] = r8ge_fa ( element_order, w );\n\n if ( info ~= 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'MAP - Fatal error!\\n' );\n fprintf ( 1, ' The Vandermonde matrix is singular.\\n' );\n error ( 'MAP - Fatal error!' );\n end\n%\n% Invert the Vandermonde matrix.\n%\n w = r8ge_inverse ( element_order, w_lu, pivot );\n\n return\nend\n", "meta": {"author": "johannesgerer", "repo": "jburkardt-m", "sha": "1726deb4a34dd08a49c26359d44ef47253f006c1", "save_path": "github-repos/MATLAB/johannesgerer-jburkardt-m", "path": "github-repos/MATLAB/johannesgerer-jburkardt-m/jburkardt-m-1726deb4a34dd08a49c26359d44ef47253f006c1/fem2d_pack/map.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699845, "lm_q2_score": 0.8615382165412809, "lm_q1q2_score": 0.7932954895586521}}
{"text": "function result=halfspacedepth(u,v,x,y)\n\n%HALFSPACEDEPTH computes the halfspace depth of a (two-dimensional) point theta \n% relative to a bivariate data set. \n%\n% The algoritm is described in: \n% Rousseeuw, P., Ruts, I. (1996),\n% \"AS 307: Bivariate Location Depth\",\n% Applied Statistics (JRSS-C), 45, 516-526.\n% \n% Required input arguments:\n% u : first coordinate of the point theta\n% v : second coordinate of the point theta\n% x : vector containing the first coordinates of all the data\n% points\n% y : vector containing the second coordinates of all the data\n% points\n%\n% I/O: [result] = halfspacedepth(u,v,x,y);\n%\n% This function is part of the Matlab Library for Robust Analysis,\n% available at: \n% http://wis.kuleuven.be/stat/robust.html\n%\n% Written by Fabienne Verwerft\n%\n%\n% Checking input\n%\nif not(length(x)==length(y))\n error('The vectors x and y must have the same length.')\nend\nif sum(isnan(x))>=1 || sum(isnan(y))>=1\n error('Missing values are not allowed')\nend\n%\n% m is the number of data points that coincide with theta\n%\neps=0.000001;\nn=length(x);\nnorm=sqrt((x-u).^2 + (y-v).^2);\nm=sum(norm<=eps);\nll=find(norm>eps);\nnorm=norm(ll);\nxn=(x(ll)-u)./norm;\nyn=(y(ll)-v)./norm;\n%\n% The vector containes the indices of the elements of x and y that satisfy\n% the conditions.\n%\nk=find((abs(x(ll))>abs(y(ll))) & (xn>=0));\nalfa(k)=asin(yn(k));\nt=find(alfa(k)<0);\nalfa(k(t))=2*pi+alfa(k(t));\nk=find((abs(x(ll))>abs(y(ll))) & (xn<0));\nalfa(k)=pi-asin(yn(k));\nk=find((abs(x(ll))<=abs(y(ll))) & (yn>=0));\nalfa(k)=acos(xn(k));\nk=find((abs(x(ll))<=abs(y(ll))) & (yn<0));\nalfa(k)=2*pi-acos(xn(k));\ng=find(alfa>=(2*pi-eps));\nalfa(g)=0;\n%\nnn=n-m;\nif nn <= 1\n hdepth=m;\n result=hdepth;\n return\n % all data points coincide with theta\nend\n%\nalfa=sort(alfa);\n%\nhoek=max(alfa(1)-alfa(nn)+2*pi,max(diff(alfa)));\nif hoek > pi+eps\n hdepth=m;\n result=hdepth;\n return\n % hdepth=0 because theta lies outside the datacloud\nend\n%\n% rotation around theta\n% nu is the number of angles in the upper halfcircle\n%\nalfa=alfa-alfa(1);\nnu=sum(alfa < (pi-eps));\n\nif nu >= nn \n hdepth=m;\n result=hdepth;\n return\n % hdepth=0 every angle in the upper halfcircle so theta outside the\n % datacloud.\nend\n%\n% construction of the array F\n%\nbeta=alfa+pi;\nalfatwee=alfa+2*pi;\nA=[alfa,alfatwee,beta];\nAindex(1:2*nn)=1;\nAindex((2*nn+1):3*nn)=0;\n[As,Asin]=sort(A);\nAindexs=Aindex(Asin);\npp=cumsum(Aindexs);\njuisten=find(Aindexs==0);\nF=pp(juisten);\n%\n% Adjust the array F for the angles that coincide with beta.\n%\ngelijkab=intersect(find(diff(As)<=eps)+1,juisten);\nbetagelijka=Asin(gelijkab);\nif length(gelijkab)>0\n for i=1:length(gelijkab)\n aantal=sum((As(Aindexs==1)+eps)0\n for i=1:length(gindex)\n aantal=sum(alfa(1:gindex(i)) 1e-12;\n\tx = ones(size(t));\n\tt = t(j);\n\td = d(j);\n\tx(j) = sin(pi*t) ./ d / K;\nelse\n\tx = nufft_diric(t, K, K, 1);\n%\txo = diric(2*pi*t/K,K); % would require matlab's signal toolbox\n%\tmax_percent_diff(xo, x)\nend\n\n\n%\n% self test\n%\nfunction sinc_periodic_test\n\nKlist = [4 5];\nim clf, pl=220;\nfor kk=1:2\n\tK = Klist(kk);\n\tn = [0:(4*K)]';\n\tt = linspace(0,4*K,401)';\n\tx = @(t,K) sinc_periodic(t, K);\n%\ty = @(t,K) diric(2*pi*t/K,K); % would require matlab's signal toolbox\n\ty = @(t,K) nufft_diric(t,K,K,1);\n\tif im\n\t\tsubplot(pl+kk+0)\n\t\tplot(t, x(t,K), '-', n, x(n,K), 'o')\n\t\ttitlef('Sinc-Periodic K=%d', K)\n\t\taxis([0 4*K -1 1]), xtick([0:4]*K), grid\n\t\tsubplot(pl+kk+2)\n\t\tplot(t, y(t,K), '-', n, y(n,K), 'o')\n\t\ttitlef('Dirichlet K=%d', K)\n\t\taxis([0 4*K -1 1]), xtick([0:4]*K), grid\n\t\tylabelf('K=%d', K)\n\tend\nend\n", "meta": {"author": "JeffFessler", "repo": "mirt", "sha": "b7f36cc46916821e8bc8502301b1554ebc7efe1d", "save_path": "github-repos/MATLAB/JeffFessler-mirt", "path": "github-repos/MATLAB/JeffFessler-mirt/mirt-b7f36cc46916821e8bc8502301b1554ebc7efe1d/utilities/sinc_periodic.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.8670357632379241, "lm_q1q2_score": 0.7932518437758337}}
{"text": "% solution of Poisson equation using sparse matrix\n%\n% E.Holzbecher, 18.3.2011 \n%\n%--------------------------------------------------\nnx = 12; ny = 12; % dimensions in x- and y-direction\nh = 1/4; % grid spacing\n\n% boundary type indicators (1=Dirichlet, 0=Neumann no-flow)\nltop = logical(zeros(1,nx)); % top\nlbottom = logical(zeros(1,nx)); % bottom\nlleft = logical([ones(6,1) zeros(6,1)]); % left\nlright = logical([zeros(6,1) ones(6,1)]); % right\n\n% boundary values (Dirichlet only)\nbtop = ones(1,nx); % top\nbbottom = zeros(1,nx); % bottom\nbleft = ones(ny,1); % left\nbright = zeros(ny,1); % right\n\nq = 1*ones(nx,ny); % right hand side (source term)\n\nN = nx*ny;\nd = [-nx,-1,0,1,nx];\nB = [ones(N,2) -4*ones(N,1) ones(N,2)];\nq = reshape(q,N,1);\nb = -h*h*q.*ones(N,1);\nfor i = 1:nx\n if ltop(i)\n b(i) = b(i)-btop(i);\n else\n B(i,3) = -3;\n %B(i-1,1) = 0;\n end\n if lbottom(i)\n b(N-nx+i) = b(N-nx+i)-bbottom(i);\n else\n B(N-nx+i,3) = -3;\n % B(N-nx+i,5) = 0;\n end\nend\nfor i = 1:ny\n B(i*nx,2) = 0; \n if i> BVP_Galerkin1(a,b,c,t1,t2,x1,x2,n)\n% where \"n\" is the number of trial functions\n% The output of this program is \n% 1- The approximated solution of x(t) vs. exact solution of x(t)\n% 2- The approximated x'(t) vs. exact x'(t)\n% 3- The approximated x\"(t) vs. exact x\"(t)\n% ======Example============================================================\n% Equation x\"(t)+ x'(t)+ x(t)=0\n% Boundary values x(1)=2, x(10)=0;\n% Solution: We have:\n% a=1; b=1; c=1;\n% t1=1; t2=10; \n% x1=2; x2=0;\n% Using n=8 tiral functions,\n% >>BVP_Galerkin(1,2,3,1,10,2,0,8)\n%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n% October.26, 2010, Ramin Shamshiri \n% ramin.sh@ufl.edu\n% Doctoral student at the University of Florida\n%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\nfunction BVP_Galerkin1(a,b,c,t1,t2,x1,x2,n) % Declare function\ndt=0.001; % increment\n%% Begin Approximate solution via Galerkin method over the entire domain\n\n\nfor i=1:n\n for j=1:n\n K1(i,j)=(i*j)*(t2^(j+i-1)-t1^(j+i-1))/(i+j-1); % K1 matrix corresponding to the x\"(t)\n K2(i,j)=j*((t2^(i+j))-(t1^(i+j)))/(i+j); % K2 matrix corresponding to the x'(t)\n K3(i,j)=(t2^(i+j+1)-(t1^(i+j+1)))/(i+j+1); % K3 matrix corresponding to the x(t)\n end\nend\n% Overall Matrix\nK=-a*K1+b*K2+c*K3;\n\n%Applying boundary conditions and Solving nxn system of equations \nfor i=1:n-1\n for j=1:n\n A(i,j)=K(i,j)+((j*a*t2^(j+i-1))-(j*a*t1^(j+i-1)));\n \n end\nend\n\n%Applying boundary conditions\nfor j=1:n\n A(n-1,j)=(t1^j);\n A(n,j)=(t2^j);\nend\n\nfor i=1:n-1\n B(i,1)=0;\nend\nB(n-1,1)=x1;\nB(n,1)=x2;\n\nC=inv(A)*B; % Ci: Coefficients of terms \n\nt=t1:dt:t2;\nt=t'; \n% Creating vertical axis values, x(t)\nx= zeros((t2-t1)/dt+1,1);\nfor i=1:(t2-t1)/dt+1\n for j=1:n\n x(i,1)=x(i,1)+ C(j,1)*(t(i,1)^j);\n end\nend\n\n% calculating x'(t)\ndx=zeros((t2-t1)/dt+1,1);\nfor i=2:(t2-t1)/dt+1\n dx(i,1)=(x(i)-x(i-1))/dt;\nend\n% calculating x\"(t)\nd2x=zeros((t2-t1)/dt+1,1);\nfor i=3:(t2-t1)/dt+1\n d2x(i,1)=(dx(i)-dx(i-1))/dt;\nend\n\n figure1 = figure('Color',[1 1 1]); \n% Plotting approximate solution via Galerkin method over the entire domain\nsubplot(3,1,1,'Parent',figure1);\n% Plotting the Approximate solution in green (Galerkin method over the entire domain)\nplot(t,x,'-.', 'Color','r', 'LineWidth',2), grid on; hold on; \n% Plotting the approximate dx\nsubplot(3,1,2,'Parent',figure1);\nplot(t,dx, '-.', 'Color','r', 'LineWidth',2), grid on; hold on; \n% Plotting the approximate d2u\nsubplot(3,1,3,'Parent',figure1);\nplot(t,d2x, '-.', 'Color','r', 'LineWidth',2), grid on; hold on; \n%% End of approximate solution via Galerkin method over the entire domain\n\n\n\n\n%% ==============Begin Calculating Exact Soution========================== \nr=roots([a b c]); % Roots of auxiliary equation\nr1=r(1); r2=r(2);\n\n% Bulding t-axis values\nt=t1:dt:t2; t=t'; \ns=size(t);\n\n% Bulding x(t) axis values\nx=zeros(s(1),1);\nif r1==r2 % For critically damped case\n \n C=inv([exp(r1*t1) t1*exp(r2*t1);exp(r1*t2) t2*exp(r2*t2)])*([x1;x2]);\n C1=C(1);\n C2=C(2);\n \n for i=1:s(1)\n x(i)=C1*exp(r1*t(i))+C2*t(i)*exp(r2*t(i));\n end\n \nelse % For Under-damped or Over-damped case\n \n C=inv([exp(r1*t1) exp(r2*t1);exp(r1*t2) exp(r2*t2)])*([x1;x2]);\n C1=C(1);\n C2=C(2);\n \n for i=1:s(1)\n x(i)=C1*exp(r1*t(i))+C2*exp(r2*t(i));\n end\nend\n\n% calculating x'(t)\ndx=zeros(s(1),1);\nfor i=2:s(1)\n dx(i,1)=(x(i)-x(i-1))/dt;\nend\n\n% calculating x\"(t)\nd2x=zeros(s(1),1);\nfor i=3:s(1)\n d2x(i,1)=(dx(i)-dx(i-1))/dt;\nend\n\n% Plotting Exact solution \nsubplot(3,1,1,'Parent',figure1);\n% Plotting the exact solution x(t) in blue\nplot(t,x, 'Color','b', 'LineWidth',2); \nxlabel('Time (sec)','FontSize',12);\nylabel('x(t) (m)','FontSize',12);\nlegend1 = legend(subplot(3,1,1),'show');\nlegend('Approximate x(t)','Exact x(t)')\n\n% Plotting the exact solution x'(t) in blue\nsubplot(3,1,2,'Parent',figure1);\nplot(t,dx, 'Color','b', 'LineWidth',2); \nxlabel('Time (sec)','FontSize',12);\nylabel('dx/dt (m/s)','FontSize',12);\nlegend1 = legend(subplot(3,1,2),'show');\nlegend('Approximate dx(t)','Exact dx(t)')\n\n% Plotting the exact solution x\"(t) in blue\nsubplot(3,1,3,'Parent',figure1);\nplot(t,d2x, 'Color','b', 'LineWidth',2);\nxlabel('Time (sec)','FontSize',12);\nylabel('d^2x/dt^2 m/s^2','FontSize',12);\nlegend1 = legend(subplot(3,1,3),'show');\nlegend('Approximate d2x(t)','Exact dx(t)')\nclc\n%% =====================End of exact solution============================== \n\n\n\n", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/39794-galerkins-method-for-solving-2nd-order-homogeneous-constant-coefficients-bvp/BVP_Galerkin1/BVP_Galerkin1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.944176857294597, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7928573842406845}}
{"text": "function [S,C]=allsums(varargin)\n% ALLSUMS Distribution of unique sums among all combinations of vectors.\n% [S,C]=ALLSUMS(IN) depending on input IN, will do one of two different\n% procedures for calculating all unique combinations of sums.\n%\n% The output vectors, S and C, are respectively the list of unique\n% sums, and the count distribution for those sums among all combinations.\n%\n%\n% SINGLE INPUT: \n%\n% [S,C]=ALLSUMS(VEC) for a single input vector of length N, returns the\n% distribution of unique sums among the (2^N)-1 combinations of\n% non-empty subsets of elements within VEC.\n%\n% EXAMPLE:\n% Number of ways to have a total of 250 using only the odd numbers\n% from 1 to 100.\n% [S,C]=allsums(1:2:100);\n% num=C(S==250)\n%\n%\n% MULTIPLE INPUTS:\n%\n% [S,C]=ALLSUMS(VEC,K) with vector VEC of length N, assumes the\n% equivalent scenario of rolling a N-sided die, with values VEC, \n% K times and returns the distributions of unique sums among all\n% N^K combinations of values.\n%\n% [S,C]=ALLSUMS(VEC1,K1,VEC2,K2,...) with vectors of length N1, N2, ...\n% assumes the equivalent scenario of rolling a N1-sided die, with\n% values VEC1, K1 times; then rolling a N2-sided dice, with values VEC2,\n% K2 times; etc. and returns the distribution of unique sums among\n% all (N1^K1)*(N2^K2)*... combinations of values\n%\n% SINGLE VECTOR, REPEATED\n% Probability distribution of rolling a regular 6-sided die 100 times\n% [S,C]=allsums(1:6,100);\n% plot(S,C./sum(C)), grid on\n%\n% MULTIPLE VECTORS, REPEATED\n% Probability of the total yielding exactly zero when rolling a\n% A) six-sided die with values [-5:0] ten times, and then a\n% B) ten-sided die with values [-4:5] twenty times.\n% [S,C]=allsums([-5:0],10,[-4:5],20);\n% prob=C(S==0)/sum(C)\n%\n\n% Mike Sheppard\n% Last Modified: 27-Oct-2011\n\n\n\n%ERROR CHECKING\nninputs=numel(varargin);\nswitch ninputs\n case 0\n error('allsums:Inputs','Requires at least one input');\n case 1\n VEC=varargin{1}; %Input vector\n if any(~isfinite(VEC))\n error('allsums:Inputs','Requires input vector to be numeric');\n end\n otherwise\n num=ninputs/2;\n if mod(ninputs,2)~=0\n error('allsums:Inputs','Requires inputs to be in [Vector],[Number] order');\n end\n for k=1:num\n ALLVEC{k}=varargin{2*k-1}; ALLNUMR{k}=varargin{2*k}; numr=ALLNUMR{k};\n if any(~isfinite(ALLVEC{k}))\n error('allsums:Inputs','Requires all input vectors to be numeric');\n end\n if any([~isfinite(numr) ~isscalar(numr) numr~=round(numr) numr<=0])\n error('allsums:Inputs','Requires number of repetitions to be a positive scalar integer');\n end\n end\nend\n\n\n\n%ALGORITHM\nswitch ninputs\n case 1\n % Distribution of unique sums among the (2^N)-1 combinations of\n % non-empty subsets of elements within VEC.\n S=[]; C=[];\n for k=1:numel(VEC)\n [S,ign,indx]=unique([S VEC(k) S+VEC(k)]);\n C=accumarray(indx',[C 1 C])';\n end\n S=S(:); C=C(:);\n otherwise\n % Distribution of unique sums among all (N1^K1)*(N2^K2)*... \n % combinations of vectors of length N_k repeated K_k times,\n % with values VEC_k each.\n S=0; C=1;\n for k=1:num\n VEC=ALLVEC{k}; VEC=VEC(:); numr=ALLNUMR{k};\n for n=1:numr\n tempv=bsxfun(@plus,S',VEC);\n tempc=repmat(C',length(VEC),1);\n [S,ign,indx]=unique(tempv(:));\n C=accumarray(indx,tempc(:));\n end\n end\nend\n\n\n\nend", "meta": {"author": "Sable", "repo": "mcbench-benchmarks", "sha": "ba13b2f0296ef49491b95e3f984c7c41fccdb6d8", "save_path": "github-repos/MATLAB/Sable-mcbench-benchmarks", "path": "github-repos/MATLAB/Sable-mcbench-benchmarks/mcbench-benchmarks-ba13b2f0296ef49491b95e3f984c7c41fccdb6d8/33454-all-sums/allsums.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567177, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7928263899150048}}
{"text": "% \n% Computing the numerical rank of a downdated matrix.\n%\n% \n% [r,Basis,C] = NumericalRankDowndate(A,pth,C,RC)\n%\n% \n% 1. A -- the target matrix;\n% 2. pth -- the index of row/column to be deleted;\n% 3. C -- cell array contains information required by updating/downdating;\n% 4. RC -- Set to 'row', then the pth row will be deleted.\n% Set to 'column', then the pth column will be deleted.\n%\n%