{"text": "function val=sincFun(x)\n%%SINCFUN Evaluate the sinc function. This is defined to be\n% sin(pi*x)/(pi*x). Note that some authors use the definition\n% sin(x)/x. This function accounts for the singularity at zero.\n%\n%INPUTS: x A matrix of the values at which to evaluate the sinc function.\n%\n%OUTPUTS: vals A matrix the same size as x where the sinc function has been\n% evaluted at each of the elements.\n%\n%The sinc function is described in [1]. It arises in many areas of signal\n%processing.\n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Sinc Function.\" From MathWorld--A Wolfram Web\n% Resource. http://mathworld.wolfram.com/SincFunction.html\n%\n%November 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n y=pi*x;\n sel=(y==0);\n val=sin(y)./y;\n val(sel)=1;\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/sincFun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418158002491, "lm_q2_score": 0.9196425289753969, "lm_q1q2_score": 0.8498801166144565}} {"text": "function [rdiff, Z, pval, stats] = correl_compare_indep_inputr(r1, r2, N1, N2, varargin)\n% Compare two Pearson's correlation values collected from independent samples\n% :Based on: www.stat-help.com/\n% :Usage:\n% ::\n% [rdiff, Z, pval, stats] = correl_compare_indep_inputr(r1, r2, N1, N2, varargin)\n%\n% :Inputs:\n%\n% **r1:**\n% Correlation coefficient for group 1\n%\n% **r2:**\n% Correlation coefficient for group 2\n%\n% **N1:**\n% Sample size for group 1 \n%\n% **N2:**\n% Sample size for group 2 \n%\n% :Outputs:\n%\n% **rdiff:**\n% Difference in correlation coefficient matrices (r1 - r2)\n%\n% **Z:**\n% Z score for difference in correlation coefficients.\n%\n% **pval:**\n% p value for two-tailed z-test\n%\n% **stats:**\n% Structure of variables including r1, r2, N1, N2, rdiff, zdiff, Z,\n% pval, myalpha, sig\n%\n% :Examples:\n% ::\n%\n% %generate two random input matrices (20 subjects x 5 variables)\n% r1 = .77;\n% r2 = .33;\n% N1 = 100;\n% N2 = 100;\n%\n% [rdiff, Z, pval, stats] = correl_compare_indep_inputr(r1, r2, N1, N2);\n%\n%\n% :See also:\n% - correl_compare_indep_inputr, correl_compare_permute*\n%\n%\n% ..\n% Tor Wager, March 2010\n% ..\n\n if nargin == 0\n disp('Using sample values for r1 r2 N1 N2')\n N1 = 100;\n N2 = 100;\n r1 = .33;\n r2 = .77;\n end\n\n rdiff = r1 - r2;\n\n sediff = sqrt(1/(N1-3) + 1/(N2-3)); % Standard error of difference between two standard normals, with df = N - 3 for correlation coeff\n zdiff = fisherz(r1) - fisherz(r2); % difference in Fisher's z values\n\n Z = zdiff ./ sediff; % Z-score (inferential stat)\n\n pval = 2 * (1 - normcdf(abs(Z))); % p-value\n\n myalpha = .05; % ROI\n sig = pval < myalpha;\n\n stats = struct('r1', r1, 'r2', r2, 'N1', N1, 'N2', N2, 'diff_r_values', rdiff, ...\n 'fishers_z_diff', zdiff, 'Z_stat', Z, 'p', pval, 'alpha', myalpha, 'sig', sig);\n\nend\n\n%out = correl_compare_dep(y1,y2, 'alpha',myalpha)\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/Statistics_tools/correl_compare_indep_inputr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545362802363, "lm_q2_score": 0.8962513772903669, "lm_q1q2_score": 0.8497848090252709}} {"text": "function f = gaussfunction(x,p)\n% f = gaussfunction(x,p)\n% p(1) = mean\n% p(2) = std deviation (sqrt(var))\n% p(3) = scale coefficient (if p(3)==1 then it is normalised)\nnormconst = 1/(sqrt(2*pi*p(2)^2));\nf = p(3)*normconst*exp(-((x-p(1)).^2)/(2*p(2)^2));\n\n\n\n", "meta": {"author": "aludnam", "repo": "MATLAB", "sha": "020b5cb02cc843e09a0ed689589382f18cce5e6d", "save_path": "github-repos/MATLAB/aludnam-MATLAB", "path": "github-repos/MATLAB/aludnam-MATLAB/MATLAB-020b5cb02cc843e09a0ed689589382f18cce5e6d/fit/fitfunctions/gaussfunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9683812309063187, "lm_q2_score": 0.8774767826757122, "lm_q1q2_score": 0.8497320468992224}} {"text": "function bernstein_polynomial_test02 ( )\n\n%*****************************************************************************80\n%\n%% BERNSTEIN_POLYNOMIAL_TEST02 tests BERNSTEIN_POLY_AB.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 11 July 2011\n%\n% Author:\n%\n% John Burkardt\n%\n n = 10;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BERNSTEIN_POLYNOMIAL_TEST02\\n' );\n fprintf ( 1, ' BERNSTEIN_POLY_AB evaluates Bernstein polynomials over an\\n' );\n fprintf ( 1, ' arbitrary interval [A,B].\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Here, we demonstrate that \\n' );\n fprintf ( 1, ' BPAB(N,K,A1,B1)(X1) = BPAB(N,K,A2,B2)(X2)\\n' );\n fprintf ( 1, ' provided only that\\n' );\n fprintf ( 1, ' (X1-A1)/(B1-A1) = (X2-A2)/(B2-A2).\\n' );\n\n x = 0.3;\n a = 0.0;\n b = 1.0;\n bern = bernstein_poly_ab ( n, a, b, x );\n \n fprintf ( 1, '\\n' );\n fprintf ( 1, ' N K A B X BPAB(N,K,A,B)(X)\\n' );\n fprintf ( 1, '\\n' );\n for k = 0 : n\n fprintf ( 1, ' %4d %4d %7.4f %7.4f %7.4f %14.6g\\n', n, k, a, b, x, bern(k+1) );\n end\n \n x = 1.3;\n a = 1.0;\n b = 2.0;\n bern = bernstein_poly_ab ( n, a, b, x );\n \n fprintf ( 1, '\\n' );\n fprintf ( 1, ' N K A B X BPAB(N,K,A,B)(X)\\n' );\n fprintf ( 1, '\\n' );\n for k = 0 : n\n fprintf ( 1, ' %4d %4d %7.4f %7.4f %7.4f %14.6g\\n', n, k, a, b, x, bern(k+1) );\n end\n\n x = 2.6;\n a = 2.0;\n b = 4.0;\n bern = bernstein_poly_ab ( n, a, b, x );\n \n fprintf ( 1, '\\n' );\n fprintf ( 1, ' N K A B X BPAB(N,K,A,B)(X)\\n' );\n fprintf ( 1, '\\n' );\n for k = 0 : n\n fprintf ( 1, ' %4d %4d %7.4f %7.4f %7.4f %14.6g\\n', n, k, a, b, x, bern(k+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/bernstein_polynomial/bernstein_polynomial_test02.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.9173026624116692, "lm_q1q2_score": 0.8497008780005025}} {"text": "function val=fallingFactorial(x,n)\n%%FALLINGFACTORIAL Evaluate the falling factorial (x)_n, which for n>=0 is\n% also known as the binomial polynomial, the lower\n% factorial, the factorial power, and the falling\n% factorial power. It is defined\n% (x)_n=x*(x-1)*(x-2)*...*(x-(n-1)). It can be expressed\n% as gamma(x+1)/gamma(x-n+1), which makes it continuous.\n% It is implemented using logarthmic functions to reduce\n% problems with overflows in intermediate results.\n%\n%INPUTS: x A scalar or matrix of first values in the product series of\n% x*(x-1)*...*(x-(n-1)). x cannot be negative.\n% n The scalar or matrix n value in the product series of\n% x*(x-1)*...*(x-(n-1)). If x is a matrix, n can be a scalar or a\n% matrix of the same size. If x is a scalar, n can be a scalar or\n% a matrix.\n%\n%OUTPUTS: val The falling factorial (x)_n for each x and the corresponding\n% n/ for each n and a single x depending on what is a matrix\n% and what is scalar. Note that if n>x, the falling factorial\n% is defined to be 0.\n%\n%The falling factorial is discussed in [1]. Note that\n%fallingFactorial(n,n)=factorial(n);\n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Falling Factorial.\" From MathWorld--A Wolfram Web\n% Resource. http://mathworld.wolfram.com/FallingFactorial.html\n%\n%October 2014 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nval=exp(gammaln(x+1)-gammaln(max(0,x-n+1)));\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/fallingFactorial.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012732322216, "lm_q2_score": 0.8976952825278492, "lm_q1q2_score": 0.8490413411893988}} {"text": "function value = cone_volume_3d ( r, h )\n\n%*****************************************************************************80\n%\n%% CONE_VOLUME_3D returns the volume of a cone in 3D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 20 May 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R, the radius of the base of the cone.\n%\n% Input, real H, the height of the cone.\n%\n% Output, real CONE_VOLUME_3D, the volume of the cone.\n%\n value = ( pi / 3.0 ) * h * r * r;\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/cone_volume_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.95041097139764, "lm_q2_score": 0.8933094110250333, "lm_q1q2_score": 0.8490110650909555}} {"text": "function [ n_data, n, area ] = hypersphere_01_area_values ( n_data )\n\n%*****************************************************************************80\n%\n%% HYPERSPHERE_01_AREA_VALUES returns some areas of the unit sphere in ND.\n%\n% Discussion:\n%\n% The formula for the surface area of the unit sphere in N dimensions is:\n%\n% Sphere_Unit_Area ( N ) = 2 * PI^(N/2) / Gamma ( N / 2 )\n%\n% Some values of the function include:\n%\n% N Area\n%\n% 2 2 * PI\n% 3 ( 4 / ) * PI\n% 4 ( 2 / 1) * PI^2\n% 5 ( 8 / 3) * PI^2\n% 6 ( 1 / 1) * PI^3\n% 7 (16 / 15) * PI^3\n% 8 ( 1 / 3) * PI^4\n% 9 (32 / 105) * PI^4\n% 10 ( 1 / 12) * PI^5\n%\n% For the unit sphere, Area(N) = N * Volume(N)\n%\n% In Mathematica, the function can be evaluated by:\n%\n% 2 * Pi^(n/2) / Gamma[n/2]\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% 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.\n% On input, if N_DATA is 0, the first test data is returned, and\n% N_DATA is set to the index of the test data. On each subsequent\n% call, N_DATA is incremented and that test data is returned. When\n% there is no more test data, N_DATA is set to 0.\n%\n% Output, integer N, the spatial dimension.\n%\n% Output, real AREA, the area of the unit sphere \n% in that dimension.\n%\n n_max = 20;\n\n area_vec = [ ...\n 0.2000000000000000E+01, ...\n 0.6283185307179586E+01, ...\n 0.1256637061435917E+02, ...\n 0.1973920880217872E+02, ...\n 0.2631894506957162E+02, ...\n 0.3100627668029982E+02, ...\n 0.3307336179231981E+02, ...\n 0.3246969701133415E+02, ...\n 0.2968658012464836E+02, ...\n 0.2550164039877345E+02, ...\n 0.2072514267328890E+02, ...\n 0.1602315322625507E+02, ...\n 0.1183817381218268E+02, ...\n 0.8389703410491089E+01, ...\n 0.5721649212349567E+01, ...\n 0.3765290085742291E+01, ...\n 0.2396678817591364E+01, ...\n 0.1478625959000308E+01, ...\n 0.8858104195716824, ...\n 0.5161378278002812 ];\n\n n_vec = [ ...\n 1, ...\n 2, ...\n 3, ...\n 4, ...\n 5, ...\n 6, ...\n 7, ...\n 8, ...\n 9, ...\n 10, ...\n 11, ...\n 12, ...\n 13, ...\n 14, ...\n 15, ...\n 16, ...\n 17, ...\n 18, ...\n 19, ...\n 20 ];\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 area = 0.0;\n else\n n = n_vec(n_data);\n area = area_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/hypersphere_properties/hypersphere_01_area_values.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075755433747, "lm_q2_score": 0.8824278571786139, "lm_q1q2_score": 0.8489905262620515}} {"text": "%% Radix-4 FFT Test Script\n% This file runs three versions of a Radix-4 FFT written in MATLAB:\n%\n% radix4FFT1_Float.m computes a radix-4 FFT for floating point data types\n%\n% radix4FFT2_FixPt.m computes a fixed point radix-4 FFT (requires Fixed\n% Point Toolbox)\n%\n% radix4FFT3_FixPtEML.m is an Embedded MATLAB version of the radix-4 FFT\n% that can be used in Simulink. You can also generate C code for this\n% code (using Real Time Workshop). This version can also be compiled\n% into a MEX'd executable that runs significantly faster than the fixed\n% point code.\n%\n% For a description of the radix-4 FFT algorithm see the following link to\n% DSPDesignLine.com:\n%\n% http://www.dspdesignline.com/showArticle.jhtml;jsessionid=5DBROAJQ3\n% SIWCQSNDLOSKHSCJUNN2JVN?articleID=204400676&queryText=freescale+fft \n%\n%% Set up a signal\n% The test signal is the sum of 2 sinusoids plus some noise. The test\n% signal is a complex signal with real and imaginary components.\na=256; % FFT Length\nt=0:1/a:(a-1)/a;\ns=(sin(2*pi*12*t)+.8*j*sin(2*pi*4.25*t)+.01*randn(size(t)))/2;\ns = floor(s*16384)/16384; %Quantized sum of 2 sines plus noise\nsubplot(211)\nplot(t,real(s))\nxlabel('time (sec)');ylabel('Amplitude');title('Test Signal - Real Component')\nsubplot(212)\nplot(t,imag(s))\nxlabel('time (sec)');ylabel('Amplitude');title('Test Signal - Imag Component')\n\n%% Test Original Floating Point Code\n% Run the Radix-4 algorithm as a floating point implementation.\n%\n% The function radix4FFT1_Float.m accepts real or complex floating point\n% inputs and calculates the FFT.\nS = radix4FFT1_Float(s);\nS = bitrevorder(S);\n\n% Calculate FFT using MATLAB function\nY = fft(s);\n\n% Compare accuracy of Radix-4 FFT to MATLAB's FFT\nerrs = double(S) - Y;\nSig = sum(abs(Y).^2)/a;\nNoise = sum(abs(errs).^2)/a;\nSNR = 10*log10(Sig/Noise);\nsprintf('SNR for 2 floating point FFT methods is: %6.2f dB', SNR)\n\nfigure\nplotPYYf(s,a)\n\n% The radix-4 FFT is nearly identical in accuracy to MATLAB's built in FFT\n% computation.\n%% Set Fixed Point Parameters\n% The Fixed Point Toolbox can convert a test signal to a true fixed point\n% data type with specified word lengths and fractional scaling. In this\n% case the test signal is a 16 bit integer with 15 fractional bits.\nwl = 16;\nsfi=fi(s,1,wl,wl-1); % Data is Q16,15\nsfi.RoundMode = 'nearest'; % Fixed Point Rounding, etc.\nsfi.OverflowMode = 'wrap';\nsfi.ProductMode = 'KeepMSB';\nsfi.ProductWordLength = wl*2;\nsfi.SumMode = 'KeepMSB';\nsfi.SumWordLength = wl*2;\nplot(t,real(sfi))\nxlabel('time (sec)');ylabel('Amplitude');title('Test Signal - Real Component')\n\n%% Fixed Point Test\n% Run the Radix-4 algorithm as a fixed point implementation.\n%\n% The function radix4FFT2_FixPt.m accepts fixed or floating point inputs\n% and calculates the FFT\nSFI = radix4FFT2_FixPt(sfi);\nSFI = bitrevorder(SFI);\n\n% Calculate FFT using MATLAB function\ny = fft(s);\n\n% Compare results\nerrs = double(SFI) - y;\nSig = sum(abs(y).^2)/a;\nNoise = sum(abs(errs).^2)/a;\nSNR = 10*log10(Sig/Noise);\nsprintf('SNR for fixed vs floating point methods is: %6.2f dB', SNR)\n\nplotPYYf(double(sfi),a)\n\n% As expected, the accuracy of the fixed point FFT is reduced compared to\n% the floating point computation.\n%% Set Fixed Point Parameters\n% The accuracy of the FFT for a shorter word length can be tested by\n% changing the input signal to a 14 bit integer with 13 fractional bits.\nwl = 14;\nsfi=fi(s,1,wl,wl-1); % Data is Q16,15\nsfi.RoundMode = 'nearest'; % Fixed Point Rounding, etc.\nsfi.OverflowMode = 'wrap';\nsfi.ProductMode = 'KeepMSB';\nsfi.ProductWordLength = wl*2;\nsfi.SumMode = 'KeepMSB';\nsfi.SumWordLength = wl*2;\nplot(t,real(sfi))\nxlabel('time (sec)');ylabel('Amplitude');title('Test Signal - Real Component')\n\n%% Fixed Point Test\n% Run the Radix-4 FFT algorithm with a lower precision data type.\n%\nSFI = radix4FFT2_FixPt(sfi);\nSFI = bitrevorder(SFI);\n\n% Calculate FFT using MATLAB function\ny = fft(s);\n\n% Compare results\nerrs = double(SFI) - y;\nSig = sum(abs(y).^2)/a;\nNoise = sum(abs(errs).^2)/a;\nSNR = 10*log10(Sig/Noise);\nsprintf('SNR for fixed vs floating point methods is: %6.2f dB', SNR)\n\nplotPYYf(double(sfi),a)\n\n% In this case there is an approximate loss of 12 dB of accuracy compared\n% to the 16 bit FFT computation\n\n%% Use emlmex to compile code into executable\n% The fixed point FFT code can be accelerated by changing the algorithm to\n% an EML-compliant algorithm and compiling it with the emlmex command. The\n% emlmex command will produce a mex'd version of the MATLAB algorithm.\nemlmex -o radix4FFT3_MX -eg {sfi} radix4FFT3_FixPtEML\n\n%% Show speed of non-compiled code\ntic;SFI = radix4FFT3_FixPtEML(sfi);toc\ntic;SFI = radix4FFT3_FixPtEML(sfi);toc\ntic;SFI = radix4FFT3_FixPtEML(sfi);toc\n\n%% Show speed of compiled code\ntic;SFI = radix4FFT3_MX(sfi);toc\ntic;SFI = radix4FFT3_MX(sfi);toc\ntic;SFI = radix4FFT3_MX(sfi);toc\n\n% The MEX'd version of the FFT code runs over 600 times faster than the\n% fixed point MATLAB algorithm.\n%\n%% Generate C source code for radix-4 FFT\n% EML compliant algorithms can be used to generate C source code using Real\n% Time Workshop. \nrtwcfg = emlcoder.RTWConfig\n\nemlc -v -s rtwcfg -eg {sfi} -o radix4FFT_C radix4FFT3_FixPtEML\n\n% The source code can be inspected in the emcprj directory\n\n%% Use the EML compliant FFT code in Simulink\n% The attached Simulink model hiperman_4_2007b_FixPt.mdl uses the radix-4\n% FFT algorithm in the OFDM_RX block (requires Simulink and Communications\n% Blockset).\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/22326-fixed-point-radix-4-fft/MLCentral/radix4_Script.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.944176857294597, "lm_q2_score": 0.8991213813246444, "lm_q1q2_score": 0.8489296001454797}} {"text": "%--- help for sym/jacobian ---\n%\n% JACOBIAN Jacobian matrix.\n% JACOBIAN(f,x) computes the Jacobian of the scalar or vector f\n% with respect to the vector x. The (i,j)-th entry of the result\n% is df(i)/dx(j). Note that when f is scalar, the Jacobian of f\n% is the gradient of f. Also, note that scalar x is allowed,\n% although this is just DIFF(f,x).\n% \n% Example:\n% syms x y z u v; jacobian([x*y*z; y; x+z],[x y z])\n% returns [y*z, x*z, x*y; 0, 1, 0; 1, 0, 1]\n% \n% jacobian(u*exp(v),[u;v])\n% returns [exp(v), u*exp(v)]\n% \n% See also SYM/CURL, SYM/DIFF, SYM/DIVERGENCE, SYM/GRADIENT, SYM/HESSIAN,\n% SYM/POTENTIAL, CURL, DIVERGENCE, HESSIAN, LAPLACIAN, VECTORPOTENTIAL,\n% SUBS.\n%", "meta": {"author": "jmaih", "repo": "RISE_toolbox", "sha": "1b2edfa27830c6d522f9d7d2335d33c3e4d84285", "save_path": "github-repos/MATLAB/jmaih-RISE_toolbox", "path": "github-repos/MATLAB/jmaih-RISE_toolbox/RISE_toolbox-1b2edfa27830c6d522f9d7d2335d33c3e4d84285/m/+utils/+numdiff/jacobian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9518632302488963, "lm_q2_score": 0.8918110432813418, "lm_q1q2_score": 0.8488821404294162}} {"text": "function y = laprnd(m, n, mu, sigma)\n%LAPRND generate i.i.d. laplacian random number drawn from laplacian distribution\n% with mean mu and standard deviation sigma. \n% mu : mean\n% sigma : standard deviation\n% [m, n] : the dimension of y.\n% Default mu = 0, sigma = 1. \n% For more information, refer to\n% http://en.wikipedia.org./wiki/Laplace_distribution\n\n% Author : Elvis Chen (bee33@sjtu.edu.cn)\n% Date : 01/19/07\n\n%Check inputs\nif nargin < 2\n error('At least two inputs are required');\nend\n\nif nargin == 2\n mu = 0; sigma = 1;\nend\n\nif nargin == 3\n sigma = 1;\nend\n\n% Generate Laplacian noise\nu = rand(m, n)-0.5;\nb = sigma / sqrt(2);\ny = mu - b * sign(u).* log(1- 2* abs(u));\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/13705-laplacian-random-number-generator/laprnd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9518632261523028, "lm_q2_score": 0.8918110440002044, "lm_q1q2_score": 0.8488821374602878}} {"text": "function [ X,h,R ] = generate_test_data(~)\n% GENERATE_TEST_DATA creates a sample data set for demonstration of the \n% Abel inversion algorithm. Based on the density distribution f \n% (polynomial function), the virtual measurement result h is calculated \n% via Abel transform:\n%\n% h(x) = 2* int_x^R f(r)*r/sqrt(r^2-x^2) dr (1)\n%\n%\n% written by C. Killer, Sept. 2013\n\nR=3; % radius\nX=(0:0.01:R-0.01)'; % spatial coordinates\n\n%polynomial distribution function\nf= (17.*(X./R).^4-32.*(X./R).^3+14.*(X./R).^2+1); \n\nh=zeros(length(X),1); % allocate result vector\n\nfor c=1:length(X) \n x=X(c);\n % evaluate Abel-transform equation (1)\n fun = @(r) (17.*(r./R).^4-32.*(r./R).^3+14.*(r./R).^2+1).*r./sqrt(r.^2 - x.^2);\n h(c,1)=2*integral(fun,x,R); \nend\n\n\nfigure; \nplot(X,f./max(f),'k','Linewidth',1.5); \nhold on; \nplot(X,h./max(h),'b','Linewidth',1.5); \ngrid on; box on; \nlegend('initial density distribution f(r)','measurement result h(r) (Abel-Transform of f(r))','Location','SouthWest')\ntitle('example with polynomial data sample (normalized for better comparison)')\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/43639-abel-inversion-algorithm/generate_test_data.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9674102571131692, "lm_q2_score": 0.8774767778695834, "lm_q1q2_score": 0.848880035289649}} {"text": "function [g, c, tmp, m]=kMeansCluster(m,k,isRand)\n% kMeansCluster - Simple k means clustering algorithm \n% Author: Kardi Teknomo, Ph.D. \n% \n% Purpose: classify the objects in data matrix based on the attributes \n% Criteria: minimize Euclidean distance between centroids and object points \n% For more explanation of the algorithm, see http://people.revoledu.com/kardi/tutorial/kMean/index.html \n% Output: matrix data plus an additional column represent the group of each object \n% \n% Example: m = [ 1 1; 2 1; 4 3; 5 4] or in a nice form \n% m = [ 1 1; \n% 2 1; \n% 4 3; \n% 5 4] \n% k = 2 \n% kMeansCluster(m,k) produces m = [ 1 1 1; \n% 2 1 1; \n% 4 3 2; \n% 5 4 2] \n% Input:\n% m - required, matrix data: objects in rows and attributes in columns \n% k - optional, number of groups (default = 1)\n% isRand - optional, if using random initialization isRand=1, otherwise input any number (default)\n% it will assign the first k data as initial centroids\n%\n% Local Variables\n% f - row number of data that belong to group i\n% c - centroid coordinate size (1:k, 1:maxCol)\n% g - current iteration group matrix size (1:maxRow)\n% i - scalar iterator \n% maxCol - scalar number of rows in the data matrix m = number of attributes\n% maxRow - scalar number of columns in the data matrix m = number of objects\n% temp - previous iteration group matrix size (1:maxRow)\n% z - minimum value (not needed)\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nif nargin<3, isRand=0; end\nif nargin<2, k=1; end\ntmp = [];\n\n[maxRow, maxCol]=size(m);\nif maxRow<=k, \n y=[m, 1:maxRow];\nelse\n\t\n\t% initial value of centroid\n if isRand,\n p = randperm(size(m,1)); % random initialization\n for i=1:k\n c(i,:)=m(p(i),:) \n \tend\n else\n for i=1:k\n c(i,:)=m(i,:); % sequential initialization\n \tend\n end\n \n\ttemp=zeros(maxRow,1); % initialize as zero vector\n \n\twhile 1,\n d=DistMatrix(m,c); % calculate objcets-centroid distances\n [z,g]=min(d,[],2); % find group matrix g\n if g==temp,\n break; % stop the iteration\n else\n temp=g; % copy group matrix to temporary variable\n end\n for i=1:k\n f=find(g==i);\n if f % only compute centroid if f is not empty\n c(i,:)=mean(m(find(g==i),:),1);\n end\n end\n\tend\n \n\ty=[m,g];\n \nend\n\n%The Matlab function kMeansCluster above call function DistMatrix as shown in the code below. It works for multi-dimensional Euclidean distance. Learn about other type of distance here.\n\n function d=DistMatrix(A,B)\n %%%%%%%%%%%%%%%%%%%%%%%%%\n % DISTMATRIX return distance matrix between points in A=[x1 y1 ... w1] and in B=[x2 y2 ... w2]\n % Copyright (c) 2005 by Kardi Teknomo, http://people.revoledu.com/kardi/\n %\n % Numbers of rows (represent points) in A and B are not necessarily the same.\n % It can be use for distance-in-a-slice (Spacing) or distance-between-slice (Headway),\n %\n % A and B must contain the same number of columns (represent variables of n dimensions),\n % first column is the X coordinates, second column is the Y coordinates, and so on.\n % The distance matrix is distance between points in A as rows\n % and points in B as columns.\n % example: Spacing= dist(A,A)\n % Headway = dist(A,B), with hA ~= hB or hA=hB\n % A=[1 2 3; 4 5 6; 2 4 6; 1 2 3]; B=[4 5 1; 6 2 0]\n % dist(A,B)= [ 4.69 5.83;\n % 5.00 7.00;\n % 5.48 7.48;\n % 4.69 5.83]\n %\n % dist(B,A)= [ 4.69 5.00 5.48 4.69;\n % 5.83 7.00 7.48 5.83]\n %%%%%%%%%%%%%%%%%%%%%%%%%%%\n [hA,wA]=size(A);\n [hB,wB]=size(B);\n if wA ~= wB, error(' second dimension of A and B must be the same'); end\n for k=1:wA\n C{k}= repmat(A(:,k),1,hB);\n D{k}= repmat(B(:,k),1,hA);\n end\n S=zeros(hA,hB);\n for k=1:wA\n S=S+(C{k}-D{k}').^2;\n end\n d=sqrt(S);\n\n", "meta": {"author": "sccn", "repo": "eeglab", "sha": "36d3982a63cde83fb279ab465b7a026ec2807c0a", "save_path": "github-repos/MATLAB/sccn-eeglab", "path": "github-repos/MATLAB/sccn-eeglab/eeglab-36d3982a63cde83fb279ab465b7a026ec2807c0a/functions/sigprocfunc/kmeanscluster.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.9241418152779357, "lm_q1q2_score": 0.8488060020726002}} {"text": "% In this small MATLAB script, we compute the least squares solution to a\n% regression problem subject to L1 regularization, which rewards \"sparse\"\n% models that have regression coefficients of zero. See, for instance,\n% the work in the \"Lasso\" by the statistician Robert Tibshirani.\n%\n% Copyright (C) 2008 Peter Carbonetto. All Rights Reserved.\n% This code is published under the Eclipse Public License.\n%\n% Author: Peter Carbonetto\n% Dept. of Computer Science\n% University of British Columbia\n% September 18, 2008\n\n% Experiment parameters.\nlambda = 1; % Level of L1 regularization.\nn = 100; % Number of training examples.\ne = 1; % Std. dev. in noise of outputs.\nbeta = [ 0 0 2 -4 0 0 -1 3 ]'; % \"True\" regression coefficients.\n\n% Set the random number generator seed.\nseed = 7;\nrand('state',seed);\nrandn('state',seed);\n\n% CREATE DATA SET.\n% Generate the input vectors from the standard normal, and generate the\n% binary responses from the regression with some additional noise, and then\n% transform the results using the logistic function. The variable \"beta\" is\n% the set of true regression coefficients.\nm = length(beta); % Number of features.\nA = randn(n,m); % The n x m matrix of examples.\nnoise = e * randn(n,1); % Noise in outputs.\ny = A * beta + noise; % The binary outputs.\n\n% COMPUTE SOLUTION WITH IPOPT.\n% Compute the L1-regularized maximum likelihood estimator.\nw = lasso(A,y,lambda);\nfprintf('Solution:\\n');\ndisp(w);\n\n\n", "meta": {"author": "vigente", "repo": "gerardus", "sha": "4d7c5195b826967781f1bb967872410e66b7cd3d", "save_path": "github-repos/MATLAB/vigente-gerardus", "path": "github-repos/MATLAB/vigente-gerardus/gerardus-4d7c5195b826967781f1bb967872410e66b7cd3d/matlab/ThirdPartyToolbox/OptiToolbox/Solvers/ipopt/distribution/examples/examplelasso.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811641488383, "lm_q2_score": 0.8791467738423874, "lm_q1q2_score": 0.8487117359896594}} {"text": "% Euclidean projection on a halfspace\n% Sec. 8.1.1, Boyd & Vandenberghe \"Convex Optimization\"\n% Joelle Skaf - 10/04/05\n%\n% The projection of x0 on a halfspace C = {x | a'*x <= b} is given by\n% minimize || x - x0 ||^2\n% s.t. a'*x <= b\n% It is also given by P_C(x0) = x0 + (b - a'*x0)*a/||a||^2 if a'*x0 > b\n% and x0 if a'*x0 <=b\n\n% Input data\nrandn('seed',0);\nn = 10;\na = randn(n,1);\nb = randn(1);\nx0 = randn(n,1); % a'*x0 <=b\nx1 = x0 + a; % a'*x1 > b\n\n% Analytical solution\nfprintf(1,'Computing the analytical solution for the case where a^T*x0 <=b...');\npc_x0 = x0;\nfprintf(1,'Done! \\n');\nfprintf(1,'Computing the analytical solution for the case where a^T*x0 > b...');\npc_x1 = x1 + (b - a'*x1)*a/norm(a)^2;\nfprintf(1,'Done! \\n');\n\n% Solution via QP\nfprintf(1,'Computing the solution of the QP for the case where a^T*x0 <=b...');\ncvx_begin quiet\n variable xs0(n)\n minimize ( norm(xs0 - x0).^2 )\n a'*xs0 <= b; %#ok\ncvx_end\nfprintf(1,'Done! \\n');\n\nfprintf(1,'Computing the solution of the QP for the case where a^T*x0 > b...');\ncvx_begin quiet\n variable xs1(n)\n minimize ( norm(xs1 - x1).^2 )\n a'*xs1 <= b; %#ok\ncvx_end\nfprintf(1,'Done! \\n');\n\n% Verification\ndisp('-----------------------------------------------------------------');\ndisp('Verifying that p_C(x0) and x0_star are equal in the case where a^T*x0 <=b');\ndisp(['||p_C(x0) - x0_star|| = ' num2str(norm(xs0 - pc_x0))]);\ndisp('They should be equal to working precision');\ndisp('Verifying that p_C(x1) and x1_star are equal in the case where a^T*x1 > b');\ndisp(['||p_C(x1) - x1_star|| = ' num2str(norm(xs1 - pc_x1))]);\ndisp('They should be equal to working precision');\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/cvxbook/Ch08_geometric_probs/eucl_proj_hlf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.938124016006303, "lm_q2_score": 0.9046505261034854, "lm_q1q2_score": 0.8486743846304166}} {"text": "function [ r, center ] = sphere_dia2imp_3d ( p1, p2 )\n\n%*****************************************************************************80\n%\n%% SPHERE_DIA2IMP_3D converts a diameter to an implicit sphere in 3D.\n%\n% Discussion:\n%\n% An implicit sphere in 3D satisfies the equation:\n%\n% ( X - CENTER(1) )**2 + ( Y - CENTER(2) )**2 + ( Z - CENTER(3) )**2 = R**2\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 P1(3), P2(3), are two points which form a diameter\n% of the sphere.\n%\n% Output, real R, the computed radius of the sphere.\n%\n% Output, real CENTER(3), the computed center of the sphere.\n%\n dim_num = 3;\n\n r = 0.5 * sqrt ( sum ( ( p2(1:dim_num) - p1(1:dim_num) ).^2 ) );\n\n center(1:dim_num) = 0.5 * ( p1(1:dim_num) + p2(1:dim_num) );\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_dia2imp_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482725, "lm_q2_score": 0.9073122269997506, "lm_q1q2_score": 0.8486513297663663}} {"text": "function dot = permutation_puzzle ( n )\n\n%*****************************************************************************80\n%\n%% PERMUTATION_PUZZLE exhibits a peculiar property of permutations.\n%\n% Discussion:\n%\n% Let P1 and P2 be arbitrary permutations of the integers from 1 to 10.\n%\n% Pair corresponding entries of the permutations to create the set of 10 \n% points (P1(1),P2(1)) through (P1(10),P2(10)). Now subtract 5, that is, \n% N/2, from the X and Y coordinates of each point so that their average value \n% is zero. Then apply a rotation of 45 degrees to each vector.\n%\n% Now instead of looking at 10 vectors (X(I),Y(I)), each of length 2, consider \n% the data as two vectors X and Y, each of length 10. If the instructions have \n% been followed correctly, then X are Y are perpendicular to each other in \n% 10-dimensional space. \n%\n% In fct, this seems to be true for all the permutations you try.\n% You can even set P1 and P2 equal. \n% You can try other values of N.\n%\n% It does not work for most other rotation angles. For example, a 30 degree\n% rotation will not work.\n%\n% Once you've picked P1 and P2, you can take an arbitrary vector Q,\n% set Q1 = Q(P1) and Q2 = Q(P2) and carry out the transformation on Q1 and\n% Q2 instead of on P1 and P2, and it will still work.\n%\n% The question is, can you show that all these statements are true, and\n% can you explain why?\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 September 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the vector length.\n%\n% Output, real DOT, the dot product of the two vectors.\n%\n p1 = randperm ( n );\n p2 = randperm ( n );\n\n xy = [ p1; p2 ];\n\n xy = xy - ( n / 2 );\n\n angle = pi / 4;\n\n A = [ cos ( angle ), - sin ( angle ); ...\n sin ( angle ), cos ( angle ) ]; \n\n xy = A * xy;\n\n dot = xy(1,1:n) * xy(2,1:n)';\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/puzzles/permutation_puzzle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897542390751, "lm_q2_score": 0.90192067652954, "lm_q1q2_score": 0.8485177316153663}} {"text": "function d = chord2arclen(d, R)\n% CHORD2ARCLEN Euclidean chord length distances to sphere arc length\n% distances.\n%\n% DARCLEN = chord2arclen(DCHORD, R)\n%\n% DCHORD is a scalar, vector, matrix or general array with Euclidean\n% chord length distances. Units are metres.\n%\n% R is the radius of the sphere. Units are metres. By default, R=1.\n%\n% DARCLEN has the same size as DCHORD, with the corresponding geodesic\n% (great circle) distances. Units are metres.\n%\n% See also: arclen2chord.\n\n% Author: Ramon Casero \n% Copyright © 2014 University of Oxford\n% Version: 0.1.0\n%\n% University of Oxford means the Chancellor, Masters and Scholars of\n% the University of Oxford, having an administrative office at\n% Wellington Square, Oxford OX1 2JD, UK. \n%\n% This file is part of Gerardus.\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. The offer of this\n% program under the terms of the License is subject to the License\n% being interpreted in accordance with English Law and subject to any\n% action against the University of Oxford being under the jurisdiction\n% of the English Courts.\n%\n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see\n% .\n\n% check arguments\nnarginchk(1, 2);\nnargoutchk(0, 1);\n\n% defaults\nif (nargin < 2 || isempty(R))\n R = 1.0;\nend\n\n% convert chord length distances to arc length distances (both in metres)\nd = 2*R * asin(d/(2*R));\n", "meta": {"author": "vigente", "repo": "gerardus", "sha": "4d7c5195b826967781f1bb967872410e66b7cd3d", "save_path": "github-repos/MATLAB/vigente-gerardus", "path": "github-repos/MATLAB/vigente-gerardus/gerardus-4d7c5195b826967781f1bb967872410e66b7cd3d/matlab/ManifoldToolbox/chord2arclen.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9615338079816756, "lm_q2_score": 0.8824278772763471, "lm_q1q2_score": 0.8484842371067127}} {"text": "function x = circle01_to_circle ( alpha, r, c, n, x )\n\n%*****************************************************************************80\n%\n%% CIRCLE01_TO_CIRCLE maps points from the unit circle to a general one.\n%\n% Discussion:\n%\n% To map data, defined in the unit circle, to a circle with radius R\n% and center C, and to rotate the original data by an angle of ALPHA first,\n%\n% X = R * ( cos(alpha) -sin(alpha) ) * X + CX\n% Y ( sin(alpha) cos(alpha) ) Y CY\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 21 May 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real ALPHA, the angle, in radians, by which the unit circle\n% data should be rotated.\n%\n% Input, real R, the scale factor by which the unit circle data\n% should be stretched.\n%\n% Input, real C(2,1), the translation to be applied.\n%\n% Input, integer N, the number of points to transform.\n%\n% Input/output, real X(2,N), the points to be transformed.\n%\n\n%\n% Rotation:\n%\n% Don't write \"cos ( alpha )\" instead of \"cos(alpha)\" because Matlab's\n% bebuggered automatic array creator thinks blanks separate matrix elements!\n%\n rot = [ cos(alpha), -sin(alpha); ...\n sin(alpha), cos(alpha) ];\n\n x(1:2,1:n) = c(1:2,1:2) * x(1:2,1:n);\n%\n% Dilation:\n%\n x(1:2,1:n) = r * x(1:2,1:n);\n%\n% Translation:\n%\n x(1:2,1:n) = x(1:2,1:n) + repmat ( c(1:2,1), 1, n );\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/circle_segment/circle01_to_circle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545304202039, "lm_q2_score": 0.8947894731166139, "lm_q1q2_score": 0.8483986927078248}} {"text": "function varargout = circleArcToPolyline(arc, N)\n%CIRCLEARCTOPOLYLINE Convert a circle arc into a series of points\n%\n% P = circleArcToPolyline(ARC, N);\n% convert the circle ARC into a series of N points. \n% ARC is given in the format: [XC YC R THETA1 DTHETA]\n% where XC and YC define the center of the circle, R its radius, THETA1\n% is the start of the arc and DTHETA is the angle extent of the arc. Both\n% angles are given in degrees. \n% N is the number of vertices of the resulting polyline, default is 65.\n%\n% The result is a N-by-2 array containing coordinates of the N points. \n%\n% [X Y] = circleArcToPolyline(ARC, N);\n% Return the result in two separate arrays with N lines and 1 column.\n%\n%\n% See also:\n% circles2d, circleToPolygon, drawCircle, drawPolygon\n%\n%\n% ---------\n% author : David Legland \n% created the 22/05/2006.\n% Copyright 2010 INRA - Cepia Software Platform.\n%\n\n% HISTORY\n% 2011-03-30 use angles in degrees, add default value for N\n% 2011-12-09 rename to circleArcToPolyline\n\n\n% default value for N\nif nargin < 2\n N = 65;\nend\n\n% vector of positions\nt0 = deg2rad(arc(4));\nt1 = t0 + deg2rad(arc(5));\nt = linspace(t0, t1, N)';\n\n% compute coordinates of vertices\nx = arc(1) + arc(3) * cos(t);\ny = arc(2) + arc(3) * sin(t);\n\n% format output\nif nargout <= 1\n varargout = {[x y]};\nelse\n varargout = {x, y};\nend\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/geom2d/circleArcToPolyline.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9481545348152282, "lm_q2_score": 0.8947894689081711, "lm_q1q2_score": 0.8483986926501921}} {"text": "function d = dsphere ( p, xc, yc, zc, r )\n\n%*****************************************************************************80\n%\n%% DSPHERE returns the signed distance of one or more points to a sphere.\n%\n% Discussion:\n%\n% The corresponding routine in 2D is called DCIRCLE.\n%\n% Licensing:\n%\n% (C) 2004 Per-Olof Persson. \n% See COPYRIGHT.TXT for details.\n%\n% Reference:\n%\n% Per-Olof Persson and Gilbert Strang,\n% A Simple Mesh Generator in MATLAB,\n% SIAM Review,\n% Volume 46, Number 2, June 2004, pages 329-345.\n%\n% Parameters:\n%\n% Input, real P(NP,3), the point coordinates.\n%\n% Input, real XC, YC, ZC, the coordinates of the center of the sphere.\n%\n% Input, real R, the radius of the sphere.\n%\n% Output, real D(NP), the signed distance of each point to the\n% sphere. The point is inside, on, or outside the sphere depending\n% on whether D is negative, zero, or positive.\n%\n d = sqrt ( ( p(:,1) - xc ).^2 ...\n + ( p(:,2) - yc ).^2 ...\n + ( p(:,3) - zc ).^2 ) - r;\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/distmesh/dsphere.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966717067253, "lm_q2_score": 0.8962513800615313, "lm_q1q2_score": 0.8483885733788048}} {"text": "function li = lagrange_value ( nd, xd, ni, xi ) \n\n%*****************************************************************************80\n%\n%% LAGRANGE_VALUE evaluates 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 LI(NI,ND), the value, at the I-th point XI, of the\n% Jth basis function.\n%\n li = zeros ( ni, nd );\n \n for i = 1 : ni\n for j = 1 : nd\n li(i,j) = prod ( ( xi(i) - xd(1:j-1) ) ./ ( xd(j) - xd(1:j-1) ) ) ...\n * prod ( ( xi(i) - xd(j+1:nd) ) ./ ( xd(j) - xd(j+1:nd) ) );\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_value.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065459, "lm_q2_score": 0.8976952948443462, "lm_q1q2_score": 0.8483173063517556}} {"text": "function J = computeCostMulti(X, y, theta)\n%COMPUTECOSTMULTI Compute cost for linear regression with multiple variables\n% J = COMPUTECOSTMULTI(X, y, theta) computes the cost of using theta as the\n% parameter for linear regression to fit the data points in X and y\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta\n% You should set J to the cost.\n\ny_pred = X * theta; % X.shape=(m,3) theta.shape=(3,1)\nJ = 1/(2*m) * sum((y_pred - y).^2); \n\n\n\n% =========================================================================\n\nend\n", "meta": {"author": "imLogM", "repo": "Machine_Learning_AndrewNg", "sha": "1d499e8e2738032dc85e869ba55c32eb24da288d", "save_path": "github-repos/MATLAB/imLogM-Machine_Learning_AndrewNg", "path": "github-repos/MATLAB/imLogM-Machine_Learning_AndrewNg/Machine_Learning_AndrewNg-1d499e8e2738032dc85e869ba55c32eb24da288d/machine-learning-ex1/ex1/computeCostMulti.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248191350351, "lm_q2_score": 0.9032942145139149, "lm_q1q2_score": 0.8482156864096525}} {"text": "function [phi,dphi]=pt2BarycentricTriangCoords(x,v1,v2,v3)\n%%PT2BARYCENTRICTIANGCOORDS Convert a point into barycentric points with\n% respect to the vertices of a triangle in 2D. This solves for a\n% specific set of phi such that\n% x=phi(1)*v1+phi(2)*v2+phi(3)*v3\n% and sum(phi)=1. If x is inside the triangle, then phi>=0.\n%\n%INPUTS: x The 2X1 point whose barycentric coordiantes are desired.\n% v1,v2,v3 The three 2X1 vertices of the triangle. It doens't matter if\n% they are in clockwise or counterclockwise order.\n%\n%OUTPUTS: phi The 3X1 set of barycentric coordinates of x.\n% dPhi A 3X2 set of partial derivatives of phi (rows) with respect\n% to the components of x (columns).\n%\n%The barycentric coordinate system on a triangle is described in Section 2\n%of [1].\n%\n%EXAMPLE:\n%In this example, coordinates inside a triangle are obtained. It is\n%verified that the returned derivatives are (within finite precision\n%limits) within the bounds of what one gets with finite diferencing. Also,\n%the normalization of the weights is verified and the relative error of the\n%interpolated values is computed and is also negligible within finite\n%precision limits.\n% v1=[-2;3];\n% v2=[11;0];\n% v3=[1;1];\n% x=[4;1.5];\n% [phi,dphi]=pt2BarycentricTriangCoords(x,v1,v2,v3);\n% \n% f=@(y)pt2BarycentricTriangCoords(y,v1,v2,v3);\n% dPhiNumDiff=numDiff(x,f,3);\n% \n% RelDerivError=max(max(abs((dPhiNumDiff-dphi)./dPhiNumDiff)))\n% normalizationError=sum(phi)-1\n% \n% interpPoint=phi(1)*v1+phi(2)*v2+phi(3)*v3;\n% RelErrVal=max(abs((interpPoint-x)./x))\n%\n%REFERENCES:\n%[1] M. S. Floater, \"Generalized barycentric coordinates and applications,\"\n% Acta Numerica, vol. 24, pp. 161-214, 1 May 2015.\n%\n%September 2021 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nAv=triangleArea(v1,v2,v3);\n\nphi=zeros(3,1);\nphi(1)=triangleArea(x,v2,v3)/Av;\nphi(2)=triangleArea(x,v3,v1)/Av;\nphi(3)=triangleArea(x,v1,v2)/Av;\n\nif(nargout>1) \n dphi=zeros(3,2);\n \n dphi(1,:)=[(v2(2)-v3(2)),(v3(1)-v2(1))]/(2*Av);\n dphi(2,:)=[(v3(2)-v1(2)),(v1(1)-v3(1))]/(2*Av);\n dphi(3,:)=[(v1(2)-v2(2)),(v2(1)-v1(1))]/(2*Av);\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/Coordinate_Systems/Barycentric_Coordinate_Systems/pt2BarycentricTriangCoords.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248208414329, "lm_q2_score": 0.9032941975921684, "lm_q1q2_score": 0.8482156720610918}} {"text": "clear;\n\t\t% Setarea formatului de scriere a randurilor\nformat compact\n % Definirea functiei de integrat\nF=inline('1./x');\n\t\t% Incarcarea vectorului x cu elementele cuprinse\n\t\t% intre limitele de integrare\nx=1:1e-2:2;\n\t\t% Evaluarea functiei de integrat in aceste puncte\ny=feval(F,x);\n\t\t% Incarcarea solutiei exacte\nsol_exact=log(2); \n % Calcularea aproximativa a integralei cu\n\t\t% ajutorul metodei lui Simpson\nI_S=quad(F,1,2);\n\t\t% Calcularea erorii relative la aceasta metoda\neroare_S=abs(I_S-sol_exact)/sol_exact*100; \n\t\t% Afisarea rezultatelor\ndisp(['Solutia exacta a integralei= ',num2str(sol_exact)]);\ndisp(' ');\ndisp('Solutia aproximativa a integralei');\ndisp(['prin metoda lui Simpson=', num2str(I_S)]); \ndisp(['Eroarea relativa= ',num2str(eroare_S),' %']);\n\t\t% Calcularea aproximativa a integralei cu\n\t\t% ajutorul metodei lui Lobatto\nI_L=quadl(F,1,2);\n\t\t% Calcularea erorii relative la aceasta metoda\neroare_L=abs(I_L-sol_exact)/sol_exact*100; \n\t\t% Afisarea rezultatelor\ndisp(' ');\ndisp('Solutia aproximativa a integralei ');\ndisp(['prin metoda lui Lobatto=', num2str(I_L)]); \ndisp(['Eroarea relativa= ',num2str(eroare_L),' %']);\n\t\t% Calcularea aproximativa a integralei cu\n\t\t% ajutorul metodei trapezelor\nI_t=trapz(x,y);\n\t\t% Calcularea erorii relative la aceasta metoda\neroare_t=abs(I_t-sol_exact)/sol_exact*100; \n\t\t% Afisarea rezultatelor\ndisp(' ');\ndisp('Solutia aproximativa a integralei ');\ndisp(['prin metoda trapezelor=', num2str(I_t)]); \ndisp(['Eroarea relativa= ',num2str(eroare_t),' %']);\n\t\t% Generarea unui vector cu erorile obtinute \n\t\t% la diferite metode\neror=[eroare_S, eroare_L,eroare_t];\n\t\t% Determinarea erorii minime\n\t\t% - val_eroare contine valoarea minima \n\t\t% din vectorul eror\n\t\t% - nr_eroare contine numarul elementului \n\t\t% minim din vectorul eror\n[val_eroare, nr_eroare]=min(eror);\n\t\t% Afisarea erorii minime si a metodei cu ajutorul \n\t\t% careia s-a obtinut\ndisp(' ');\ndisp(['Eroarea cea mai mica de ',num2str(val_eroare)]);\nswitch nr_eroare\n case 1\n\t disp('s-a obtinut cu ajutorul metodei Simpson');\n case 2\n\t disp('s-a obtinut cu ajutorul metodei Lobatto');\n case 3 \n\t disp('s-a obtinut cu ajutorul metodei trapezelor');\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/8416-widely-used-programming-environments-in-electrical-engineering-matlab/9/Ex_9_2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475699138558, "lm_q2_score": 0.8991213684847577, "lm_q1q2_score": 0.8481839580177166}} {"text": "function [ p1, p2, p3 ] = plane_imp2exp_3d ( a, b, c, d )\n\n%*****************************************************************************80\n%\n%% PLANE_IMP2EXP_3D converts an implicit plane to explicit form in 3D.\n%\n% Discussion:\n%\n% The implicit form of a plane in 3D is\n%\n% A * X + B * Y + C * Z + D = 0.\n%\n% The explicit form of a plane in 3D is\n%\n% the plane through P1, P2 and P3.\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 A, B, C, D, the implicit plane parameters.\n%\n% Output, real P1(3,1), P2(3,1), P3(3,1), three points on the plane.\n%\n [ pp, normal ] = plane_imp2normal_3d ( a, b, c, d );\n\n [ p1, p2, p3 ] = plane_normal2exp_3d ( pp, normal );\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_imp2exp_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9539661002182847, "lm_q2_score": 0.8887587927558434, "lm_q1q2_score": 0.8478457595600025}} {"text": "function v = cheby_t_poly ( m, n, x )\n\n%*****************************************************************************80\n%\n%% CHEBY_T_POLY evaluates Chebyshev polynomials T(n,x).\n%\n% Discussion:\n%\n% Chebyshev polynomials are useful as a basis for representing the\n% approximation of functions since they are well conditioned, in the sense\n% that in the interval [-1,1] they each have maximum absolute value 1.\n% Hence an error in the value of a coefficient of the approximation, of\n% size epsilon, is exactly reflected in an error of size epsilon between\n% the computed approximation and the theoretical approximation.\n%\n% Typical usage is as follows, where we assume for the moment\n% that the interval of approximation is [-1,1]. The value\n% of N is chosen, the highest polynomial to be used in the\n% approximation. Then the function to be approximated is\n% evaluated at the N+1 points XJ which are the zeroes of the N+1-th\n% Chebyshev polynomial. Let these values be denoted by F(XJ).\n%\n% The coefficients of the approximation are now defined by\n%\n% C(I) = 2/(N+1) * sum ( 1 <= J <= N+1 ) F(XJ) T(I,XJ)\n%\n% except that C(0) is given a value which is half that assigned\n% to it by the above formula,\n%\n% and the representation is\n%\n% F(X) approximated by sum ( 0 <= J <= N ) C(J) T(J,X)\n%\n% Now note that, again because of the fact that the Chebyshev polynomials\n% have maximum absolute value 1, if the higher order terms of the\n% coefficients C are small, then we have the option of truncating\n% the approximation by dropping these terms, and we will have an\n% exact value for maximum perturbation to the approximation that\n% this will cause.\n%\n% It should be noted that typically the error in approximation\n% is dominated by the first neglected basis function (some multiple of\n% T(N+1,X) in the example above). If this term were the exact error,\n% then we would have found the minimax polynomial, the approximating\n% polynomial of smallest maximum deviation from the original function.\n% The minimax polynomial is hard to compute, and another important\n% feature of the Chebyshev approximation is that it tends to behave\n% like the minimax polynomial while being easy to compute.\n%\n% To evaluate a sum like \n%\n% sum ( 0 <= J <= N ) C(J) T(J,X), \n%\n% Clenshaw's recurrence formula is recommended instead of computing the\n% polynomial values, forming the products and summing.\n%\n% Assuming that the coefficients C(J) have been computed\n% for J = 0 to N, then the coefficients of the representation of the\n% indefinite integral of the function may be computed by\n%\n% B(I) = ( C(I-1) - C(I+1))/2*(I-1) for I=1 to N+1, \n%\n% with\n% \n% C(N+1)=0\n% B(0) arbitrary. \n%\n% Also, the coefficients of the representation of the derivative of the \n% function may be computed by:\n%\n% D(I) = D(I+2)+2*I*C(I) for I=N-1, N-2, ..., 0, \n%\n% with\n%\n% D(N+1) = D(N)=0.\n%\n% Some of the above may have to adjusted because of the irregularity of C(0).\n%\n% Differential equation:\n%\n% (1-X*X) Y'' - X Y' + N N Y = 0\n%\n% Formula:\n%\n% T(N,X) = COS(N*ARCCOS(X))\n%\n% First terms:\n%\n% T(0,X) = 1\n% T(1,X) = 1 X\n% T(2,X) = 2 X^2 - 1\n% T(3,X) = 4 X^3 - 3 X\n% T(4,X) = 8 X^4 - 8 X^2 + 1\n% T(5,X) = 16 X^5 - 20 X^3 + 5 X\n% T(6,X) = 32 X^6 - 48 X^4 + 18 X^2 - 1\n% T(7,X) = 64 X^7 - 112 X^5 + 56 X^3 - 7 X\n%\n% Inequality:\n%\n% abs ( T(N,X) ) <= 1 for -1 <= X <= 1\n%\n% Orthogonality:\n%\n% For integration over [-1,1] with weight\n%\n% W(X) = 1 / sqrt(1-X*X), \n%\n% if we write the inner product of T(I,X) and T(J,X) as\n%\n% < T(I,X), T(J,X) > = integral ( -1 <= X <= 1 ) W(X) T(I,X) T(J,X) dX\n%\n% then the result is:\n%\n% 0 if I /= J\n% PI/2 if I == J /= 0\n% PI if I == J == 0\n%\n% A discrete orthogonality relation is also satisfied at each of\n% the N zeroes of T(N,X): sum ( 1 <= K <= N ) T(I,X) * T(J,X)\n% = 0 if I /= J\n% = N/2 if I == J /= 0\n% = N if I == J == 0\n%\n% Recursion:\n%\n% T(0,X) = 1,\n% T(1,X) = X,\n% T(N,X) = 2 * X * T(N-1,X) - T(N-2,X)\n%\n% T'(N,X) = N * ( -X * T(N,X) + T(N-1,X) ) / ( 1 - X^2 )\n%\n% Special values:\n%\n% T(N,1) = 1\n% T(N,-1) = (-1)^N\n% T(2N,0) = (-1)^N\n% T(2N+1,0) = 0\n% T(N,X) = (-1)^N * T(N,-X)\n%\n% Zeroes:\n%\n% M-th zero of T(N,X) is cos((2*M-1)*PI/(2*N)), M = 1 to N\n%\n% Extrema:\n%\n% M-th extremum of T(N,X) is cos(PI*M/N), M = 0 to N\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 26 March 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, the number of evaluation points.\n%\n% Input, integer N, the highest polynomial to compute.\n%\n% Input, real X(M,1), the evaluation points.\n%\n% Output, real V(M,N+1), the values of the Chebyshev polynomials \n% 0 through N at X(1:M).\n%\n if ( n < 0 )\n c = [];\n return\n end\n\n v = zeros ( m, n + 1 );\n\n v(1:m,1) = 1.0;\n\n if ( n < 1 )\n return\n end\n\n x = x(:);\n\n v(1:m,2) = x(1:m,1);\n \n for i = 2 : n\n v(1:m,i+1) = 2.0 * x(1:m,1) .* v(1:m,i) - v(1:m,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/polpak/cheby_t_poly.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768144, "lm_q2_score": 0.8962513828326955, "lm_q1q2_score": 0.8476756962808897}} {"text": "%book : Signals and Systems Laboratory with MATLAB \n%by Alex Palamides & Anastasia Veloni\n\n% FS of periodic signals \n\n%x(t)= 1, 0=2.\n%\n%OUTPUTS: rPhiList The nXN values convert from Cartesian coordinates to \n% hyperspherical coordinates. Each value is a range r\n% (0<=r=0)\n phiList(curDim)=0;\n else\n phiList(curDim)=pi;\n end\n else\n phiList(curDim)=acos(x(curDim)/normVal);\n end\nend\n\nif(x(n)<0)\n phiList(n-1)=2*pi-phiList(n-1);\nend\nphiList(n-1)=wrapRange(phiList(n-1),-pi,pi);\n\nrphiList=[r;phiList];\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/Cart2Hypersphere.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331956, "lm_q2_score": 0.907312219480915, "lm_q1q2_score": 0.8469131842474544}} {"text": "function x = power_mod ( a, n, m )\n\n%*****************************************************************************80\n%\n%% POWER_MOD computes mod ( A^N, M ).\n%\n% Discussion:\n%\n% Some programming tricks are used to speed up the computation, and to\n% allow computations in which A**N is much too large to store in a\n% real word.\n%\n% First, for efficiency, the power A**N is computed by determining\n% the binary expansion of N, then computing A, A**2, A**4, and so on\n% by repeated squaring, and multiplying only those factors that\n% contribute to A**N.\n%\n% Secondly, the intermediate products are immediately \"mod'ed\", which\n% keeps them small.\n%\n% For instance, to compute mod ( A^13, 11 ), we essentially compute\n%\n% 13 = 1 + 4 + 8\n%\n% A^13 = A * A^4 * A^8\n%\n% mod ( A^13, 11 ) = mod ( A, 11 ) * mod ( A^4, 11 ) * mod ( A^8, 11 ).\n%\n% Fermat's little theorem says that if P is prime, and A is not divisible\n% by P, then ( A^(P-1) - 1 ) is divisible by P.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 15 November 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer A, the base of the expression to be tested.\n% A should be nonnegative.\n%\n% Input, integer N, the power to which the base is raised.\n% N should be nonnegative.\n%\n% Input, integer M, the divisor against which the expression is tested.\n% M should be positive.\n%\n% Output, integer X, the remainder when A^N is divided by M.\n%\n if ( a < 0 )\n x = -1;\n return\n end\n\n if ( floor ( a ) ~= a )\n x = -1;\n return\n end\n\n if ( n < 0 )\n x = -1;\n return\n end\n\n if ( floor ( n ) ~= n )\n x = -1;\n return\n end \n\n if ( m <= 0 )\n x = -1;\n return\n end\n\n if ( floor ( m ) ~= m )\n x = -1;\n return\n end\n%\n% A contains the successive squares of A.\n%\n x = 1;\n\n while ( 0 < n )\n\n d = mod ( n, 2 );\n\n if ( d == 1 )\n x = mod ( x * a, m );\n end\n\n a = mod ( a * a, m );\n n = floor ( ( n - d ) / 2 );\n\n end\n%\n% Ensure that 0 <= X.\n%\n while ( x < 0 )\n x = x + m;\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/uniform/power_mod.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.9073122244934722, "lm_q1q2_score": 0.8469131805253048}} {"text": "function out = OrthNorm(n)\n% =======================================================================\n% Compute a [n x n] random orthonormal matrix\n% =======================================================================\n% out = OrthNorm(n)\n% -----------------------------------------------------------------------\n% INPUT\n% - n: size of the matrix\n% -----------------------------------------------------------------------\n% OUTPUT\n% - out: [n x n] random orthonormal matrix\n% =======================================================================\n% Ambrogio Cesa Bianchi, March 2015\n% ambrogio.cesabianchi@gmail.com\n\n% [n x n] matrix of N(0,1) random variables\nX = randn(n,n);\n\n% QR decomposition of X\n[Q, ~] = qr(X);\n\n% Check precision\nif sum(sum(Q*Q'))> n + 1.0e-5\n error('Q*transpose(Q) is not equal to identity')\nend\n\n% Random orthonormal matrix such that Q*Q'=I\nout = Q; ", "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/OldVersions/v2dot0/VAR/OrthNorm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9579122720843811, "lm_q2_score": 0.8840392893839086, "lm_q1q2_score": 0.8468320843056016}} {"text": "function cdf = logistic_cdf ( x, a, b )\n\n%*****************************************************************************80\n%\n%% LOGISTIC_CDF evaluates the Logistic CDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 13 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the CDF.\n%\n% Input, real A, B, the parameters of the PDF.\n% 0.0 < B.\n%\n% Output, real CDF, the value of the CDF.\n%\n cdf = 1.0 / ( 1.0 + exp ( ( a - x ) / b ) );\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/logistic_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9511422199928904, "lm_q2_score": 0.8902942224835226, "lm_q1q2_score": 0.846796423219822}} {"text": "function Pr = gbm_upcrossing_prob(X0, K, T, mu, sigma)\n%gbm_upcrossing_prob - Compute probability of an upcrossing of a geometric Brownian motion.\n%\n%\tPr = gbm_upcrossing_prob(X0, K, T, mu, sigma);\n%\n% Inputs:\n%\tX0 - Almost surely known initial value of geometric Brownian motion process [scalar].\n%\tK - Level for upcrossing of geometric Brownian motion during a specified period [scalar].\n%\tT - Duration of the period of observation in a specified unit of time [scalar].\n%\tmu - Drift of geometric Brownian motion in rate of change per specified unit of time [scalar].\n%\tsigma - Diffusion of geometric Brownian motion in rate of change per specified unit of time\n%\t\t[scalar].\n%\n% Outputs:\n%\tPr - Probability of an upcrossing of a geometric Brownian motion during the period T in the\n%\t\tspecified units of time [scalar].\n%\n% Comments:\n%\t1) This function computes the probability that a geometric Brownian motion crosses at or above a\n%\t\tspecified level at any time during a specified fixed period of time.\n%\t2) The term \"unit of time\" indicates that all times and rates must be in the same units of time.\n\n% Copyright (C) 2012 The MathWorks, Inc.\n\nif K <= X0\n\tPr = 1;\nelse\n\td0 = log(X0/K);\n\td1 = (d0 + (mu - 0.5*sigma^2)*T)/(sigma*sqrt(2*T));\n\td2 = (d0 - (mu - 0.5*sigma^2)*T)/(sigma*sqrt(2*T));\n\td3 = -0*(mu - 0.5*sigma^2)/(0.5*sigma^2);\n\n\tPr = 0.5*(1 + erf(d1)) + 0.5*exp(-d3)*(1 + erf(d2));\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/39449-analyzing-investment-strategies-with-cvar-portfolio-optimization/source/gbm_upcrossing_prob.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741308615411, "lm_q2_score": 0.8887587964389113, "lm_q1q2_score": 0.8466086380633453}} {"text": "function val=multinomial(repList)\n%%MULTINOMIAL Compute a multinomial coefficient. The multinomial\n% coefficient is the number of permutation of a multiset. A\n% multiset is a set with repeated elements. Multinomial\n% coefficients are usually written like binomial coefficients but\n% with multiple terms below.\n%\n%INPUTS: repList A numUniqueX1 list of how many times each unique item in\n% the multiset is repeated. All elements >=1 and\n% n=sum(repList), where n is the total number of elements in\n% the multiset.\n%\n%OUTPUTS: val The value of the multinomial coefficient.\n%\n%The multinomial coefficient is factorial(n)/prod(factorial(repList)).\n%However, that formulation is subject to overflow issues. Thus, it is\n%implemented here as a product of boinomial coefficients.\n%\n%September 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n numUniqueEls=length(repList);\n val=1;\n cumSum=0;\n for curEl=1:numUniqueEls\n cumSum=cumSum+repList(curEl);\n val=val*binomial(cumSum,repList(curEl));\n end\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/multinomial.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951698485602, "lm_q2_score": 0.905989822921759, "lm_q1q2_score": 0.846552514470044}} {"text": "function fx = p21_fun ( n, x )\n\n%*****************************************************************************80\n%\n%% P21_FUN evaluates the integrand for problem 21.\n%\n% Interval:\n%\n% 0 <= X <= 1\n%\n% Integrand:\n%\n% ( sech ( 10.0 * ( x - 0.2 ) ) )^2\n% + ( sech ( 100.0 * ( x - 0.4 ) ) )^4\n% + ( sech ( 1000.0 * ( x - 0.6 ) ) )^6\n%\n% Exact Integral:\n%\n% ( 1 + tanh ( 8 ) * tanh ( 2 ) ) / 10.0 + 2 / 150 + 2 / 1875\n%\n% Approximate Integral (20 digits):\n%\n% 0.21080273631018169851...\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 November 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% David Kahaner,\n% Comparison of Numerical Quadrature Formulas,\n% in Mathematical Software, edited by John R Rice,\n% Academic Press, 1971.\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 = ...\n ( sech ( 10.0 * ( x - 0.2 ) ) ).^2 ...\n + ( sech ( 100.0 * ( x - 0.4 ) ) ).^4 ...\n + ( sech ( 1000.0 * ( x - 0.6 ) ) ).^6;\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/p21_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660976007596, "lm_q2_score": 0.8872045981907006, "lm_q1q2_score": 0.8463631083094326}} {"text": "function num_dist = dist_enum ( k, m )\n\n%*****************************************************************************80\n%\n%% DIST_ENUM returns the number of distributions of indistinguishable objects.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 January 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer K, the number of distinguishable \"slots\".\n%\n% Input, integer M, the number of indistinguishable objects.\n%\n% Output, integer NUM_DIST, the number of distributions of M\n% indistinguishable objects about K distinguishable slots.\n%\n cnk = combin ( m + k - 1, m );\n\n num_dist = round ( cnk );\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/combo/dist_enum.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625012602593, "lm_q2_score": 0.9086178882719769, "lm_q1q2_score": 0.8463434908996305}} {"text": "function [w,x]=fclencurt(N1,a,b)\n% Fast Clenshaw Curtis Quadrature\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% fclencurt.m - Fast Clenshaw Curtis Quadrature\n%\n% Compute the N nodes and weights for Clenshaw-Curtis\n% Quadrature on the interval [a,b]. Unlike Gauss \n% quadratures, Clenshaw-Curtis is only exact for \n% polynomials up to order N, however, using the FFT\n% algorithm, the weights and nodes are computed in linear\n% time. This script will calculate for N=2^20+1 (1048577\n% points) in about 5 seconds on a normal laptop computer.\n%\n% Written by: Greg von Winckel - 02/12/2005\n% Contact: gregvw(at)chtm(dot)unm(dot)edu\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nN=N1-1; bma=b-a;\nc=zeros(N1,2);\nc(1:2:N1,1)=(2./[1 1-(2:2:N).^2 ])'; c(2,2)=1;\nf=real(ifft([c(1:N1,:);c(N:-1:2,:)]));\nw=bma*([f(1,1); 2*f(2:N,1); f(N1,1)])/2;\nx=0.5*((b+a)+N*bma*f(1:N1,2));\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/tools/math_tools/fclencurt.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9626731158685838, "lm_q2_score": 0.8791467611766711, "lm_q1q2_score": 0.8463309518877197}} {"text": "function y = r8vec_sqstb ( n, x )\n\n%*****************************************************************************80\n%\n%% R8VEC_SQSTB computes a \"slow\" quarter sine transform backward 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% For 0 <= I <= N-1,\n%\n% Y(I) = -2 Sum ( 1 <= J <= N-1 ) X(J) * sin ( PI * J * (I+1/2) / N )\n% - X(N) * cos ( pi * I )\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% Reference:\n%\n% William Briggs, Van Emden Henson,\n% The Discrete Fourier Transform,\n% SIAM, 1995,\n% QA403.5 B75\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 y(1:n) = 0.0;\n\n for i = 1 : n\n\n for j = 1 : n - 1\n theta = 0.5 * pi * j * ( 2 * i - 1 ) / n;\n y(i) = y(i) - 2.0 * x(j) * sin ( theta );\n end\n\n theta = pi * ( i - 1 );\n y(i) = y(i) - x(n) * cos ( theta );\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/sftpack/r8vec_sqstb.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109770159683, "lm_q2_score": 0.8902942224835226, "lm_q1q2_score": 0.8461454018222366}} {"text": "function f = p30_fun ( n, x )\n\n%*****************************************************************************80\n%\n%% P30_FUN evaluates the integrand for problem 30.\n%\n% Interval:\n%\n% 2 <= x <= 7\n%\n% Integrand:\n%\n% cos ( x )\n% + 5 * cos ( 1.6 * x )\n% - 2 * cos ( 2.0 * x )\n% + 5 * cos ( 4.5 * x )\n% + 7 * cos ( 9.0 * x )\n%\n% Antiderivative:\n%\n% sin ( x )\n% + 5 * sin ( 1.6 * x ) / 1.6\n% - 2 * sin ( 2.0 * x ) / 2.0\n% + 5 * sin ( 4.5 * x ) / 4.5\n% + 7 * sin ( 9.0 * x ) / 9.0\n%\n% Exact Integral:\n%\n% -4.5275696251606720278\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 November 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Dianne OLeary,\n% Scientific Computing with Case Studies,\n% SIAM, 2008,\n% ISBN13: 978-0-898716-66-5,\n% LC: QA401.O44.\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 f = cos ( x ) ...\n + 5 * cos ( 1.6 * x ) ...\n - 2 * cos ( 2.0 * x ) ...\n + 5 * cos ( 4.5 * x ) ...\n + 7 * cos ( 9.0 * x );\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/p30_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.9019206692796966, "lm_q1q2_score": 0.8461134388234878}} {"text": "function y=log10p1(x)\n%%LOG10P1 Evaluate the function log10(x+1) without a loss of precision for\n% values of x near 0.\n%\n%INPUTS: x A vector of matrix of real values at which the function should\n% be evaluated.\n%\n%OUTPUTS: y The value(s) of the function log10(x+1) at the point(s) in x.\n%\n%For values of x having magnitude over 1e-2 and for complex values, the\n%function is evaluated as written. For smaller values, a Taylor series\n%expansion is used to avoid the singularity near the origin.\n%\n%EXAMPLE:\n%Compare\n% log10(1e-16+1)\n% log10p1(1e-16)\n%For the first one, one will get 0, for the second,\n%4.342944819032518e-17. Compare this to a value computed using\n%higher-precision arithmetic of 4.3429448190325180593640482375402*10^-17\n%and it is clear that this function is more accurate than explicitly\n%evaluating the expression.\n%\n%November 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n%Allocate space\ny=zeros(size(x));\n\n%For large enough values, use the standard function.\nsel=abs(x)>1e-2|~isreal(x);\nx1=x(sel);\ny(sel)=log10(x1+1);\n\n%For smaller magnitude values, use an ninth-order Taylor series expansion.\n%The relative error at 10^-2 is on the order of 1e-20, which is less than\n%the precision of a double floating point number at that value. The series\n%is given in Horner form.\nlog10Val=log(10);\nx1=x(~sel);\ny(~sel)=x1.*(x1.*(x1.*(x1.*(x1.*(x1.*(x1.*(x1.*(-(1/(8*log10Val))+x/(9*log10Val))+1/(7*log10Val))-1/(6*log10Val))+1/(5*log10Val))-1/(4*log10Val))+1/(3*log10Val))-1/(2*log10Val))+1/log10Val);\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/log10p1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067228145365, "lm_q2_score": 0.8976953016868439, "lm_q1q2_score": 0.8460838568788739}} {"text": "function [weights,location] = GaussQuad1d(ngp)\n% Guass weights and abscissas.\n% Taken from http://en.wikipedia.org/wiki/Gaussian_quadrature\n\n% Data Table\nswitch ngp\n case{1} % ngp =1\n location = 0;\n weights = 2;\n case{2} % ngp =2\n location = [-sqrt(3)/3,sqrt(3)/3]';\n weights = [1,1]';\n case{3} % ngp =3\n location = [-sqrt(3/5),0,sqrt(3/5)]';\n weights = [5/9,8/9,5/9]';\n case{4} % ngp =4\n x1 = sqrt((3-2*sqrt(6/5))/7);\n x2 = sqrt((3+2*sqrt(6/5))/7);\n location = [-x1,-x2,x2,x1]';\n w1 = (18+sqrt(30))/36;\n w2 = (18-sqrt(30))/36;\n weights = [w1,w2,w2,w1]';\n case{5} % ngp =5\n x1 = (1/3)*sqrt(5-2*sqrt(10/7));\n x2 = (1/3)*sqrt(5+2*sqrt(10/7));\n x3 = 0;\n location = [-x1,-x2,x3,x2,x1]';\n w1 = (322 + 13*sqrt(70))/900;\n w2 = (322 - 13*sqrt(70))/900;\n w3 = 128/225;\n weights = [w1,w2,w3,w2,w1]';\n otherwise\n error('ngp max value = 5')\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/QuadratureMethods/GaussQuad1d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9736446463891303, "lm_q2_score": 0.8688267813328977, "lm_q1q2_score": 0.8459285442842754}} {"text": "function M_rice=imrician(M,s)\n\n% function M_rice=imrician(M,s)\n% ------------------------------------------------------------------------\n% IMCRICIAN Random samples from the Rice/Rician probability distribution.\n%\n% R ~ Rice(v, s) if R = sqrt(X^2 + Y^2), where X ~ N(v*cos(a), s^2) and\n% Y ~ N(v*sin(a), s^2) are independent normal distributions (any real a).\n%\n% Reference: http://en.wikipedia.org/wiki/Rice_distribution\n%\n% Kevin Mattheus Moerman\n% kevinmoerman@hotmail.com\n% 15/04/2009\n% ------------------------------------------------------------------------\n\nX_GAUSS=s.*randn(size(M))+M;\nY_GAUSS=s.*randn(size(M));\nM_rice = hypot(X_GAUSS,Y_GAUSS); \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/imrician.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9658995772325382, "lm_q2_score": 0.8757870046160257, "lm_q1q2_score": 0.8459222975043701}} {"text": "function xval = r8vec_even_select ( xlo, xhi, n, ival )\n\n%*****************************************************************************80\n%\n%% R8VEC_EVEN_SELECT returns the I-th of N evenly spaced values in [ XLO, XHI ].\n%\n% Formula:\n%\n% XVAL = ( (N-IVAL) * XLO + (IVAL-1) * XHI ) / dble ( N - 1 )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 29 November 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real XLO, XHI, the low and high values.\n%\n% Input, integer N, the number of values.\n%\n% Input, integer IVAL, the index of the desired point.\n% IVAL is normally between 1 and N, but may be any\n% integer value.\n%\n% Output, real XVAL, the IVAL-th of N evenly spaced values\n% between XLO and XHI.\n%\n% Unless N = 1, X(1) = XLO and X(N) = XHI.\n%\n% If N = 1, then X(1) = 0.5*(XLO+XHI).\n%\n if ( n == 1 )\n\n xval = 0.5 * ( xlo + xhi );\n\n else\n\n xval = ( ( n - ival ) * xlo ...\n + ( ival - 1 ) * xhi ) ...\n / ( n - 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/stroud/r8vec_even_select.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897475985936, "lm_q2_score": 0.899121375242593, "lm_q1q2_score": 0.8458841716749793}} {"text": "function GameOfLife\n% This is a simple simulation of Conway Game of life GoL\n% it is good for understanding Cellular Automata (CA) concept\n% GoL Rules:\n% 1. Survival: an alive cell live if it has 2 or 3 alive neighbors\n% 2. Birth: a dead cell will be alive if it has 3 alive neighbors\n% 3. Deaths: \n% Lonless: alive cell dies if it has 0 or 1 alive neighbors \n% Overcrowding: alive cell dies if it has 4 or more alive neighbors \n% Any questions related to CA are welcome\n% By: Ibraheem Al-Dhamari\n\nclc;\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Initialization\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% size= 500x500 \n% different random initial values\n%A= rand(500,500);\n%A= ones(500,500);\n\n% periodic configuration\n%A= zeros(500,500);\n% A(100,200)=1;\n% A(100,201)=1;\n% A(100,202)=1;\n\n% initial from image\n A=imread('CA02.JPG');\n\n% convert to binary--> % states={0,1}\nA=im2bw(A);\n% visualize the initial states \ndisp('the binary image')\nimshow(A);\npause\n% boundary type: 0= reflection \n% 1= doublication\n% 2= null, zeros\n\n% this step enlarge A with 4 virtual vectors\nA=Bnd(A,0); \n[d1,d2]=size(A);\ndisp('the extended binary image')\nwhos A\nimshow(A);\npause\nB=A;\nt=0;\nstp=false; % to stop when if no new configrations\n%B is the CA in time t\n%A is the CA in time t+1\n%t is the number of generations \n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Play ^_^\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nwhile ~stp & (t<10) % repeat for 10 generations\n % for each cell in the CA \n for i=2:d1-1\n for j=2:d2-1 \n % apply Game of life rule \n A(i,j)=GOL(A,B,i,j) ;\n end\n end \n % visualize what happened\n disp('the CA image')\n imshow(A); \n drawnow;\n% pause\n % save B \n if A==B\n stp=true; % no more new states\n end\n B=A; \n t=t+1 \nend \n\n%==========================================\n% Game of Life Rules \n%==========================================\nfunction s=GOL (A,B,i,j)\n% game of life rule\nsm=0;\n% count number of alive neighbors\nsm=sm+ B(i-1,j-1)+B(i-1,j)+B(i-1,j+1);\nsm=sm+ B(i,j-1)+ B(i,j+1);\nsm=sm+ B(i+1,j-1)+B(i+1,j)+B(i+1,j+1);\n\n% compute the new state of the current cell\ns=B(i,j);\nif B(i,j)==1\n if (sm>1)&&(sm<4)\n s=1;\n else\n s=0 ; \n end\nelse\n if sm==3\n s=1;\n end\nend\n \n%==========================================\n% Boundary Type\n%==========================================\nfunction bA= Bnd(A,k)\n% add new four vectors based on boundary type\n[d1, d2]=size(A);\nd1=d1+2; d2=d2+2;\nX=ones(d1,d2);\nX=im2bw(X);\nX(2:d1-1,2:d2-1)=A;\nimshow(X);\nwhos A X\nif k==0 % Reflection\n X( 1 , 2:d2-1)=A(end , :);\n X( d1 , 2:d2-1)=A( 1 , :);\n X( 2:d1-1 , 1 )=A(: , end);\n X( 2:d1-1 , d2 )=A(: , 1 );\n \n X(1,1) =A(end,end);\n X(1,end) =A(end,1);\n X(end,1) =A(1,end);\n X(end,end)=A(1,1); \nelseif k==1 % Double\n X( 1 , 2:d2-1)=A( 1 , :);\n X( d1 , 2:d2-1)=A(end , :);\n X( 2:d1-1 , 1 )=A(: , 1 );\n X( 2:d1-1 , d2 )=A(: , end);\n \n X(1,1) =A(end,1);\n X(1,end) =A(end,end);\n X(end,1) =A(1,1);\n X(end,end)=A(1,end);\n\nelse % k==2 % zeros\n X( 1 ,:)=0;\n X( end ,:)=0;\n X(: , 1 )=0;\n X(: , end )=0;\nend\nbA=X;\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/27233-conway-game-of-life/GameOfLife.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377284730286, "lm_q2_score": 0.8824278556326344, "lm_q1q2_score": 0.845840392279431}} {"text": "%% Demonstration of the 2D Discrete Gram Transformation\n%\n% (C) 2013 Matthew harker and Paul O'Leary\n% Institute for Automation\n% University of Leoben\n% A-8700 Leoben\n% Austria\n%\n% email: office@harkeroleary.org\n%\n% This file produces a demonstration of the 2D discrete gram polynomial\n% transformation of an image and the corresponding inverse transformation.\n% It used the function |dgt| to compute the discrete Gram transformation\n% and the function |idgt| to compute the inverse transformation.\n%\n% It is also demonstarted that the error in the reconstrcuted image ins\n% negligible, i.e., approaching the numerical accuracy available in MATLAB.\n% This demonstrates that the polynomial basis functions are free from error\n% evant at very high degrees in this example d = 1024.\n%\n% This tool requires the discrete orthogonal toolbox: dopBox:\n%\n% http://www.mathworks.com/matlabcentral/fileexchange/41250\n%\n%%\nclose all;\nclear all;\n%\n% Set some defaults\n%\nFontSize = 12;\nset(0,'DefaultaxesFontName','Times');\nset(0,'DefaultaxesFontSize',FontSize);\nset(0,'DefaulttextFontName','Times');\nset(0,'DefaulttextFontSize',FontSize);\nset(0,'DefaultTextInterpreter', 'latex');\n%\n%% Load an image and convert to a double gray data set\n%\n% This is an image of an art object. The snails are modelled in modelling\n% material, they are not real animals.\n%\n[pic, map] = imread('snails1.jpg');\n%\n% Make the data mean free so that the spectrum is better viwible\n%\nD = double( rgb2gray( pic ));\nD = D - mean(D(:));\n%% View the Test Image\n%\n% View the image\n%\nfig1 = figure;\nimagesc( pic );\naxis image;\n%\ntitle('Photo Finish ($$\\copyright$$ 2012 Paul O''Leary and Wolfgang Trettnak)');\nxlabel('These are artificial snails and not real animals');\n%\n%% Compute the Gram Spectrum\n%\n% Call the |dgt2| function to compute the two dimensional Gram polynomial\n% transformation. This is akin to the fft2 for the Fourier basis.\n%\n[S, Bx, By] = dgt2( D );\n%\n[ny,nx] = size( S );\n%\n% Compute the degrees in x and y directions.\n%\nxScale = 0:(nx-1);\nyScale = 0:(ny-1);\n%% View the 2D Polynomial Spectrum\n%\n% This is the complete 2D spectrum for the complete image.\n%\nfig2 = figure;\nimagesc( xScale, yScale, S );\naxis image;\ncolorbar\ntitle('2D Gram Spectrum (information is at lower degrees)');\nxlabel('Polynomial degree in $$x$$');\nylabel('Polynomial degree in $$y$$');\n%\n%% Zoomed Section of Spectrum\n%\n% Virtually all of the Information of the test image is concentrated at\n% lower degrees. This can be shown by zooming in on the relevant portion\n% of the spectrum.\n%\nfig3 = figure;\nimagesc( xScale, yScale, S);\naxis image;\ncolorbar\ntitle('2D Gram Spectrum');\nxlabel('Polynomial degree in $$x$$');\nylabel('Polynomial degree in $$y$$');\naxis([0,20,0,20]);\n%\n%\n%% Reconstruct the Image and Test for Errors\n%\n% The aim here is to reconstruct the image from its spectrum and then to\n% compute a norm for the total error. This gives a measure for the quality\n% of the transform inverse-transform pair.\n%\n% Note: the basis functions computed for the transform are passed to the\n% inverse transform. this avoids the necessity to recompute the polynomial\n% basis functions.\n%\n% As can be seen in the final figure, the Frobeneus norm of the error is in\n% the order of $10^{-15}$, consequently, the polynomial transformation can\n% be regarded as free from error.\n%\nDr = idgt2( S, Bx, By );\n%\n% Calculate the difference between the original gray scale image and its\n% reconstruction.\n%\nE = D - Dr;\n%\n% Compute the ratio of the Frobenius of the error to the norm of the data. \n%\nnormE = norm( E, 'fro');\nnormD = norm( D, 'fro');\nnormEtoD = normE / normD;\n%\n%% View the Reconstructed Image.\n%\nfig3 = figure;\nimagesc( Dr );\naxis image;\ncolormap gray;\naxis off;\ntitle(['Reconstructed Gray Image ($$ \\epsilon = ',num2str(normEtoD),' $$)']);\nxlabel('These are artificial snails and not real animals');\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/42474-2d-polynomial-data-modelling-version-1-0/dop2DBoxV1-0/demos/Gram2DTransformDemo.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.9032942034496965, "lm_q1q2_score": 0.8457408216809433}} {"text": "function I = percentile2i(h,P)\n%PERCENTILE2I Computes an intensity value given a percentile.\n% I = PERCENTILE2I(H,P) Given a percentile, P, and a histogram, H,\n% this function computes an intensity, I, representing the Pth\n% percentile and returns the value in I. P must be in the range [0, 1]\n% and I is returned as a value in the range [0, 1] also.\n%\n% Example:\n% \n% Suppose that h is a uniform histogram of an 8-bit image. Typing\n% \n% I = percentile2i(h,0.5) \n%\n% would output I = 0.5. To convert to the (integer) 8-bit range\n% [0, 255], we let I = floor(255*I).\n%\n% See also I2PERCENTILE. \n%\n% Copyright 2002-2020 Gatesmark\n%\n% This function, and other functions in the DIPUM Toolbox, are based \n% on the theoretical and practical foundations established in the \n% book Digital Image Processing Using MATLAB, 3rd ed., Gatesmark \n% Press, 2020.\n%\n% Book website: http://www.imageprocessingplace.com\n% License: https://github.com/dipum/dipum-toolbox/blob/master/LICENSE.txt\n\n% Check value of P.\nif P < 0 || P > 1\n error('The percentile must be in the range [0, 1].')\nend\n\n% Normalized the histogram to unit area. If it is already normalized\n% the following computation has no effect.\nh = h/sum(h);\n\n% Cumulative distribution.\nC = cumsum(h);\n\n% Calculations.\nidx = find(C >= P,1,'first');\n% Subtract 1 from idx because indexing starts at 1, but intensities\n% start at 0. Also, normalize to the range [0, 1].\nI = (idx - 1)/(numel(h) - 1); \n\n \n\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/percentile2i.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.9184802507195636, "lm_q1q2_score": 0.845727132372329}} {"text": "function ng = ellipsoid_grid_count ( n, r, c )\n\n%*****************************************************************************80\n%\n%% ELLIPSOID_GRID_COUNT counts the grid points inside an ellipsoid.\n%\n% Discussion:\n%\n% The ellipsoid is specified as\n%\n% ( ( X - C1 ) / R1 )^2 \n% + ( ( Y - C2 ) / R2 )^2 \n% + ( ( Z - C3 ) / R3 )^2 = 1\n%\n% The user supplies a number N. There will be N+1 grid points along\n% the shortest axis.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 September 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of subintervals.\n%\n% Input, real R(3), the half axis lengths.\n%\n% Input, real C(3), the center of the ellipsoid.\n%\n% Output, integer NG, the number of grid points inside the ellipsoid.\n%\n if ( r(1) == min ( r ) )\n h = 2 * r(1) / ( 2 * n + 1 );\n ni = n;\n nj = ceil ( r(2) / r(1) ) * n;\n nk = ceil ( r(3) / r(1) ) * n;\n elseif ( r(2) == min ( r ) )\n h = 2 * r(2) / ( 2 * n + 1 );\n nj = n;\n ni = ceil ( r(1) / r(2) ) * n;\n nk = ceil ( r(3) / r(2) ) * n;\n else\n h = 2 * r(3) / ( 2 * n + 1 );\n nk = n;\n ni = ceil ( r(1) / r(3) ) * n;\n nj = ceil ( r(2) / r(3) ) * n;\n end\n\n ng = 0;\n\n for k = 0 : nk\n z = c(3) + k * h;\n for j = 0 : nj\n y = c(2) + j * h;\n for i = 0 : ni\n x = c(1) + i * h;\n if ( 1 < ( ( x - c(1) ) / r(1) ).^2 ...\n + ( ( y - c(2) ) / r(2) ).^2 ...\n + ( ( z - c(3) ) / r(3) ).^2 )\n break\n end\n%\n% At least one point is generated, but more possible by symmetry.\n%\n np = 1;\n if ( 0 < i )\n np = 2 * np;\n end\n if ( 0 < j )\n np = 2 * np;\n end\n if ( 0 < k )\n np = 2 * np;\n end\n ng = ng + np;\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/ellipsoid_grid/ellipsoid_grid_count.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.9184802429095673, "lm_q1q2_score": 0.8457271211880307}} {"text": "function [ n_data_new, n, c ] = sigma_values ( n_data )\n\n%*****************************************************************************80\n%\n%% SIGMA_VALUES returns some values of the Sigma function.\n%\n% Definition:\n%\n% SIGMA(N) is the sum of the distinct divisors of N, including 1 and N.\n%\n% First values:\n%\n% N SIGMA(N)\n%\n% 1 1\n% 2 3\n% 3 4\n% 4 7\n% 5 6\n% 6 12\n% 7 8\n% 8 15\n% 9 13\n% 10 18\n% 11 12\n% 12 28\n% 13 14\n% 14 24\n% 15 24\n% 16 31\n% 17 18\n% 18 39\n% 19 20\n% 20 42\n%\n% Formula:\n%\n% SIGMA(U*V) = SIGMA(U) * SIGMA(V) if U and V are relatively prime.\n%\n% SIGMA(P**K) = ( P**(K+1) - 1 ) / ( P - 1 ) if P is prime.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 26 May 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% Parameters:\n%\n% Input, integer N_DATA, indicates the index of the previous test data\n% returned, or is 0 if this is the first call. For repeated calls,\n% set the input value of N_DATA to the output value of N_DATA_NEW\n% from the previous call.\n%\n% Output, integer N_DATA_NEW, the index of the test data.\n%\n% Output, integer N, the argument of the Sigma function.\n%\n% Output, integer C, the value of the Sigma function.\n%\n n_max = 20;\n c_vec = [ ...\n 1, 3, 4, 7, 6, 12, 8, 15, 13, 18, ...\n 72, 128, 255, 176, 576, 1170, 618, 984, 2232, 2340 ];\n n_vec = [ ...\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...\n 30, 127, 128, 129, 210, 360, 617, 815, 816,1000 ];\n\n n_data_new = n_data;\n\n if ( n_data_new < 0 )\n n_data_new = 0;\n end\n\n n_data_new = n_data_new + 1;\n\n if ( n_max < n_data_new )\n n_data_new = 0;\n n = 0;\n c = 0;\n else\n n = n_vec(n_data_new);\n c = c_vec(n_data_new);\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/polpak/sigma_values.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098192, "lm_q2_score": 0.9173026505426832, "lm_q1q2_score": 0.8456813407378854}} {"text": "function out = slidingavg(in, N)\n% OUTPUT_ARRAY = SLIDINGAVG(INPUT_ARRAY, N)\n%\n% The function 'slidingavg' implements a one-dimensional filtering, applying a sliding window to a sequence. Such filtering replaces the center value in\n% the window with the average value of all the points within the window. When the sliding window is exceeding the lower or upper boundaries of the input\n% vector INPUT_ARRAY, the average is computed among the available points. Indicating with nx the length of the the input sequence, we note that for values\n% of N larger or equal to 2*(nx - 1), each value of the output data array are identical and equal to mean(in).\n%\n% * The input argument INPUT_ARRAY is the numerical data array to be processed.\n% * The input argument N is the number of neighboring data points to average over for each point of IN.\n%\n% * The output argument OUTPUT_ARRAY is the output data array.\n%\n% Š 2002 - Michele Giugliano, PhD and Maura Arsiero\n% (Bern, Friday July 5th, 2002 - 21:10)\n% (http://www.giugliano.info) (bug-reports to michele@giugliano.info)\n%\n% Two simple examples with second- and third-order filters are\n% slidingavg([4 3 5 2 8 9 1],2) \n% ans =\n% 3.5000 4.0000 3.3333 5.0000 6.3333 6.0000 5.0000\n%\n% slidingavg([4 3 5 2 8 9 1],3)\n% ans =\n% 3.5000 4.0000 3.3333 5.0000 6.3333 6.0000 5.0000\n%\n\nif (isempty(in)) | (N<=0) % If the input array is empty or N is non-positive,\n disp(sprintf('SlidingAvg: (Error) empty input data or N null.')); % an error is reported to the standard output and the\n return; % execution of the routine is stopped.\nend % if\n\nif (N==1) % If the number of neighbouring points over which the sliding \n out = in; % average will be performed is '1', then no average actually occur and\n return; % OUTPUT_ARRAY will be the copy of INPUT_ARRAY and the execution of the routine\nend % if % is stopped.\n\nnx = length(in); % The length of the input data structure is acquired to later evaluate the 'mean' over the appropriate boundaries.\n\nif (N>=(2*(nx-1))) % If the number of neighbouring points over which the sliding \n out = mean(in)*ones(size(in)); % average will be performed is large enough, then the average actually covers all the points\n return; % of INPUT_ARRAY, for each index of OUTPUT_ARRAY and some CPU time can be gained by such an approach.\nend % if % The execution of the routine is stopped.\n\n\n\nout = zeros(size(in)); % In all the other situations, the initialization of the output data structure is performed.\n\nif rem(N,2)~=1 % When N is even, then we proceed in taking the half of it:\n m = N/2; % m = N / 2.\nelse % Otherwise (N >= 3, N odd), N-1 is even ( N-1 >= 2) and we proceed taking the half of it:\n m = (N-1)/2; % m = (N-1) / 2.\nend % if\n\nfor i=1:nx, % For each element (i-th) contained in the input numerical array, a check must be performed:\n if ((i-m) < 1) & ((i+m) <= nx) % If not enough points are available on the left of the i-th element..\n out(i) = mean(in(1:i+m)); % then we proceed to evaluate the mean from the first element to the (i + m)-th.\n elseif ((i-m) >= 1) & ((i+m) <= nx) % If enough points are available on the left and on the right of the i-th element..\n out(i) = mean(in(i-m:i+m)); % then we proceed to evaluate the mean on 2*m elements centered on the i-th position.\nelseif ((i-m) >= 1) & ((i+m) > nx) % If not enough points are available on the rigth of the i-th element..\n out(i) = mean(in(i-m:nx)); % then we proceed to evaluate the mean from the element (i - m)-th to the last one.\n elseif ((i-m) < 1) & ((i+m) > nx) % If not enough points are available on the left and on the rigth of the i-th element..\n out(i) = mean(in(1:nx)); % then we proceed to evaluate the mean from the first element to the last.\n end % if\nend % for i\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/1967-slidingavg/slidingavg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109606718245, "lm_q2_score": 0.9230391717138002, "lm_q1q2_score": 0.8456050525842642}} {"text": "function [J, grad] = costFunction(theta, X, y)\n%COSTFUNCTION Compute cost and gradient for logistic regression\n% J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the\n% parameter for logistic regression and the gradient of the cost\n% w.r.t. to the parameters.\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n% Note: grad should have the same dimensions as theta\n%\n\nhtheta = sigmoid(X * theta);\nJ = 1 / m * sum(-y .* log(htheta) - (1 - y) .* log(1 - htheta));\nfor i = 1:size(theta, 1)\n grad(i) = 1 / m * sum((htheta - y) .* X(:, i));\nend\n\n\n\n\n\n% =============================================================\n\nend\n", "meta": {"author": "merwan", "repo": "ml-class", "sha": "0b06b73d4aac0b8d7c726325200c3781b5c9d3b0", "save_path": "github-repos/MATLAB/merwan-ml-class", "path": "github-repos/MATLAB/merwan-ml-class/ml-class-0b06b73d4aac0b8d7c726325200c3781b5c9d3b0/mlclass-ex2/costFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966762263736, "lm_q2_score": 0.8933094010836642, "lm_q1q2_score": 0.845603709907569}} {"text": "function fx = p40_fun ( n, x )\n\n%*****************************************************************************80\n%\n%% P40_FUN evaluates the integrand for problem 40.\n%\n% Discussion:\n%\n% The problem has a parameter ALPHA that can be set by calling\n% P40_PARAM_SET.\n%\n% The integrand has a singularity at an internal point ( x = pi/4 ).\n%\n% The suggested range for ALPHA is -0.8 through 2.1.\n%\n% Interval:\n%\n% 0 <= x <= 1\n%\n% Integrand:\n%\n% ( abs ( x - pi/4 ) )^alpha\n%\n% Exact Integral:\n%\n% ( (1-pi/4)^(alpha+1) + (pi/4)^(alpha+1) ) / ( alpha + 1 )\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% Robert Piessens, Elise de Doncker-Kapenga,\n% Christian Ueberhuber, David Kahaner,\n% QUADPACK: A Subroutine Package for Automatic Integration,\n% Springer, 1983, page 83.\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 alpha = p40_param_get ( );\n\n fx = ( abs ( x - 0.25 * pi ) ).^alpha;\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/p40_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693674025231, "lm_q2_score": 0.8902942261220292, "lm_q1q2_score": 0.8454851545234263}} {"text": "function center = polylineCentroid(varargin)\n%POLYLINECENTROID Compute centroid of a curve defined by a series of points\n%\n% PT = polylineCentroid(POINTS);\n% Computes center of mass of a polyline defined by POINTS. POINTS is a\n% [NxD] array of double, representing a set of N points in a\n% D-dimensional space.\n%\n% PT = polylineCentroid(PTX, PTY);\n% PT = polylineCentroid(PTX, PTY, PTZ);\n% Specifies points as separate column vectors\n%\n% PT = polylineCentroid(..., TYPE);\n% Specifies if the last point is connected to the first one. TYPE can be\n% either 'closed' or 'open'.\n%\n% Example\n% poly = [0 0;10 0;10 10;20 10];\n% polylineCentroid(poly)\n% ans = \n% [10 5]\n%\n% See also:\n% polygons2d, centroid, polygonCentroid, polylineLength\n%\n% ---------\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 22/05/2006.\n%\n\n\n\n%% process input arguments\n\n% check whether the curve is closed\nclosed = false;\nvar = varargin{end};\nif ischar(var)\n if strcmpi(var, 'closed')\n closed = true;\n end\n varargin = varargin(1:end-1);\nend\n\n% extract point coordinates\nif length(varargin)==1\n points = varargin{1};\nelseif length(varargin)==2\n points = [varargin{1} varargin{2}];\nend\n\n% compute centers and lengths composing the curve\nif closed\n centers = (points + points([2:end 1],:))/2;\n lengths = sqrt(sum(diff(points([1:end 1],:)).^2, 2));\nelse\n centers = (points(1:end-1,:) + points(2:end,:))/2;\n lengths = sqrt(sum(diff(points).^2, 2));\nend\n\n% centroid of edge centers weighted by edge length\n%weigths = repmat(lengths/sum(lengths), [1 size(points, 2)]); \ncenter = sum(centers.*repmat(lengths, [1 size(points, 2)]), 1)/sum(lengths);\n\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/polygons2d/polylineCentroid.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9433475810629194, "lm_q2_score": 0.8962513745192026, "lm_q1q2_score": 0.8454765661770064}} {"text": "function pde = biharmonicdata\n%% BIHARMONICDATA trigonometric data for biharmonic equation\n%\n% f = 64*pi^4*sin(2*pi*x)*cos(2*pi*y);\n% u = sin(2*pi*x)*cos(2*pi*y);\n% Du = (2*pi*cos(2*pi*x)*cos(2*pi*y), -2*pi*sin(2*pi*x)*sin(2*pi*y));\n% w = Delta u = -8*pi^2*sin(2*pi*x)*cos(2*pi*y);\n% du/dn = g_N on [0,1]^2.\n%\n% Added by Jie Zhou.\n%\n% Copyright (C) Long Chen. See COPYRIGHT.txt for details.\n\npde = struct('f',@f,'exactu',@exactu,'Du',@Du,'exactw',@exactw,'Dw',@Dw,...\n 'g_D',@g_D,'g_N',@g_N);\n\n% load data (right hand side function)\nfunction rhs = f(p)\n x = p(:,1); y = p(:,2);\n rhs = 64*pi^4*sin(2*pi*x).*cos(2*pi*y);\nend\n\n% exact solution\nfunction u = exactu(p)\n x = p(:,1); y = p(:,2);\n u = sin(2*pi*x).*cos(2*pi*y);\nend\n\n% derivative of the exact solution\nfunction uprime = Du(p)\n x = p(:,1); y = p(:,2);\n uprime(:,1) = 2*pi*cos(2*pi*x).*cos(2*pi*y);\n uprime(:,2) = -2*pi*sin(2*pi*x).*sin(2*pi*y);\nend\n\n% exact solution of w = -Delta u\nfunction w = exactw(p)\n x = p(:,1); y = p(:,2);\n w = -8*pi^2*sin(2*pi*x).*cos(2*pi*y);\nend\n\n% derivative of the exact solution w\nfunction wprime = Dw(p)\n x = p(:,1); y = p(:,2);\n wprime(:,1) = -16*pi^3*cos(2*pi*x).*cos(2*pi*y);\n wprime(:,2) = 16*pi^3*sin(2*pi*x).*sin(2*pi*y);\nend\n\n% Dirichlet boundary condition\nfunction u = g_D(p)\n u = exactu(p);\nend\n\n% Neumann boundary condition \nfunction f = g_N(p)\n f = zeros(size(p,1),1);\n x = p(:,1); y = p(:,2);\n uprime = [2*pi*cos(2*pi*p(:,1)).*cos(2*pi*p(:,2)) -2*pi*sin(2*pi*p(:,1)).*sin(2*pi*p(:,2))];\n leftbd = (abs(x).\n", "meta": {"author": "lyc102", "repo": "ifem", "sha": "29f31c812001ca8d93dad08e67208ca60e8716d4", "save_path": "github-repos/MATLAB/lyc102-ifem", "path": "github-repos/MATLAB/lyc102-ifem/ifem-29f31c812001ca8d93dad08e67208ca60e8716d4/fem/verifyquadpts.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541626630937, "lm_q2_score": 0.8976952866333484, "lm_q1q2_score": 0.8453185034613315}} {"text": "function [ht, rho, theta] = hough(IM, f, t, M, N)\n% HOUGH Hough transform for detection lines in images.\n% [HT,RHO,THETA] = HOUGH(IM,M,N). \n% From an image IM, computes the integration of the values\n% of the image over all the lines. The origin of the coordinates is \n% in the middle of x axis (-250<=x<250, 0<=y<=1). The formula for the\n% transform is rho = x*cos(theta) + y*sin(theta). Only the values of IM exceeding 5 % of the maximum \n%\tare taken into account (to speed up the algorithm). \n%\n%\tIM : image to be analyzed (size Xmax x Ymax).\n%\tM : desired number of samples along the radial axis \n%\t\t\t\t\t(default : Xmax).\n%\tN : desired number of samples along the azimutal (angle) axis\n%\t\t\t\t\t(default : Ymax). \n%\tHT : output matrix (MxN matrix).\n%\tRHO : sequence of samples along the radial axis.\n%\tTHETA : sequence of samples along the azimutal axis.\n\nif (nargin < 3 ),\n error('At least three parameters required');\nend;\n[Xmax,Ymax] = size(IM);\n\nif (nargin == 3),\nM = Xmax; N = Ymax; \nelseif (nargin == 4),\nN=Ymax; \nend;\n\nrhomax = sqrt(Xmax^2 + Ymax^2)/2;\ndeltar=rhomax/(M-1);\ndeltat=2*pi/N;\n\nht=zeros(M,N);\nMax=max(max(IM)); \nfor x = 0:Xmax-1,\n for y = 0:Ymax-1,\n if abs(IM(x+1,y+1))>Max/20,\n for theta = 0:deltat:(2*pi-deltat),\n rho = x*cos(theta) + y*sin(theta); \n if ((rho>=0)&&(rho<=rhomax)),\n ht(round(rho/deltar)+1,round(theta/deltat)+1) =...\n ht(round(rho/deltar)+1,round(theta/deltat)+1)+...\n IM(x+1,y+1);\n end\n end\n end\n end\nend\nrho=0:deltar:rhomax;\ntheta=0:deltat:(2*pi-deltat);", "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/42698-wigner-hough-transform/hough.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122708828604, "lm_q2_score": 0.8824278664544911, "lm_q1q2_score": 0.845288481445739}} {"text": "function r=ellipsoidalRadius(el,elType,a,f)\n%%ELLIPSOIDALRADIUS Find the distance from the center of an axis-aligned\n% oblate spheroid, as is used to approximate the shape of the\n% Earth, to a point on the surface of the spheroid as a function\n% of the (spherical) elevation angle above the equatorial plane\n% or as a function of the ellipsoidal latitude.\n%\n%INPUTS: el A point or a matrix of the elevation points for which one wants\n% to find radii. The points are in radians. The next parameter\n% sets the type of points.\n% elType An optional parameter specifying the type of elevation el is.\n% Possible values are:\n% 0 (The default if omitted or an empty matrix is passed)\n% Geocentric elevations (as in spherical cooridinates).\n% 1 Geodetic (ellipsoidal) latitudes.\n% a The semi-major axis of the reference ellipsoid. If this\n% argument is omitted, the value in Constants.WGS84SemiMajorAxis\n% is used.\n% f The flattening factor of the reference ellipsoid. If this\n% argument is omitted, the value in Constants.WGS84Flattening is\n% used.\n%\n%OUTPUTS: r A matrix of the radii corresponding to the values in el.\n%\n%The formula for the radius as a function of spherical elevation is taken\n%from Section 3.2 of [1].\n%\n%REFERENCES:\n%[1] C. Hirt and M. Rexer, \"Earth2014: 1 arc-min shape, topography, bedrock\n% and ice-sheet models - available as gridded data and degree - 10,800 \n% spherical harmonics,\" International Journal of Applied Earth\n% Observation and Geoinformation, vol. 39, pp. 103-112, Jul. 2015.\n%\n%June 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<2||isempty(elType))\n elType=0; \nend\n\nif(nargin<3||isempty(a))\n a=Constants.WGS84SemiMajorAxis;\nend\n\nif(nargin<4||isempty(f))\n f=Constants.WGS84Flattening;\nend\n\nb=a*(1-f);%Semi-minor axis\ne2=(a^2-b^2)/a^2;%eccentricity squared\n\nif(elType==0)\n %We need the square of the sine of the ellipsoidal latitude. However,\n %we only have the spherical elevation. Here, we just substituted the\n %formula from spherLat2EllipsLat into the square of the sine and\n %simplified to get the following formula in terms of the squared\n %tangent.\n spherLat=wrapRange(el,-pi/2,pi/2,true);\n sinEl2=1-1./(1+(1/(1-e2))^2*tan(spherLat).^2);\nelse\n sinEl2=sin(el).^2;\nend\n\nr=a*sqrt((1-e2*(2-e2)*sinEl2)./(1-e2*sinEl2));\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/ellipsoidalRadius.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122684798184, "lm_q2_score": 0.8824278649085117, "lm_q1q2_score": 0.8452884778443152}} {"text": "function value = i4_log_10 ( i )\n\n%*****************************************************************************80\n%\n%% I4_LOG_10 returns the integer part of the logarithm base 10 of ABS(X).\n%\n% Example:\n%\n% I VALUE\n% ----- --------\n% 0 0\n% 1 0\n% 2 0\n% 9 0\n% 10 1\n% 11 1\n% 99 1\n% 100 2\n% 101 2\n% 999 2\n% 1000 3\n% 1001 3\n% 9999 3\n% 10000 4\n%\n% Discussion:\n%\n% I4_LOG_10 ( I ) + 1 is the number of decimal digits in I.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 29 January 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer I, the number whose logarithm base 10 is desired.\n%\n% Output, integer VALUE, the integer part of the logarithm base 10 of\n% the absolute value of X.\n%\n i = floor ( i );\n\n if ( i == 0 )\n\n value = 0;\n\n else\n\n value = 0;\n ten_pow = 10;\n\n i_abs = abs ( i );\n\n while ( ten_pow <= i_abs )\n value = value + 1;\n ten_pow = ten_pow * 10;\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/subpak/i4_log_10.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133565584851, "lm_q2_score": 0.8991213759183765, "lm_q1q2_score": 0.8450961903929247}} {"text": "%% Fun with remap\n% Maps a rectangular image into a circle using cv.remap\n%\n% To build the mapping we do the following simple geometry calculation:\n%\n% * shift the origin (0,0) coordinate to the center of the image\n% * convert the cartesian x-y coordinates to polar r-theta form\n% * determine the length of the line with the same theta that touches the\n% border of the rectangle\n% * retain the theta, but scale the r value based on how much the line has to\n% shrink to fit into the circle.\n% * convert the modified r-theta values back into x-y coordinates\n%\n% Sources:\n%\n% * \n%\n\n%%\n% source image\nfname = which('coins.png');\nif isempty(fname)\n fname = fullfile(mexopencv.root(), 'test', 'apple.jpg');\nend\nsrc = imread(fname);\n\n%%\n% coordinates space, shifted so that origin is at the center of the image\n[h,w,~] = size(src);\nc = [w,h] / 2;\n[X,Y] = meshgrid(single(1:w)-c(1), single(1:h)-c(2));\n\n%%\n% convert cartesian coordinates to polar form (r,theta)\nR = hypot(Y,X);\nT = atan(Y./X); % NOTE: atan not atan2\n\n% handle NaN case when atan(0/0) in the center\nT(isnan(T)) = 0;\n\n%%\n% scale R\nradius = min(h,w) / 2;\nD = min(abs(c(1)./cos(T)), abs(c(2)./sin(T)));\nR = R ./ (radius ./ D);\n\n%%\n% remap points\nmap_X = c(1) + sign(X) .* R .* cos(abs(T));\nmap_Y = c(2) + sign(Y) .* R .* sin(abs(T));\n\n%%\n% destination image\ndst = cv.remap(src, map_X, map_Y);\n\n%%\n% show result\nsubplot(121), imshow(src), title('image')\nsubplot(122), imshow(dst), title('remapped')\n", "meta": {"author": "kyamagu", "repo": "mexopencv", "sha": "d29007b2a484d0fd92e6e941dc5fd4750014fa6a", "save_path": "github-repos/MATLAB/kyamagu-mexopencv", "path": "github-repos/MATLAB/kyamagu-mexopencv/mexopencv-d29007b2a484d0fd92e6e941dc5fd4750014fa6a/samples/remap_fun_demo.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810525948927, "lm_q2_score": 0.8918110475945175, "lm_q1q2_score": 0.8448848889858479}} {"text": "function area = triangle_area_heron ( s )\n\n%*****************************************************************************80\n%\n%% TRIANGLE_AREA_HERON computes the area of a triangle using Heron's formula.\n%\n% Discussion:\n%\n% The formula is valid for any spatial dimension, depending only\n% on the lengths of the sides, and not the coordinates of the vertices.\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 S(3,1), the lengths of the three sides.\n%\n% Output, real AREA, the area of the triangle, or -1.0 if the\n% sides cannot constitute a triangle.\n%\n area = ( s(1,1) + s(2,1) + s(3,1) ) ...\n * ( - s(1,1) + s(2,1) + s(3,1) ) ...\n * ( s(1,1) - s(2,1) + s(3,1) ) ...\n * ( s(1,1) + s(2,1) - s(3,1) );\n\n if ( area < 0.0 )\n area = -1.0;\n return\n end\n\n area = 0.25 * sqrt ( area );\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/triangle_area_heron.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.947381048137938, "lm_q2_score": 0.8918110440002044, "lm_q1q2_score": 0.8448848816059024}} {"text": "function y = norm_pdf(x,mu,sigma)\n%NORM_PDF Normal probability density function (pdf).\n%\n% Y = NORMPDF(X,MU,SIGMA) Returns the normal pdf with\n% mean, MU, and standard deviation, SIGMA, at the values in X.\n%\n% The size of X is the common size of the input arguments. A scalar input \n% functions as a constant matrix of the same size as the other inputs. \n%\n% Default values for MU and SIGMA are 0 and 1 respectively.\n\n% Copyright (c) 1998-2004 Aki Vehtari\n\n% This software is distributed under the GNU General Public \n% License (version 3 or later); please refer to the file \n% License.txt, included with the software, for details.\n\nif nargin < 3, \n sigma = 1;\nend\n\nif nargin < 2;\n mu = 0;\nend\n\nif nargin < 1, \n error('Requires at least one input argument.');\nend\n\ny = exp(-0.5 * ((x-mu)./sigma).^2 -log(sigma) -log(2*pi)/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/dmlt/external/gpstuff/dist/norm_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9609517050371972, "lm_q2_score": 0.8791467754256017, "lm_q1q2_score": 0.8448175928231858}} {"text": "% Quadratic discrimination (separating ellipsoid)\n% Section 8.6.2, Boyd & Vandenberghe \"Convex Optimization\"\n% Original by Lieven Vandenberghe\n% Adapted for CVX by Joelle Skaf - 10/16/05\n% (a figure is generated)\n%\n% The goal is to find an ellipsoid that contains all the points\n% x_1,...,x_N but none of the points y_1,...,y_M. The equation of the\n% ellipsoidal surface is: z'*P*z + q'*z + r =0\n% P, q and r can be obtained by solving the SDP feasibility problem:\n% minimize 0\n% s.t. x_i'*P*x_i + q'*x_i + r >= 1 for i = 1,...,N\n% y_i'*P*y_i + q'*y_i + r <= -1 for i = 1,...,M\n% P <= -I\n\n% data generation\nn = 2;\nrand('state',0); \nrandn('state',0);\nN=50;\nX = randn(2,N); X = X*diag(0.99*rand(1,N)./sqrt(sum(X.^2)));\nY = randn(2,N); Y = Y*diag((1.02+rand(1,N))./sqrt(sum(Y.^2)));\nT = [1 -1; 2 1]; X = T*X; Y = T*Y;\n\n% Solution via CVX\nfprintf(1,'Find the optimal ellipsoid that seperates the 2 classes...');\n\ncvx_begin sdp\n variable P(n,n) symmetric\n variables q(n) r(1)\n P <= -eye(n); %#ok\n sum((X'*P).*X',2) + X'*q + r >= +1; %#ok\n sum((Y'*P).*Y',2) + Y'*q + r <= -1; %#ok\ncvx_end\n\nfprintf(1,'Done! \\n');\n\n% Displaying results\nr = -r; P = -P; q = -q;\nPq = P \\ q;\nc = 0.25*q'*Pq - r;\nxc = -0.5*Pq;\nnopts = 1000;\nangles = linspace(0,2*pi,nopts);\nell = sqrtm(P/c)\\[cos(angles); sin(angles)] + repmat(xc,1,nopts);\ngraph=plot(X(1,:),X(2,:),'o', Y(1,:), Y(2,:),'o', ell(1,:), ell(2,:),'-');\nset(graph(2),'MarkerFaceColor',[0 0.5 0]);\nset(gca,'XTick',[]); set(gca,'YTick',[]);\ntitle('Quadratic discrimination');\n% print -deps ellips.eps\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/cvxbook/Ch08_geometric_probs/quad_discr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517028006207, "lm_q2_score": 0.8791467643431002, "lm_q1q2_score": 0.8448175802071581}} {"text": "function c=zak(f,a);\n%ZAK Zak transform\n% Usage: c=zak(f,a);\n%\n% `zak(f,a)` computes the Zak transform of *f* with parameter *a*. The\n% coefficients are arranged in an $a \\times L/a$ matrix, where *L* is the\n% length of *f*.\n%\n% If *f* is a matrix then the transformation is applied to each column.\n% This is then indexed by the third dimension of the output.\n%\n% Assume that $c=zak(f,a)$, where *f* is a column vector of length *L* and\n% $N=L/a$. Then the following holds for $m=0,\\ldots,a-1$ and $n=0,\\ldots,N-1$\n%\n% .. N-1 \n% c(m+1,n+1)=1/sqrt(N)*sum f(m-k*a+1)*exp(2*pi*i*n*k/N)\n% k=0\n%\n% .. math:: c(m+1,n+1) = \\frac{1}{\\sqrt{N}}\\sum_{k=0}^{N-1}f(m-ka+1)e^{2\\pi ink/M}\n%\n% Examples:\n% ---------\n%\n% This figure shows the absolute value of the Zak-transform of a Gaussian.\n% Notice that the Zak-transform is 0 in only a single point right in the\n% middle of the plot :::\n%\n% a=64;\n% L=a^2; \n% g=pgauss(L);\n% zg=zak(g,a);\n%\n% surf(abs(zg));\n% \n% This figure shows the absolute value of the Zak-transform of a 4th order\n% Hermite function. Notice how the Zak transform of the Hermite functions\n% is zero on a circle centered on the corner :::\n%\n% a=64;\n% L=a^2; \n% g=pherm(L,4);\n% zg=zak(g,a);\n%\n% surf(abs(zg));\n%\n% See also: izak\n%\n% References: ja94-4 bohl97-1\n\n% AUTHOR : Peter L. Søndergaard\n% TESTING: TEST_ZAK\n% REFERENCE: REF_ZAK\n\ncomplainif_argnonotinrange(nargin,2,2,mfilename);\n\nif (prod(size(a))~=1 || ~isnumeric(a))\n error([callfun,': a must be a scalar']);\nend;\n\nif rem(a,1)~=0\n error([callfun,': a must be an integer']);\nend;\n\n\nif size(f,2)>1 && size(f,1)==1\n % f was a row vector.\n f=f(:);\nend;\n\nL=size(f,1);\nW=size(f,2);\nN=L/a;\n\nif rem(N,1)~=0\n error('The parameter for ZAK must divide the length of the signal.');\nend;\n\nc=zeros(a,N,W,assert_classname(f));\n\nfor ii=1:W\n % Compute it, it can be done in one line!\n % We use a normalized DFT, as this gives the correct normalization\n % of the Zak transform.\n c(:,:,ii)=dft(reshape(f(:,ii),a,N),[],2);\nend;\n\n\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/gabor/zak.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172659321807, "lm_q2_score": 0.8902942348544447, "lm_q1q2_score": 0.8448155712132625}} {"text": "function x = line_grid ( n, a, b, c )\n\n%*****************************************************************************80\n%\n%% LINE_GRID: grid points over the interior of a line segment in 1D.\n%\n% Discussion:\n%\n% In 1D, a grid is created using N points.\n%\n% Over the interval [A,B], we have 5 choices for grid centering:\n% 1: 0, 1/3, 2/3, 1\n% 2: 1/5, 2/5, 3/5, 4/5\n% 3: 0, 1/4, 2/4, 3/4\n% 4: 1/4, 2/4, 3/4, 1\n% 5: 1/8, 3/8, 5/8, 7/8\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 31 August 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of points.\n%\n% Input, real A, B, the endpoints for each dimension.\n%\n% Input, integer C, the grid centering for each dimension.\n% 1 <= C <= 5.\n%\n% Output, real X(N), the points.\n%\n\n%\n% Create the 1D grids in each dimension.\n%\n x = zeros ( n, 1 );\n\n for j = 1 : n\n\n if ( c == 1 )\n\n if ( n == 1 )\n x(j) = 0.5 * ( a + b );\n else\n x(j) = ( ( n - j ) * a ...\n + ( j - 1 ) * b ) ... \n / ( n - 1 );\n end\n elseif ( c == 2 )\n x(j) = ( ( n - j + 1 ) * a ...\n + ( j ) * b ) ... \n / ( n + 1 );\n elseif ( c == 3 )\n x(j) = ( ( n - j + 1 ) * a ...\n + ( j - 1 ) * b ) ... \n / ( n );\n elseif ( c == 4 )\n x(j) = ( ( n - j ) * a ...\n + ( j ) * b ) ...\n / ( n );\n elseif ( c == 5 )\n x(j) = ( ( 2 * n - 2 * j + 1 ) * a ...\n + ( 2 * j - 1 ) * b ) ...\n / ( 2 * n );\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/line_grid/line_grid.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.900529776774399, "lm_q1q2_score": 0.8448086122787265}} {"text": "function geometry_test1746 ( )\n\n%*****************************************************************************80\n%\n%% TEST1746 tests R8MAT_INVERSE_3D.\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 n = 3;\n\n a = [ ...\n 3.0, 2.0, 0.0; ...\n 2.0, 2.0, 1.0; ...\n 1.0, 1.0, 1.0 ]';\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST1746\\n' );\n fprintf ( 1, ' R8MAT_INVERSE_3D inverts a 3 by 3 matrix.\\n' );\n\n r8mat_print ( n, n, a, ' Matrix A:' );\n\n [ b, det ] = r8mat_inverse_3d ( a );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Determinant of A is %f\\n', det );\n\n r8mat_print ( n, n, b, ' Inverse matrix B:' );\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_test1746.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.9059898216525935, "lm_q1q2_score": 0.844793210394997}} {"text": "function A = vandermonde_interp_1d_matrix ( n, x )\n\n%*****************************************************************************80\n%\n%% VANDERMONDE_INTERP_1D_MATRIX computes a Vandermonde 1D interpolation matrix.\n%\n% Discussion:\n%\n% We assume the interpolant has the form\n%\n% p(x) = c1 + c2 * x + c3 * x^2 + ... + cn * x^(n-1).\n%\n% We have n data values (x(i),y(i)) which must be interpolated:\n%\n% p(x(i)) = c1 + c2 * x(i) + c3 * x(i)^2 + ... + cn * x(i)^(n-1) = y(i)\n%\n% This can be cast as an NxN linear system for the polynomial\n% coefficients:\n%\n% [ 1 x1 x1^2 ... x1^(n-1) ] [ c1 ] = [ y1 ]\n% [ 1 x2 x2^2 ... x2^(n-1) ] [ c2 ] = [ y2 ]\n% [ ...................... ] [ ... ] = [ ... ]\n% [ 1 xn xn^2 ... xn^(n-1) ] [ cn ] = [ yn ]\n%\n% and if the x values are distinct, the matrix A is theoretically\n% invertible (though in fact, generally badly conditioned).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 July 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of data points.\n%\n% Input, real X(N,1), the data values.\n%\n% Output, real A(N,N), the Vandermonde matrix for X.\n%\n A = ( x(1:n,1) * ones(1,n) ) .^ ( ones(n,1) * (0: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/vandermonde_interp_1d/vandermonde_interp_1d_matrix.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778000158575, "lm_q2_score": 0.8824278772763471, "lm_q1q2_score": 0.8447286170317646}} {"text": "function [ x, ierror ] = congruence ( a, b, c )\n\n%*****************************************************************************80\n%\n%% CONGRUENCE solves a congruence of the form A * X = C ( mod B ).\n%\n% Discussion:\n%\n% A, B and C are given integers. The equation is solvable if and only\n% if the greatest common divisor of A and B also divides C.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 22 May 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Eric Weisstein, editor,\n% CRC Concise Encylopedia of Mathematics,\n% CRC Press, 1998, page 446.\n%\n% Parameters:\n%\n% Input, integer A, B, C, the coefficients of the Diophantine equation.\n%\n% Output, integer X, the solution of the Diophantine equation.\n% X will be between 0 and B-1.\n%\n% Output, integer IERROR, error flag.\n% 0, no error, X was computed.\n% 1, A = B = 0, C is nonzero.\n% 2, A = 0, B and C nonzero, but C is not a multiple of B.\n% 3, A nonzero, B zero, C nonzero, but C is not a multiple of A.\n% 4, A, B, C nonzero, but GCD of A and B does not divide C.\n% 5, algorithm ran out of internal space.\n%\n nmax = 100;\n%\n% Defaults for output parameters.\n%\n ierror = 0;\n x = 0;\n y = 0;\n%\n% Special cases.\n%\n if ( a == 0 & b == 0 & c == 0 )\n x = 0;\n return\n elseif ( a == 0 & b == 0 & c ~= 0 )\n ierror = 1;\n x = 0;\n return\n elseif ( a == 0 & b ~= 0 & c == 0 )\n x = 0;\n return\n elseif ( a == 0 & b ~= 0 & c ~= 0 )\n x = 0;\n if ( mod ( c, b ) ~= 0 )\n ierror = 2;\n end\n return\n elseif ( a ~= 0 & b == 0 & c == 0 )\n x = 0;\n return\n elseif ( a ~= 0 & b == 0 & c ~= 0 )\n x = c / a;\n if ( mod ( c, a ) ~= 0 )\n ierror = 3;\n end\n return\n elseif ( a ~= 0 & b ~= 0 & c == 0 )\n% g = i4_gcd ( a, b );\n% x = b / g;\n x = 0;\n return\n end\n%\n% Now handle the \"general\" case: A, B and C are nonzero.\n%\n% Step 1: Compute the GCD of A and B, which must also divide C.\n%\n g = i4_gcd ( a, b );\n\n if ( mod ( c, g ) ~= 0 )\n ierror = 4;\n return\n end\n\n a_copy = a / g;\n b_copy = b / g;\n c_copy = c / g;\n%\n% Step 2: Split A and B into sign and magnitude.\n%\n a_mag = abs ( a_copy );\n a_sign = i4_sign ( a_copy );\n b_mag = abs ( b_copy );\n b_sign = i4_sign ( b_copy );\n%\n% Another special case, A_MAG = 1 or B_MAG = 1.\n%\n if ( a_mag == 1 )\n x = a_sign * c_copy;\n return\n elseif ( b_mag == 1 )\n x = 0;\n return\n end\n%\n% Step 3: Produce the Euclidean remainder sequence.\n%\n if ( b_mag <= a_mag )\n\n swap = 0;\n q(1) = a_mag;\n q(2) = b_mag;\n\n else\n\n swap = 1;\n q(1) = b_mag;\n q(2) = a_mag;\n\n end\n\n n = 3;\n\n while ( 1 )\n\n q(n) = mod ( q(n-2), q(n-1) );\n\n if ( q(n) == 1 )\n break;\n end\n\n n = n + 1;\n\n if ( nmax < n )\n ierror = 5;\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'CONGRUENCE - Fatal error!\\n' );\n fprintf ( 1, ' Exceeded number of iterations.\\n' );\n error ( 'CONGRUENCE - Fatal error!' );\n end\n\n end\n%\n% Step 4: Now go backwards to solve X * A_MAG + Y * B_MAG = 1.\n%\n y = 0;\n for k = n : -1 : 2\n x = y;\n y = ( 1 - x * q(k-1) ) / q(k);\n end\n%\n% Step 5: Undo the swapping.\n%\n if ( swap )\n z = x;\n x = y;\n y = z;\n end\n%\n% Step 6: Now apply signs to X and Y so that X * A + Y * B = 1.\n%\n x = x * a_sign;\n%\n% Step 7: Multiply by C, so that X * A + Y * B = C.\n%\n x = x * c_copy;\n%\n% Step 8: Now force 0 <= X < B.\n%\n x = mod ( x, b );\n%\n% Step 9: Force positivity.\n%\n if ( x < 0 )\n x = x + b;\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/uniform/congruence.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067228145365, "lm_q2_score": 0.8962513682840824, "lm_q1q2_score": 0.8447229399394747}} {"text": "function F = bst_window( Method, L, R )\n% BST_WINDOW: Generate a window of length L, ot the given type: hann, hamming, blackman, parzen, tukey\n% \n% USAGE: F = bst_window( Method, L, R )\n% \n% References:\n% Formulas documented on Wikipedia: http://en.wikipedia.org/wiki/Window_function\n\n% @=============================================================================\n% This function is part of the Brainstorm software:\n% https://neuroimage.usc.edu/brainstorm\n% \n% Copyright (c) University of Southern California & McGill University\n% This software is distributed under the terms of the GNU General Public License\n% as published by the Free Software Foundation. Further details on the GPLv3\n% license can be found at http://www.gnu.org/copyleft/gpl.html.\n% \n% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED \"AS IS,\" AND THE\n% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY\n% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF\n% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY\n% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.\n%\n% For more information type \"brainstorm license\" at command prompt.\n% =============================================================================@\n%\n% Authors: Francois Tadel, 2013-2014\n\n% Parse inputs\nif (nargin < 3) || isempty(R)\n R = [];\nend\nif (nargin < 2) || isempty(L)\n L = 64;\nend\nif (nargin < 1) || isempty(Method)\n Method = 'hann';\nend\n% Calculate normalized time vector\nt = (0:L-1)' ./ (L-1);\n% Switch according to windowing method \nswitch (lower(Method))\n case 'hann'\n F = 0.5 - 0.5 * cos(2*pi*t);\n case 'hamming'\n F = 0.54 - 0.46 * cos(2*pi*t);\n case 'blackman'\n F = 0.42 - 0.5 * cos(2*pi*t) + 0.08 * cos(4*pi*t);\n case 'tukey'\n % Tukey window = tapered cosine window, cosine lobe of width aL/2 \n if isempty(R)\n R = 0.5;\n end\n a = R;\n % If a=0: square function\n if (a <= 0)\n F = ones(L,1);\n % If a=1: Hann window\n elseif (a >= 1)\n F = bst_window('hann', L);\n % Else: Function in three blocks\n else\n % Define three blocks\n len = floor(a*(L-1)/2) + 1;\n t1 = t(1:len);\n t3 = t(L-len+1:end);\n % Window is defined in three sections: taper, constant, taper\n F = [ 0.5 * (1 + cos(pi * (2*t1/a - 1))); ...\n ones(L-2*len,1); ...\n 0.5 * (1 + cos(pi * (2*t3/a - 2/a + 1)))];\n end\n case 'parzen'\n % Reference:\n % Harris FJ, On the Use of Windows for Harmonic Analysis with the Discrete Fourier Transform, \n % Proceedings of IEEE, Vol. 66, No. 1, January 1978 [Equation 37]\n \n % Time indices\n t = -(L-1)/2 : (L-1)/2;\n i1 = find(abs(t) <= (L-1)/4); % 0 <= |n| <= N/4\n i2 = find(abs(t) > (L-1)/4); % N/4 < |n| < N/2\n \n % Definition of the Parzen window: 2 parts\n F = zeros(length(t), 1);\n F(i1) = 1 - 6 .* (t(i1)/L*2).^2 .* (1 - abs(t(i1))/L*2);\n F(i2) = 2 .* (1 - abs(t(i2))/L*2) .^3;\n \n otherwise\n error(['Unsupported windowing method: \"' Method '\".']);\nend\n\n\n", "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/toolbox/math/bst_window.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.9086178987887253, "lm_q1q2_score": 0.8445061903133686}} {"text": "function value = agud ( g )\n\n%*****************************************************************************80\n%\n%% AGUD evaluates the inverse Gudermannian function.\n%\n% Discussion:\n%\n% The Gudermannian function relates the hyperbolic and trigonomentric\n% functions. For any argument X, there is a corresponding value\n% G so that\n%\n% SINH(X) = TAN(G).\n%\n% This value G(X) is called the Gudermannian of X. The inverse\n% Gudermannian function is given as input a value G and computes\n% the corresponding value X.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 20 July 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real G, the value of the Gudermannian.\n%\n% Output, real VALUE, the argument of the Gudermannian.\n%\n value = log ( tan ( 0.25 * pi + 0.5 * g ) );\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/polpak/agud.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9518632316144274, "lm_q2_score": 0.8872045937171068, "lm_q1q2_score": 0.8444974316787304}} {"text": "function [ mX ] = ProjectPosSemiDefinite( mY, numIterations, stopTol )\n% ----------------------------------------------------------------------------------------------- %\n% [ mX ] = ProjectPosSemiDefinite( mY, numIterations, stopTol )\n% Solves \\arg \\min_{X} 0.5 || X - Y ||, s.t. X \\in \\mathcal{S}_{+}^{n} by\n% Iterative Projection onto the set of Symmetric Matrices and PSD\n% Matrices.\n% Input:\n% - mY - Input Matrix.\n% Input model matrix.\n% Structure: Matrix (m x n).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - numIterations - Number of Iterations.\n% Sets the number of iterations for the algorithm to\n% run.\n% Structure: Scalar.\n% Type: 'Single' / 'Double'.\n% Range {1, 2, ...}.\n% - stopTol - Stopping Condition Tolerance.\n% Sets the stopping threshold for the L Inf (Maximum\n% Absolute Value) of the change between 2 iterations\n% of the algorithm.\n% Structure: Scalar.\n% Type: 'Single' / 'Double'.\n% Range [0, inf).\n% Output:\n% - mX - Solution Matrix.\n% A PSD Symmetric matrix which is the closest in\n% Frobenius Norm sense to 'mY'.\n% Structure: Matrix (m x n).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% References\n% 1. A\n% Remarks:\n% 1. Since both the Symmetric Matrices Set and the PSD Matrices Set are\n% sub spaces the iterative (POCS) projection onto each is the\n% orthogonal projection onto the intersection. See https://math.stackexchange.com/questions/1492095.\n% TODO:\n% 1. C\n% Release Notes:\n% - 1.0.000 12/04/2020 Royi Avital\n% * First release version.\n% ----------------------------------------------------------------------------------------------- %\n\nFALSE = 0;\nTRUE = 1;\n\nOFF = 0;\nON = 1;\n\nvectorMode = OFF;\n\nif(size(mY, 2) == 1)\n numRows = sqrt(size(mY, 1));\n vectorMode = ON;\n mX = reshape(mY, numRows, numRows);\nelse\n numRows = size(mY, 1);\n mX = mY;\nend\n\nmQ = zeros(numRows, numRows);\nmD = zeros(numRows, numRows);\nmXPrev = mX;\n\nfor ii = 1:numIterations\n % Projection onto Symmetric Matrices Set\n mX(:) = (mX.' + mX) / 2;\n \n % Projection onto PSD Matrices Set\n [mQ(:), mD(:)] = eig(mX);\n mD(:) = max(mD, 0);\n mX(:) = mQ * mD * mQ.';\n \n if(max(abs(mX(:) - mXPrev(:))) <= stopTol)\n break;\n end\n \n mXPrev(:) = mX;\n \nend\n\nif(vectorMode == ON)\n mX = mX(:);\nend\n\n\nend\n\n", "meta": {"author": "RoyiAvital", "repo": "StackExchangeCodes", "sha": "d2a934616995fa8a9f4df1ca29029402435b9e6f", "save_path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes", "path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes/StackExchangeCodes-d2a934616995fa8a9f4df1ca29029402435b9e6f/Mathematics/Q3619669/ProjectPosSemiDefinite.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632316144274, "lm_q2_score": 0.8872045847699186, "lm_q1q2_score": 0.844497423162231}} {"text": "function verifyquadpts\n%% VERIFYQUADPTS examples and verfication on quadrature rules.\n%\n% error = verifyquadpts(n) computes the error of n-th order quadrature\n% rule in a triangle. This is an example on the usage of quadrature points\n% and verification of qudarture order for approximating integrals in a\n% triangle.\n%\n% See also quadpts\n%\n% Copyright (C) Long Chen. See COPYRIGHT.txt for details. \n\n% a reference triangle\nnode = [0 0; 1 0; 0 1];\nelem = [1 2 3];\narea = 0.5;\nerr = zeros(9,2);\nfor n = 1:9 \n % get quadrature points\n [lambda,weight] = quadpts(n);\n nQuad = size(lambda,1);\n t1 = 0; \n t2 = 0;\n for p = 1:nQuad\n % quadrature points in the x-y coordinate\n pxy = lambda(p,1)*node(elem(:,1),:) ...\n + lambda(p,2)*node(elem(:,2),:) ...\n + lambda(p,3)*node(elem(:,3),:);\n t1 = t1 + weight(p)*f1(pxy(1),pxy(2),n);\n t2 = t2 + weight(p)*f2(pxy(1),pxy(2));\n end \n t1 = t1*area;\n t2 = t2*area;\n err(n,1) = abs(t1 - 2/((n+1)*(n+2)));\n err(n,2) = abs(t2 - (sin(1) - cos(1)));\nend\nts = zeros(9,3); ts = char(ts);\ndisplay('n x^n + y^n sin(x+y)');\ndisplay([num2str((1:9)') ts num2str(err(:,1),'%0.5e') ts num2str(err(:,2),'%0.5e')]);\nend\n\nfunction z = f1(x,y,n)\nz = x.^n + y.^n;\nend\n\nfunction z = f2(x,y)\nz = sin(x+y);\nend\n\n%% Results\n% Let T be the triangle formed by (0,0), (1,0), and (0,1). \n%\n% Error1 is for the integral \n% $\\int _{T} x^n + y^n \\, dxdy$. \n% It should be numerically exact. \n%\n% Error2 is for the integral \n% $\\int _{T} \\sin(x+y) \\, dxdy$.\n% It decays as n increas.\n%\n% See the doc for qudrature rules in .\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/afem/verifyquadpts.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480347, "lm_q2_score": 0.90192067257508, "lm_q1q2_score": 0.8444548021062301}} {"text": "function theta = lines_imp_angle_2d ( a1, b1, c1, a2, b2, c2 )\n\n%*****************************************************************************80\n%\n%% LINES_IMP_ANGLE_2D finds the angle between two implicit lines in 2D.\n%\n% Discussion:\n%\n% The implicit form of a line in 2D is:\n%\n% A * X + B * Y + C = 0\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 February 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, real A1, B1, C1, the implicit parameters of the \n% first line.\n%\n% Input, real A2, B2, C2, the implicit parameters of the\n% second line.\n%\n% Output, real THETA, the angle between the two lines.\n%\n pdotq = a1 * a2 + b1 * b2;\n pnorm = sqrt ( a1 * a1 + b1 * b1 );\n qnorm = sqrt ( a2 * a2 + b2 * b2 );\n\n theta = r8_acos ( pdotq / ( pnorm * qnorm ) );\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/lines_imp_angle_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966747198242, "lm_q2_score": 0.8918110540642805, "lm_q1q2_score": 0.8441853782556293}} {"text": "function [inter, inside]= intersectRayPolygon3d(ray, poly)\n%INTERSECTRAYPOLYGON3D Intersection point of a 3D ray and a 3D polygon\n%\n% INTER = intersectRayPolygon3d(RAY, POLY)\n% Compute coordinates of intersection point between the 3D ray RAY and\n% the 3D polygon POLY. RAY is a 1-by-6 row vector containing origin and\n% direction vector of the ray, POLY is a Np-by-3 array containing\n% coordinates of 3D polygon vertices.\n% INTER is a 1-by-3 row vector containing coordinates of intersection\n% point, or [NaN NaN NaN] if ray and polygon do not intersect.\n%\n% INTERS = intersectRayPolygon3d(RAYS, POLY)\n% If RAYS is a N-by-6 array representing several rays, the result\n% INTERS is a N-by-3 array containing coordinates of intersection of each\n% ray with the polygon.\n%\n% [INTER INSIDE] = intersectRayPolygon3d(RAY, POLY)\n% Also return a N-by-1 boolean array containing TRUE if both the polygon\n% and the corresponding ray contain the intersection point.\n%\n% Example\n% % Compute intersection between a 3D ray and a 3D triangle\n% pts3d = [3 0 0; 0 6 0;0 0 9];\n% ray1 = [0 0 0 3 6 9];\n% inter = intersectRayPolygon3d(ray1, pts3d)\n% inter =\n% 1 2 3\n%\n% % keep only valid intersections with several rays\n% pts3d = [3 0 0; 0 6 0;0 0 9];\n% rays = [0 0 0 3 6 9;10 0 0 1 2 3;3 6 9 3 6 9];\n% [inter inside] = intersectRayPolygon3d(rays, pts3d);\n% inter(inside, :)\n% ans = \n% 1 2 3\n%\n% See Also\n% intersectRayPolygon, intersectLinePolygon3d, intersectLineTriangle3d\n%\n\n% ------\n% Author: David Legland\n% e-mail: david.legland@inra.fr\n% Created: 2011-05-22, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2011 INRA - Cepia Software Platform.\n\n% supporting plane of polygon vertices\nplane = createPlane(poly(1:3, :));\n\n% intersection of 3D ray with the plane\ninter = intersectLinePlane(ray, plane);\n\n% project all points on reference plane\npts2d = planePosition(projPointOnPlane(poly, plane), plane);\npInt2d = planePosition(projPointOnPlane(inter, plane), plane);\n\n% need to check polygon orientation\ninPoly = xor(isPointInPolygon(pInt2d, pts2d), polygonArea(pts2d) < 0);\nonRay = linePosition3d(inter, ray) >= 0;\ninside = inPoly & onRay;\n\n% intersection points outside the polygon are set to NaN\ninter(~inside, :) = NaN;\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/intersectRayPolygon3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475699138558, "lm_q2_score": 0.8947894696095782, "lm_q1q2_score": 0.8440974717407035}} {"text": "function cx = jacobi_poly ( n, alpha, beta, x )\n\n%*****************************************************************************80\n%\n%% JACOBI_POLY evaluates the Jacobi polynomials at X.\n%\n% Differential equation:\n%\n% (1-X*X) Y'' + (BETA-ALPHA-(ALPHA+BETA+2) X) Y' + N (N+ALPHA+BETA+1) Y = 0\n%\n% Recursion:\n%\n% P(0,ALPHA,BETA,X) = 1,\n%\n% P(1,ALPHA,BETA,X) = ( (2+ALPHA+BETA)*X + (ALPHA-BETA) ) / 2\n%\n% P(N,ALPHA,BETA,X) = \n% ( \n% (2*N+ALPHA+BETA-1) \n% * ((ALPHA**2-BETA**2)+(2*N+ALPHA+BETA)*(2*N+ALPHA+BETA-2)*X) \n% * P(N-1,ALPHA,BETA,X)\n% -2*(N-1+ALPHA)*(N-1+BETA)*(2*N+ALPHA+BETA) * P(N-2,ALPHA,BETA,X)\n% ) / 2*N*(N+ALPHA+BETA)*(2*N-2+ALPHA+BETA)\n%\n% Restrictions:\n%\n% -1 < ALPHA\n% -1 < BETA\n%\n% Norm:\n%\n% Integral ( -1 <= X <= 1 ) ( 1 - X )**ALPHA * ( 1 + X )**BETA \n% * P(N,ALPHA,BETA,X)**2 dX \n% = 2**(ALPHA+BETA+1) * Gamma ( N + ALPHA + 1 ) * Gamma ( N + BETA + 1 ) /\n% ( 2 * N + ALPHA + BETA ) * N! * Gamma ( N + ALPHA + BETA + 1 )\n%\n% Special values:\n%\n% P(N,ALPHA,BETA)(1) = (N+ALPHA)!/(N!*ALPHA!) for integer ALPHA.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 24 July 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% Parameters:\n%\n% Input, integer N, the highest order polynomial to compute. Note\n% that polynomials 0 through N will be computed.\n%\n% Input, real ALPHA, one of the parameters defining the Jacobi\n% polynomials, ALPHA must be greater than -1.\n%\n% Input, real BETA, the second parameter defining the Jacobi\n% polynomials, BETA must be greater than -1.\n%\n% Input, real X, the point at which the polynomials are to be evaluated.\n%\n% Output, real CX(1:N+1), the values of the first N+1 Jacobi\n% polynomials at the point X.\n%\n if ( alpha <= -1.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'JACOBI_POLY - Fatal error!\\n' );\n fprintf ( 1, ' Illegal input value of ALPHA = %f\\n', alpha );\n fprintf ( 1, ' But ALPHA must be greater than -1.\\n' );\n error ( 'JACOBI_POLY - Fatal error!' );\n end\n \n if ( beta <= -1.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'JACOBI_POLY - Fatal error!\\n' );\n fprintf ( 1, ' Illegal input value of BETA = %f\\n', beta );\n fprintf ( 1, ' But BETA must be greater than -1.\\n' );\n error ( 'JACOBI_POLY - Fatal error!' );\n end\n \n if ( n < 0 )\n cx = [];\n return\n end\n\n cx(1) = 1.0;\n\n if ( n == 0 )\n return\n end\n\n cx(2) = ( 1.0 + 0.5 * ( alpha + beta ) ) * x + 0.5 * ( alpha - beta );\n \n for i = 2 : n\n\n c1 = 2 * i * ( i + alpha + beta ) * ( 2 * i - 2 + alpha + beta );\n\n c2 = ( 2 * i - 1 + alpha + beta ) * ( 2 * i + alpha + beta ) ...\n * ( 2 * i - 2 + alpha + beta );\n\n c3 = ( 2 * i - 1 + alpha + beta ) * ( alpha + beta ) * ( alpha - beta );\n\n c4 = - 2 * ( i - 1 + alpha ) * ( i - 1 + beta ) * ( 2 * i + alpha + beta );\n\n cx(i+1) = ( ( c3 + c2 * x ) * cx(i) + c4 * cx(i-1) ) / c1;\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/polpak/jacobi_poly.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475762847495, "lm_q2_score": 0.8947894569842487, "lm_q1q2_score": 0.8440974655312382}} {"text": "function yi = lagrange_basis_function_1d ( mx, xd, i, xi ) \n\n%*****************************************************************************80\n%\n%% LAGRANGE_BASIS_FUNCTION_1D evaluates a 1D Lagrange basis function.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 04 August 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer MX, the degree of the basis function.\n%\n% Input, real XD(MX+1), the interpolation nodes.\n%\n% Input, integer I, the index of the basis function.\n% 1 <= I <= MX+1.\n%\n% Input, real XI, the evaluation point.\n%\n% Output, real YI, the value of the I-th Lagrange 1D basis function\n% for the nodes XD, evaluated at XI.\n%\n if ( xi == xd(i) )\n yi = 1.0;\n else\n j = find ( 1 : mx + 1 ~= i );\n yi = prod ( xi - xd(j) ) / prod ( xd(i) - xd(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/lagrange_interp_2d/lagrange_basis_function_1d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9433475715065793, "lm_q2_score": 0.894789457685656, "lm_q1q2_score": 0.8440974619174527}} {"text": "function [coeffs,sigma2]=multilinRegress(zSamp,y,w,hasIntercept)\n%%MULTILINREGRESS Perform multilinear regression. This means, given a set\n% of multidimensional points of the form [x1;x2;x3;...;xn],\n% determine the line/plane/hyperplane best fitting the points\n% such that\n% xn=coeffs(1)*x(2)+coeffs(2)*x(3)+....coeffs(n-1)*x(n-1)+coeffs(n)\n% if there is an intercept or\n% xn=coeffs(1)*x(2)+coeffs(2)*x(3)+....coeffs(n)*x(n).\n% if it is known there is a zero intercept.\n% The \"best\" fitting line/plane/hyperplane is the one that\n% minimizes\n% sum_{i=1}^N w(i)*(dot(coeffs(1:(n-1)),zSamp(1:(n-1),i))+coeffs(n)-zSamp(n,i))^2\n% if there is an intercept and y is not provided or that minimizes\n% sum_{i=1}^N w(i)*(dot(coeffs(1:(n-1)),zSamp(:,i))+coeffs(n)-y(i))^2\n% if y is provided and there is a y intercept. If there is no y\n% intercept, then the coeffs(n) term goes away in both instances.\n% The w(i) terms are all positive weights. For unweighted fusion,\n% w(i)=1.\n%\n%INPUTS: There are two parameterizations for zSamp and y. If y is an empty\n% matrix, then zSamp is a numDimsXnumPoints set of numPoints data\n% samples numDims>=2, as given above. On the other hand, if y is\n% provided, then y corresponds to zSamp(n,:) in the previous\n% parameterization (and can be a row or column vector) and zSamp thus\n% lacks the final row that it has in the initial parameterization.\n% Thus, zSamp will be a (numDims-1)XnumPoints matrix when y is\n% given.\n% w If weighted linear least squares optimization is supposed to be\n% performed, this is a length numPoints vector of values >0\n% containing the weight of each sample. If the regression is\n% performed with un unweighted cost function, this parameter can be\n% omitted or an empty matrix can be passed.\n% hasIntercept A boolean value indicating whether the fit has a nonzero y\n% intercept. The default if omitted or an empty matrix is passed is\n% true.\n%\n%OUTPUTS: coeffs The numDimsX1 set of weights for the linear equation\n% described above. If hasIntercept=true, then the last\n% element is the additive constant.\n% sigma2 The residual mean square. This is SSE/(numPoints-numDims)\n% where SSE is the vector of ordinary residuals e'*diag(w)*e\n% where e=(y(:)-x'*coeffs), where x is\n% [zSamp;ones(1,numPoints)] if an intercept is desired and y\n% is given, or x=zSamp if an intercept is not desired and y\n% is given. Similar expressions for when y is not given\n% hold, whereby y is replaced by the last row of zSamp. This\n% is the quantity being minimized in the optimization.\n%\n%Formulae for this type of regression are given in Appendix A.7.1 and A.7.3\n%of [1] for 2D and 3D measurements without the weights. This function just\n%continues the pattern implementing the results for an arbitrary number of\n%dimensions, for weights and a modification allowing for there to be a\n%known zero y intercept is also added. The derivation is just basic\n%differential calculus. Note that this function will fail if the plane\n%being estimated does not depend on the independent parameter. In 2D, this\n%would correspond to a vertical line (e.g. x=4).\n%\n%EXAMPLE 1:\n%Here is an example with a nonzero y intercept using both input formats.\n% coeffs=[4;6;2];\n% numPts=20;\n% xVals=linspace(-4,4,numPts);\n% yVals=linspace(-4,4,numPts);\n% [x,y]=ndgrid(xVals,yVals);\n% xyPts=[x(:).';y(:).'];\n% zPts=sum(bsxfun(@times,coeffs(1:2),xyPts),1)+coeffs(3);\n% zPts=zPts+0.1*randn(1,numPts^2); %Add noise.\n% zSamp=[xyPts;zPts];\n% [coeffsEst,sigma2]=multilinRegress(zSamp)\n% [coeffsEstAlt,sigma2Alt]=multilinRegress(xyPts,zPts)\n%One finds that coeffsEst is the same as coeffsEstAlt and is close to\n%coeffs. A perfect fit (wihtin finite precision limitaitions) is achieved\n%if there is zero noise.\n%\n%EXAMPLE 2:\n%Here is an example when it is known that the y intercept is zero.\n% coeffs=[4;6];\n% numPts=20;\n% xVals=linspace(-4,4,numPts);\n% yVals=linspace(-4,4,numPts);\n% [x,y]=ndgrid(xVals,yVals);\n% xyPts=[x(:).';y(:).'];\n% zPts=sum(bsxfun(@times,coeffs(1:2),xyPts),1);\n% zPts=zPts+0.1*randn(1,numPts^2); %Add noise.\n% zSamp=[xyPts;zPts];\n% [coeffsEst,sigma2]=multilinRegress(zSamp,[],[],false)\n% [coeffsEstAlt,sigma2Alt]=multilinRegress(xyPts,zPts,[],false)\n%Again, the results are comparable to those in problem 1 with the two input\n%formulations equal and close to coeffs.\n%\n%REFERENCES:\n%[1] P. J. Schneider and D. H. Eberly, Geometric Tools for Computer\n% Graphics. Amsterdam: Morgan Kaufmann Publishers, 2003.\n%\n%April 2017 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nnumDims=size(zSamp,1);\nnumPoints=size(zSamp,2);\n\nif(nargin<4||isempty(hasIntercept))\n hasIntercept=true; \nend\n\nif(nargin<3)\n w=[]; \nend\n\nif(nargin>1&&~isempty(y))\n if(hasIntercept)\n x=[zSamp;ones(1,numPoints)];\n p=numDims+1;\n else\n x=zSamp;\n p=numDims;\n end\nelse\n if(hasIntercept)\n x=[zSamp(1:(numDims-1),:);ones(1,numPoints)];\n p=numDims;\n else\n x=zSamp(1:(numDims-1),:);\n p=numDims-1;\n end\n \n y=zSamp(numDims,:);\n y=y(:);\nend\n\nif(isempty(w))\n A=x*x';\n b=x*y(:);\nelse\n %In Matlab, x*eye(size(x,2))*x'-x*x' and\n %bsxfun(@times,x,ones(numPoints,1).')*x'-x*x' are not numerically zero,\n %which means that just using w with weights all equal to 1 will change\n %the last few bits of the result.\n\n w=w(:);\n A=bsxfun(@times,w.',x)*x';\n b=x*(w.*y(:));\nend\n\ncoeffs=A\\b;\n\nif(nargout>1)\n if(nargin>1&&~isempty(y))\n e=y(:)-x'*coeffs;\n else\n e=vec(zSamp(numDims,:))-x'*coeffs;\n end\n\n if(isempty(w))\n %The residual sum of squares.\n sigma2=e'*e/(numPoints-p);\n else%The weighted residual sum of squares.\n sigma2=(w.*e)'*e/(numPoints-p);\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/Statistics/multilinRegress.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395157060208, "lm_q2_score": 0.9032942008463507, "lm_q1q2_score": 0.844033726671401}} {"text": "function alpha = anglePoints3d(varargin)\n%ANGLEPOINTS3D Compute angle between three 3D points.\n%\n% ALPHA = anglePoints3d(P1, P2)\n% Computes angle (P1, O, P2), in radians, between 0 and PI.\n%\n% ALPHA = anglePoints3d(P1, P2, P3)\n% Computes angle (P1, P2, P3), in radians, between 0 and PI.\n%\n% ALPHA = anglePoints3d(PTS)\n% PTS is a 3x3 or 2x3 array containing coordinate of points.\n%\n% Example\n% rad2deg(anglePoints3d([0 0 1],[1 1 0]))\n%\n% See also \n% points3d, angles3d\n\n% ------\n% Author: David Legland \n% E-mail: david.legland@inrae.fr\n% Created: 2005-02-21\n% Copyright 2005-2022 INRA - TPV URPOI - BIA IMASTE\n\np2 = [0 0 0];\nif length(varargin) == 1\n pts = varargin{1};\n if size(pts, 1)==2\n p1 = pts(1,:);\n p0 = [0 0 0];\n p2 = pts(2,:);\n else\n p1 = pts(1,:);\n p0 = pts(2,:);\n p2 = pts(3,:);\n end\n \nelseif length(varargin) == 2\n p1 = varargin{1};\n p0 = [0 0 0];\n p2 = varargin{2};\n \nelseif length(varargin) == 3\n p1 = varargin{1};\n p0 = varargin{2};\n p2 = varargin{3};\nend\n\n% ensure all data have same size\nn1 = size(p1, 1);\nn2 = size(p2, 1);\nn0 = size(p0, 1);\n\nif n1 ~= n0\n if n1 == 1\n p1 = repmat(p1, [n0 1]);\n n1 = n0;\n elseif n0==1\n p0 = repmat(p0, [n1 1]);\n else\n error('Arguments P1 and P0 must have the same size');\n end\nend\n\nif n1 ~= n2\n if n1 == 1\n p1 = repmat(p1, [n2 1]);\n elseif n2 == 1\n p2 = repmat(p2, [n1 1]);\n else\n error('Arguments P1 and P2 must have the same size');\n end\nend\n\n% normalized vectors\np1 = normalizeVector3d(p1 - p0);\np2 = normalizeVector3d(p2 - p0);\n\n% compute angle\nalpha = acos(dot(p1, p2, 2));\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/anglePoints3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541593883189, "lm_q2_score": 0.8962513662057089, "lm_q1q2_score": 0.8439588268450692}} {"text": "function bw = audfiltbw(fc,varargin)\n%AUDFILTBW Bandwidth of auditory filter\n% Usage: bw = audfiltbw(fc)\n%\n% `audfiltbw(fc)` returns the critical bandwidth of the auditory filter \n% at center frequency *fc* defined in equivalent rectangular bandwidth.\n% The function uses the relation:\n%\n% .. bw = 24.7 + fc/9.265\n%\n% .. math:: bw = 24.7 + \\frac{fc}{9.265}\n% \n% as estimated in Glasberg and Moore (1990). This function is also used\n% when the original ERB scale ('erb83') is chosen.\n% \n% `audfiltbw(fc,'bark')` returns the critical bandwidth at *fc* according\n% to the Bark scale using the relation:\n% \n% .. bw = 25 + 75 ( 1+1.4*10^{-6} fc^2 )^0.69\n%\n% .. math:: bw = 25 + 75 ( 1+1.4\\times10^{-6} fc^2 )^{0.69}\n% \n% as estimated by Zwicker and Terhardt (1980).\n%\n% For the scales 'mel', 'mel1000', 'log10' and 'semitone', no critical\n% bandwidth function is usually given. Following the example of the\n% equivalent rectangular bandwidth (associated with the ERB scale), we\n% use the derivative of the inverse of the scale function F_{Scale},\n% evaluated at F_{Scale}(fc), i.e. \n% \n% .. bw = (F_{scale}^{-1})'(F_{scale}(fc))\n%\n% .. math:: bw = (F_{scale}^{-1})'(F_{scale}(fc))\n%\n% See also: freqtoerb, erbspace, freqtoaud, audtofreq\n%\n% References: glasberg1990daf zwickerterhardt80\n \n% AUTHOR : Peter L. Søndergaard\n \n% ------ Checking of input parameters ---------\n \n% narginchk(1,1);\nif nargin<1\n error('%s: Too few input parameters.',upper(mfilename));\nend;\n\nif ~isnumeric(fc) || any(fc(:)<0)\n error('AUDFILTBW: fc must be non-negative.');\nend;\n\ndefinput.flags.audscale={'erb','erb83','bark','mel','mel1000','log10','semitone'};\n[flags,kv]=ltfatarghelper({},definput,varargin);\n\n% ------ Computation --------------------------\n\n% FIXME: What is the upper frequency for which the estimation is valid?\nif flags.do_erb || flags.do_erb83\n bw = 24.7 + fc/9.265;\nend\n\nif flags.do_bark\n bw = 25 + 75*(1 + 1.4E-6*fc.^2).^0.69;\nend\n\nif flags.do_mel \n bw = log(17/7)*(700+fc)/1000;\nend\n\nif flags.do_mel1000 \n bw = log(2)*(1+fc/1000);\nend;\n\nif flags.do_log10 || flags.do_semitone\n bw = fc;\nend\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/auditory/audfiltbw.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474220263197, "lm_q2_score": 0.8840392741081574, "lm_q1q2_score": 0.8439458139973715}} {"text": "% This function calculates the fractional derivative of order “d” for the \n% given function r(t). It is assumed that the vector “r” contains the \n% samples of the continuous signal r(t) which we are going to calculate its\n% fractional derivative. “h” is a constant and represents the sampling\n% period of r(t) (the time period between two samples). “h” must be small \n% enough in the sense of Nyquist sampling theorem.\n% “y” is the result achieved by applying the fractional differentiation \n% operator on the input “r”. This contains the samples of the real output\n% y(t) with the same sampling period used for “r”. \n% It makes use of the Grünwald-Letnikov definition. The first element of\n% the vector \"r\", i.e. r(1), is always zero.\n% \n% d : the order of fractional differentiation \n% r : samples of the signal to be differentiated \n% h : sampling poriod \n\n\nfunction [y] = fderiv(d,r,h)\n\ntemp = 0;\nfor i=1:length(r)\n for j=0:i-1\n temp = temp+(-1)^j*(gamma(d+1)/(gamma(j+1)*gamma(d-j+1)))*r(i-j);\n end\n y(i) = temp;\n temp = 0;\nend\ny = y/(h^d);\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/13858-fractional-differentiator/fderiv.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9674102542943773, "lm_q2_score": 0.872347369700144, "lm_q1q2_score": 0.8439177907546476}} {"text": "function [ a, b, c, d, e, f ] = rs_to_xy_map ( t )\n\n%*****************************************************************************80\n%\n%% RS_TO_XY_MAP returns the linear map from reference to physical triangle.\n%\n% Location:\n%\n% http://people.sc.fsu.edu/~jburkardt/m_src/triangle_poly_integral/rs_to_xy_map.m\n%\n% Discussion:\n%\n% This function returns the coefficients of the linear map that sends\n% the vertices of the reference triangle, (0,0), (1,0) and (0,1), to\n% the vertices of a physical triangle T, of the form:\n%\n% X = A + B * R + C * S;\n% Y = D + E * R + F * S.\n%\n% Reference Element:\n%\n% |\n% 1 3\n% | |\\\n% | | \\\n% S | \\\n% | | \\\n% | | \\\n% 0 1-----2\n% |\n% +--0--R--1-->\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 April 2015\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real T(2,3), the coordinates of the vertices. The vertices are \n% assumed to be the images of (0,0), (1,0) and (0,1) respectively.\n%\n% Output, real A, B, C, D, E, F, the mapping coefficients.\n%\n a = t(1,1);\n b = t(1,2) - t(1,1);\n c = t(1,3) - t(1,1);\n\n d = t(2,1);\n e = t(2,2) - t(2,1);\n f = t(2,3) - t(2,1);\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/triangle_integrals/rs_to_xy_map.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374443, "lm_q2_score": 0.904650536386234, "lm_q1q2_score": 0.8435443877137487}} {"text": "function [rankVal,V,U,S]=matrixRank(A,algorithm)\n%%MATRIXRANK Determine the rank of a matrix using a chosen criterion.\n%\n%INPUTS: A The MXN matrix whose rank is desired.\n% algorithm An optional parameter specifying the criterion to use. All\n% methods compare the singular values to a bound. Possible values\n% are:\n% 0 (The default if omitted or an empty matrix is passed) Use\n% eps(norm(A,1)) as the bound.\n% 1 Use max(size(A))*eps(max(s)), where s is the vector of\n% singular values.\n% 2 Use eps()*norm(A,1).\n% 3 Use max(size(A))*eps()*max(s).\n%\n%OUTPUTS: rankVal The rank of matrix A.\n% V The right singular vectors from the SVD used here (The\n% full SVD is computed, not the 'econ' or 0 options). Given\n% the rank, one can extract a basis or a nullspace.\n% U The left singular vectors from the SVD.\n% S A diagonal matrix of singular values from the SVD.\n%\n%The notion of the matrix rank relating to a thresholding of the singular\n%values is discussed in Chapter 5.4.1 of [1].\n%\n%REFERENCES:\n%[1] G. H. Golub and C. F. Van Loan, Matrix Computations, 4th ed.\n% Baltimore: Johns Hopkins University Press, 2013.\n%\n%September 2019 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<2||isempty(algorithm))\n algorithm=0;\nend\n\nif(nargout>1)\n [U,S,V]=svd(A);\nelse\n [~,S,~]=svd(A);\nend\ns=diag(S);\n\nswitch(algorithm)\n case 0\n rankVal=sum(s>eps(norm(A,1)));\n case 1\n rankVal=sum(s>max(size(A))*eps(max(s)));\n case 2\n rankVal=sum(s>eps()*norm(A,1));\n case 3\n rankVal=sum(s>max(size(A))*eps()*max(s));\n otherwise\n error('Unknown rank algorithm specified.')\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/Basic_Matrix_Operations/matrixRank.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.9207896834987981, "lm_q1q2_score": 0.8435442832561773}} {"text": "% This example shows how to calculate the TM_01 mode of a step-index\n% fiber. The magnetic field for the TM_01 mode is azimuthally\n% symmetric, which means that both Hx and Hy are of the same\n% magnitude, making this an excellent test case for the\n% full-vector modesolver. It also compares the numerically\n% calculated result with the exact solution. Note that the\n% modes look virtually identical, but there is a discrepancy\n% betweeen the numerically-computed eigenvalue and the exact\n% eigenvalue. This is thought to be caused by the the\n% inaccuracy of representing a curved core-clad interface with\n% a staircase function.\n\n% Refractive indices:\nnco = 2.5; % core index\nncl = 1.5; % cladding index\nr = 0.30; % core radius (um)\n\nside = 0.2; % space on side (um)\n\ndx = 0.002; % grid size (horizontal)\ndy = 0.002; % grid size (vertical)\n\nlambda = 1; % wavelength\nnmodes = 1; % number of modes to compute\n\n% Boundary conditions for antisymmetric mode\nboundary = '0A0S'; \n\n% Set up finite difference mesh:\n[x,y,xc,yc,nx,ny,eps] = fiber([nco,ncl],[r],side,dx,dy);\n\n% Now we stretch out the mesh at the boundaries:\n[x,y,xc,yc,dx,dy] = stretchmesh(x,y,[96,0,96,0],[4,1,4,1]);\n\n% Solve for mode (using transverse H modesolver)\n[Hx,Hy,neff] = wgmodes (lambda, nco, nmodes, dx, dy, eps, ...\n boundary); \nfprintf(1,'neff (finite difference) = %8.6f\\n',neff);\n\n% Now solve for the exact eigenmodes\nV = 2*pi*r/lambda*sqrt(nco^2-ncl^2);\nU = fzero(@(U) ...\n nco^2*besselj(1,U)/(U*besselj(0,U)) + ...\n ncl^2*besselk(1,sqrt(V^2-U^2))/ ...\n (sqrt(V^2-U^2)*besselk(0,sqrt(V^2-U^2))), 3.2);\nW = sqrt(V^2-U^2);\nneff0 = sqrt(nco^2 - (U/(2*pi*r/lambda))^2);\nfprintf(1,'neff (exact solution) = %8.6f\\n',neff0);\n\nrho = sqrt(x.^2*ones(size(y)) + ones(size(x))*y.^2);\nsinphi = ones(size(x))*y./rho;\ncosphi = x*ones(size(y))./rho;\nHx0 = zeros(size(rho));\nHy0 = zeros(size(rho));\nkv = find(rho < r);\nHx0(kv) = -sinphi(kv).*besselj(1,U*rho(kv)./r)/besselj(1,U);\nHy0(kv) = cosphi(kv).*besselj(1,U*rho(kv)./r)/besselj(1,U);\nkv = find(rho >= r);\nHx0(kv) = -sinphi(kv).*besselk(1,W*rho(kv)./r)/besselk(1,W);\nHy0(kv) = cosphi(kv).*besselk(1,W*rho(kv)./r)/besselk(1,W);\n[hmax,kv] = max(abs(Hx0(:)));\nhmax = Hx0(kv);\nHx0 = Hx0/hmax;\nHy0 = Hy0/hmax;\n\nfigure(1);\n\nsubplot(221);\ncontourmode(x,y,Hx);\ntitle('Hx (finite difference)');\n\nsubplot(222);\ncontourmode(x,y,Hy);\ntitle('Hy (finite difference)');\n\nsubplot(223);\ncontourmode(x,y,Hx0);\ntitle('Hx (exact)');\n\nsubplot(224);\ncontourmode(x,y,Hy0);\ntitle('Hy (exact)');\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/12734-waveguide-mode-solver/examples/fiber_tm_mode.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.953966093674472, "lm_q2_score": 0.8840392756357327, "lm_q1q2_score": 0.8433434944330298}} {"text": "function root = BesselJ_RootsCyl(starts)\n% BesselJ_RootsCyl(starts) finds the roots of the equation J'_1(x) = 0\n% where J_1 is the first order Bessel function of the first kind.\n%\n% starts is the number of starting points in the search for\n% roots. The larger it is, the more roots are returned in the root array.\n% The default is 20, which returns 6 roots. starts = 100 returns 32 roots.\n% Generally the number of roots is just under 1/3 the number of starting\n% points.\n%\n% author: Daniel C Alexander (d.alexander@ucl.ac.uk)\n%\n\nif(nargin==0)\n starts = 20;\nend\n\nf = @(x)(0.5*(besselj(0,x) - besselj(2,x)));\n\n% Get a good list of starting points\ny = 0:0.1:starts;\ndj1 = f(y);\nstarts = (find(dj1(1:end-1).*dj1(2:end)<0)+1)*0.1;\n\nfor s=1:length(starts)\n root(s) = fzero(f,starts(s));\nend\n\n\n\n\n", "meta": {"author": "qMRLab", "repo": "qMRLab", "sha": "036ff20b47e939877f746940a969494b55911636", "save_path": "github-repos/MATLAB/qMRLab-qMRLab", "path": "github-repos/MATLAB/qMRLab-qMRLab/qMRLab-036ff20b47e939877f746940a969494b55911636/External/NODDI_toolbox_v1.0/models/BesselJ_RootsCyl.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542829224748, "lm_q2_score": 0.8791467785920306, "lm_q1q2_score": 0.8432373980040428}} {"text": "function [J, grad] = costFunction(theta, X, y)\n %COSTFUNCTION Compute cost and gradient for logistic regression\n % J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the\n % parameter for logistic regression and the gradient of the cost\n % w.r.t. to the parameters.\n\n % Initialize some useful values\n n = length(y); % number of training examples\n \n % cost: J\n J = -1/n * sum(...\n y .* log(sigmoid(X * theta)) + ...\n (1 - y) .* log(1 - sigmoid(X * theta)) ...\n );\n\n % gradient: compute as the derivative of the cost function\n grad = 1/n * X' * ((sigmoid(X * theta)) - y);\n\nend\n", "meta": {"author": "worldveil", "repo": "coursera-ml", "sha": "94e205b01ec3a47c0d777943194d12fa130f4685", "save_path": "github-repos/MATLAB/worldveil-coursera-ml", "path": "github-repos/MATLAB/worldveil-coursera-ml/coursera-ml-94e205b01ec3a47c0d777943194d12fa130f4685/logistic/code/costFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9553191348157373, "lm_q2_score": 0.8824278540866548, "lm_q1q2_score": 0.8430002141033707}} {"text": "function [R,s]=rotmat2vec(u,v)\n%\n% [R,s]=rotmat2vec(u,v)\n%\n% the rotation matrix from vector u to v, satisfying R*u*s=v\n%\n% author: Bruno Luong\n% URL:http://www.mathworks.com/matlabcentral/newsreader/view_original/827969\n%\n% input: \n% u: a 3D vector in the source coordinate system;\n% v: a 3D vector in the target coordinate system;\n%\n% output:\n% R: a rotation matrix to transform normalized u to normalized v\n% s: a scaling factor, so that R*u(:)*s=v(:)\n%\n% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)\n%\n\ns=norm(v(:))/norm(u(:));\nu1=u(:)/norm(u(:));\nv1=v(:)/norm(v(:));\n\nk = cross(u1,v1);\nif(~any(k)) % u and v are parallel\n R=eye(3);\n return;\nend\n% Rodrigues's formula:\ncostheta = dot(u1,v1);\nR =[ 0 -k(3) k(2);\n k(3) 0 -k(1);\n -k(2) k(1) 0];\nR = costheta*eye(3) + R + k*k'*(1-costheta)/sum(k.^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/iso2mesh/rotmat2vec.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.8976952941600964, "lm_q1q2_score": 0.8429581612370568}} {"text": "function xval = r8vec_even_select ( n, xlo, xhi, ival )\n\n%*****************************************************************************80\n%\n%% R8VEC_EVEN_SELECT returns the I-th of N evenly spaced values in [ XLO, XHI ].\n%\n% Discussion:\n%\n% XVAL = ( (N-IVAL) * XLO + (IVAL-1) * XHI ) / dble ( N - 1 )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 29 November 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of values.\n%\n% Input, real XLO, XHI, the low and high values.\n%\n% Input, integer IVAL, the index of the desired point.\n% IVAL is normally between 1 and N, but may be any\n% integer value.\n%\n% Output, real XVAL, the IVAL-th of N evenly spaced values\n% between XLO and XHI.\n%\n% Unless N = 1, X(1) = XLO and X(N) = XHI.\n%\n% If N = 1, then X(1) = 0.5*(XLO+XHI).\n%\n if ( n == 1 )\n\n xval = 0.5 * ( xlo + xhi );\n\n else\n\n xval = ( ( n - ival ) * xlo ...\n + ( ival - 1 ) * xhi ) ...\n / ( n - 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/r8lib/r8vec_even_select.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222396, "lm_q2_score": 0.8976952880018481, "lm_q1q2_score": 0.8429581523906582}} {"text": "function volume = sphere_cap_volume_nd ( dim_num, r, h )\n\n%*****************************************************************************80\n%\n%% SPHERE_CAP_VOLUME_ND computes the volume of a spherical cap in ND.\n%\n% Discussion:\n%\n% The spherical cap is a portion of the surface and interior of the sphere:\n%\n% sum ( X(1:N)^2 ) <= R * R\n%\n% which is no more than H units from some point P on the sphere.\n%\n%\n% The algorithm proceeds from the observation that the N-dimensional\n% sphere can be parameterized by a quantity RC that runs along the\n% radius from the center to the point P. The value of RC at the\n% base of the spherical cap is (R-H) and at P it is R. We intend to\n% use RC as our integration parameeter.\n%\n% The volume of the spherical cap is then the integral, as RC goes\n% from (R-H) to R, of the N-1 dimensional volume of the sphere\n% of radius RS, where RC * RC + RS * RS = R * R.\n%\n% The volume of the N-1 dimensional sphere of radius RS is simply \n% some constants times RS**(N-1).\n% \n% After factoring out the constant terms, and writing RC = R * cos ( T ),\n% and RS = R * sin ( T ), and letting \n% T_MAX = arc_sine ( sqrt ( ( 2.0 * r - h ) * h / r ) ),\n% the \"interesting part\" of our integral becomes\n%\n% constants * R^N * Integral ( T = 0 to T_MAX ) sin^N ( T ) dT\n%\n% The integral of sin^N ( T ) dT can be handled by recursion.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 02 April 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the dimension of the space.\n%\n% Input, real R, the radius of the sphere.\n%\n% Input, real H, the \"thickness\" of the spherical cap,\n% which is normally between 0 and 2 * R.\n%\n% Output, real VOLUME, the volume of the spherical cap.\n%\n if ( h <= 0.0 )\n volume = 0.0;\n return\n end\n\n if ( 2.0 * r <= h )\n volume = sphere_volume_nd ( dim_num, r );\n return\n end\n\n if ( dim_num < 1 )\n\n volume = -1.0;\n\n elseif ( dim_num == 1 )\n\n volume = h;\n\n else\n\n factor1 = sphere_unit_volume_nd ( dim_num - 1 );\n\n angle = r8_asin ( sqrt ( ( 2.0 * r - h ) * h / r ) );\n\n factor2 = sin_power_int ( 0.0, angle, dim_num );\n\n volume = factor1 * factor2 * r^dim_num;\n\n if ( r < h )\n volume2 = sphere_volume_nd ( dim_num, r );\n volume = volume2 - volume;\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/stroud/sphere_cap_volume_nd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947132556618, "lm_q2_score": 0.8918110353738529, "lm_q1q2_score": 0.842756713651349}} {"text": "function k=FibonacciNumInv(n,choice)\n%FIBONACCINUMINV Given a real number >=1, determine the k such that\n% n==FibonacciNum(k). If n given is not a Fibonacci number,\n% then the behaviour is determined by the choice option.\n%\n%INPUTS: n A scalar or matrix of values for which the argument of\n% FibonacciNum is desired, n>=1.\n% choice An optional parameter that determines what is returned if n\n% is not an exact Fibonacci number. If this parameter is omitted,\n% then the default is one (the next lower value).\n% 0 means return the closest value.\n% 1 means return the next lower value.\n% 2 means return the next higher value. \n%\n%OUTPUTS: k The argument of FibonacciNum that gives n, or an appropriately\n% close value selected by the choice option. k will always be\n% >=2.\n%\n%A non-recursive expression for Fibonacci numbers is given in [1] and can\n%be inverted. However, due to finite prevision issues, for n in the mid\n%70's the value returned can be off. Thus, testing needs to be done for all\n%inputs in the choice option to make sure that the proper value is chosen.\n%\n%REFERENCES:\n%[1] Chandra, Pravin and Weisstein, Eric W. \"Fibonacci Number.\" From\n% MathWorld--A Wolfram Web Resource.\n% http://mathworld.wolfram.com/FibonacciNumber.html\n%\n%November 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n if(nargin<2||isempty(choice))\n choice=1; \n end\n\n %The golden ratio.\n phi=(1+sqrt(5))/2;\n k=fix(log(n*sqrt(5))/log(phi)+(1/2));\n \n %Due to finite precision errors, even if n is a Fibonacci number, k\n %might be the correct value, it might be 1 less or it might be 1 too\n %much. We will adjust k to deal with the situation. Note that from\n %above, k>=2, so there are no issues with k-1 being <1.\n switch(choice)\n case 0%Return the closest value\n valsLower=FibonacciNum(k-1);\n valsCur=FibonacciNum(k);\n valsUpper=FibonacciNum(k+1);\n\n diffLower=abs(n-valsLower);\n diffCur=abs(n-valsCur);\n diffUpper=abs(n-valsUpper);\n\n sel=(diffLowern;\n k(sel)=k(sel)-1;\n case 2%Return the next higher value.\n valsCur=FibonacciNum(k);\n sel=valsCur= 0.\n%\n% where G(a) is the complete gamma function.\n%\n% The complementary cumulative distribution function is\n% inf\n% G(v,a) = b/(2 G(a)) Int exp(-b|x|) (b|x|)^(a-1) dx.\n% v\n% To develop this formula, we start from the one-sided gamma PDF\n%\n% G(x,a) = 1/G(a) exp(-x) x^(a-1), for x >= 0,\n% = 0, for x < 0.\n% We now make the PDF two-sided\n% Gamma2PDF(x,a) = 1/2 GammaPDF(|x|,a).\n% This is a zero-mean (symmetric) distribution. Its variance can be\n% calculated integrating the product of t^2 and Gamma2PDF(x,a). But\n% multiplying the PDF by t^2 is the same as replacing the exponent a-1\n% by a+1. Then the variance is\n% Var(Gamma2PDF(x,a) = G(a+2)/G(a) = a(a+1),\n% since G(a+1) = a G(a).\n%\n% Let the standard deviation be denoted as b = sqrt(a(a+1)). Then scaling\n% x by b and scaling the result, gives the unit-variance generalized gamma\n% density shown above. The complementary cumulative distribution function\n% is then (for v >= 0),\n% inf\n% G(v,a) = b/(2 G(a)) Int exp(-b|x|) (b|x|)^(a-1) dx \n% v\n% inf\n% = 1/(2 G(a)) Int exp(-u) u^(a-1) du\n% bv\n% = 1/2 Gamma1aCCDF(bv,a).\n\n% Moments\n% Let p(x,a1) be the generalized gamma distribution with parameter a1.\n% F0(x,a1) = Int(x,Inf) p(x,a1) dx\n% The moment integrals are\n% Fn(x,a1) = Int(x,Inf) x^n p(x,a1) dx\n% = G(a2)/(G(a1) b1^n) F0(b1 x/b2, a2) n even\n% = G(a2)/(G(a1) b1^n) F0(b1 abs(x)/b2, a2), n odd\n% where a2=a1+n, b1=sqrt(b1(b1+1)), and b2=sqrt(a2(a2+1)). Note that the\n% generalized gamma PDF uses abs(x). So for odd moments (n odd), we have to\n% compensate by changing the sign of the argument.\n\n% Gaussian\n% The Gaussian complementary cumulative distribution function can be\n% computed from the generalized gamma distribution. Consider the moments\n% of the Gaussian distribution\n% Fn(u) = 1/sqrt(2pi) Int u^n e^(-u^2/2) du\n% Consider u positive. Substitute x = u^2/(2b) with u = sqrt(2bx). Then\n% du = b/sqrt(2) 1/sqrt(bx), giving\n% Fn(x) = 1/sqrt(2pi) Int (2bx)^(n/2) e^(-bx) b/sqrt(2) 1/sqrt(bx) dx\n% = 1/sqrt(2pi) 2^(n/2)/sqrt(2) b Int (bx)^((n-1)/2) e^(-bx) dx\n% Let a = (n+1)/2,\n% Fn(x) = 2^(n/2) G(a)/sqrt(pi) b/(2G(a)) Int exp(-bx) (bx)^(a-1) dx\n% = 2^(n/2) G(a)/sqrt(pi) G(x,a) with x>0 and b=sqrt(a(a+1)).\n%\n% For the integral of the Gaussian, n=0, a=1/2, b=sqrt(3)/2), and\n% G(a)=sqrt(pi))\n% F0(x) = G(x,1/2)\n% or\n% F0(u) = G(sgn(x) x^2/(2b),1/2).\n% The sgn() function compensates for the loss of sign information in\n% squaring x.\n%\n% The Gaussian first moment is given by n=1, a=1, b=sqrt(2), and\n% G(a)=sqrt(2),\n% F1(u) = sqrt(2/pi) G(x^2/(2b), 1)\n% The sgn() function is not necessary since the integrand is odd.\n%\n% The Gaussian second moment is given by n=2, a=3/2, b=sqrt(3)/2, and\n% G(a)=sqrt(pi)/2,\n% F2(u) = G(sgn(x) x^2/(2b), 3/2)\n\nb = sqrt(a*(a+1));\nif (v >= 0)\n P = (1/2) * Gamma1aCCDF(b*v, a);\nelse\n P = 1 - (1/2) * Gamma1aCCDF(-b*v, a);\nend\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/24333-quantizers/Quantizer/private/Gamma2aCCDF.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475699138558, "lm_q2_score": 0.8933094131553264, "lm_q1q2_score": 0.8427012640812498}} {"text": "function fx = p57_fun ( n, x )\n\n%*****************************************************************************80\n%\n%% P57_FUN evaluates the integrand for problem 57.\n%\n% Interval:\n%\n% 0 <= x <= 1\n%\n% Integrand:\n%\n% x^(3/2)\n%\n% Antiderivative:\n%\n% (2/5) * x^(5/2)\n%\n% Exact Integral:\n%\n% 0.4\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% David Kahaner,\n% Comparison of Numerical Quadrature Formulas,\n% in Mathematical Software, edited by John R Rice,\n% Academic Press, 1971.\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(1:n) = sqrt ( x(1:n).^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/p57_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632956467158, "lm_q2_score": 0.9086178919837705, "lm_q1q2_score": 0.842618882793641}} {"text": "function frf=dfracft(f,a,varargin)\n%DFRACFT Discrete Fractional Fourier transform\n% Usage: V=dfracft(f,a,p);\n% V=dfracft(f,a);\n%\n% `dfracft(f,a)` computes the discrete fractional Fourier Transform of the\n% signal *f* to the power *a*. For *a=1* it corresponds to the ordinary\n% discrete Fourier Transform. If *f* is multi-dimensional, the\n% transformation is applied along the first non-singleton dimension.\n%\n% `dfracft(f,a,dim)` does the same along dimension *dim*. \n%\n% `dfracft(f,a,[],p)` or `dfracft(f,a,dim,p)` allows to choose the order\n% of approximation of the second difference operator (default: *p=2*).\n%\n% See also: ffracft, dft, hermbasis, pherm\n%\n% References: ozzaku01,buma04\n\n% AUTHOR : Christoph Wiesmeyr \n% TESTING: TEST_HERMBASIS\n% REFERENCE: OK\n\nif nargin<2\n error('%s: Too few input parameters.',upper(mfilename));\nend;\n\ndefinput.keyvals.p = 2;\ndefinput.keyvals.dim = [];\n[flags,keyvals,dim,p]=ltfatarghelper({'dim','p'},definput,varargin);\n\n[f,L,Ls,W,dim,permutedsize,order]=assert_sigreshape_pre(f,[],dim,upper(mfilename));\n\nH = hermbasis(L,p);\n\n% set up the eigenvalues\nk=0:L-1;\nlam = exp(-1i*k*a*pi/2);\nlam=lam(:);\n\n% correction for even signal lengths\nif ~rem(L,2)\n lam(end)=exp(-1i*L*a*pi/2);\nend\n\n% shuffle the eigenvalues in the right order\neven=~mod(L,2);\ncor=2*floor(L/4)+1;\nfor k=(cor+1):2:(L-even)\n lam([k,k+1])=lam([k+1,k]);\nend\n\nfrf =H*(bsxfun(@times,lam,H'*f));\n\nfrf=assert_sigreshape_post(frf,dim,permutedsize,order);\n\n\n\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/fourier/dfracft.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541610257063, "lm_q2_score": 0.8947894590884704, "lm_q1q2_score": 0.8425822173925992}} {"text": "function g = sigmoid(z)\n%SIGMOID Compute sigmoid functoon\n% J = SIGMOID(z) computes the sigmoid of z.\n\n% You need to return the following variables correctly \ng = zeros(size(z));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the sigmoid of each value of z (z can be a matrix,\n% vector or scalar).\n\n%g = 1 ./ (1 .+ e .^ -z);\ng = 1.0 ./ (1.0 + exp(-z));%exp(n)-->e的n次方\n\n\n\n% =============================================================\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-ex2/ex2/sigmoid.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.9184802501617068, "lm_q1q2_score": 0.8425243824796791}} {"text": "function [val table]= muller(strEqn,strVar,p0,p1,p2,tol,n)\n%MULLER uses the Muller's method to solve for a root of f(x)\n%\n% Find a solution to f(x) = 0 given three approximations p0, p1\n% and p2 (Note that Muller's method may return complex roots)\n%\n%\n% INPUT:\n% strEqn: is the string representation of the equation f(x)\n% strVar: is the varialbe in strEqn\n% p0, p1, p2: initial guesses at the solution\n% tol: is the solution tolerence\n% n: is the maximum number of iterations of the algorithum.\n%\n% OUTPUT: val: is the approximate solution (can be complex)\n% table: is the iteration table\n%\n%\n% USAGE: val = muller(strEqn,strVar,x0,x1,x2,tol,n)\n% [val table] = muller(...) to display a table of the iterations\n% val = muller('x^3+2*x^2-5','x',0,1,2,10^-4,100)\n%\n% BY: Jonathan Lister (jlister1@utk.edu)\n\n%% Additonal Examples\n% \n% strEqn = '16*x^4-40*x^3+5*x^2+20*x+6';\n% strVar = 'x';\n% tol = 10^-5;\n% \n% disp('p0 = 0.5, p1 = -0.5, p2 = 0.0')\n% [root1 table1]= muller(strEqn,strVar,0.5,-0.5,0,tol,100)\n% \n% disp('p0 = 0.5, p1 = 1.0, p2 = 1.5')\n% [root2 table2]= muller(strEqn,strVar,0.5,1.0,1.5,tol,100)\n% \n% disp('p0 = 2.5, p1 = 2.0, p2 = 2.25')\n% [root3 table3]= muller(strEqn,strVar,2.5,2.0,2.25,tol,100)\n%\n\n%% Input Error Checking\nif nargin < 7\n error('Incorrect number of input arguments type \"help muller\"')\nend\n\nif tol < 0\n error('tolerance must be a positive number')\nend\n\nif ~ischar(strEqn)\n error('Input 1 Error, a string of the equation of interest is required')\nend\n\nif ~ischar(strVar)\n error('Input 3 Error, a string representation of the variable is required')\nend\n\n%parse equation\nF = vectorize(inline(strEqn,strVar));\n\n%intitialize output variables\nval = [];\ntable ={};\n\n%% Algorithm 2.8 from text.\n%Step 1\nh1 = p1 - p0;\nh2 = p2 - p1;\ndel1 = (F(p1)-F(p0))./h1;\ndel2 = (F(p2)-F(p1))./h2;\nd = (del2-del1)./(h2+h1);\nI = 3;\n\n%Step 2\nwhile I <= n\n %Step 3\n b = del2+h2.*d;\n D = sqrt(b.^2-4.*F(p2).*d); % could be complex\n %Step 4\n if abs(b - D) < abs(b + D)\n E = b + D;\n else\n E = b - D;\n end\n %Step 5\n h = -2.*F(p2)./E;\n p = p2 + h;\n \n if I == 3\n table{1} = 'Muller''s Method Iterations';\n table{2}=' I P f(P) ';\n table{3}='-----------------------------------------------------';\n end\n str = sprintf('%3u: % 6.6f + %6.6fi % 6.6f + %6.6fi',I,real(p),imag(p),real(F(p)),imag(F(p)));\n table{I + 1} = str; %#ok<*AGROW> \n \n %Step 6\n if abs(h) < tol\n val = p;\n table = char(table);\n break\n end\n p0 = p1;\n p1 = p2;\n p2 = p;\n h1 = p1 - p0;\n h2 = p2 - p1;\n del1 = (F(p1)-F(p0))./h1;\n del2 = (F(p2)-F(p1))./h2;\n d = (del2-del1)./(h2+h1);\n I = I + 1;\nend\n\nif isempty(val)\n disp('The procedure was unsuccessful.')\n table = char(table); \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/28833-numerical-analysis-functions-1/muller.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.9161096164524095, "lm_q1q2_score": 0.8424933624753386}} {"text": "function h = gaussianKernel3D( r, sigma)\n%Create pre-defined 3-D Gaussian kernel.\n% \n% Description :\n%\n% h = gaussianKernel3D(r,sigma) returns a rotationally symmetric Gaussian\n% kernel h of size 2*r+1 with standard deviation sigma (positive). The \n% default size of r is 1 and the default sigma is 0.5.\n%\n% Author : Mohammad Mustafa\n% By courtesy of University of Nottingham and Mirada Medical Limited,\n% Oxford, UK\n%\n% Published under a Creative Commons Attribution-Non-Commercial-Share Alike\n% 3.0 Unported Licence http://creativecommons.org/licenses/by-nc-sa/3.0/\n% \n% June 2012\n\n\n if nargin<1\n r=1; sigma=0.5;\n elseif nargin==1\n sigma=0.5;\n end\n [x,y,z] = ndgrid(-r:r,-r:r,-r:r);\n arg = -(x.*x + y.*y + z.*z)/(2*sigma*sigma);\n\n h = exp(arg);\n \n if sum(h(:)) ~= 0,\n h = h/sum(h(:));\n end;\n\n\nend\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/37053-horn-schunck-optical-flow-method-for-3-d-images/HS3D/gaussianKernel3D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.951142215838086, "lm_q2_score": 0.8856314768368161, "lm_q1q2_score": 0.8423614852945258}} {"text": "function varargout = beale(X)\n% Beale funcion \n%\n% BEALE([x1, x2]) returns the value of the value of the Beale\n% function at the specified points. [x1] and [x2] may be vectors.\n% The search domain is\n%\n% -4.5 < x_i < 4.5\n%\n% The global minimum is \n%\n% f(x1, x2) = f(3, 0.5) = 0.\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} = [-4.5, -4.5]; % LB\n varargout{3} = [+4.5, +4.5]; % UB\n varargout{4} = [3, 0.5]; % solution\n varargout{5} = 0; % function value at solution\n\n % otherwise, output function value\n else\n \n % keep values in the serach interval\n X(X < -4.5) = inf; X(X > 4.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} = (1.5 - x1 + x1.*x2).^2 + (2.25 - x1 + x1.*x2.^2).^2 + (2.625 - x1 + x1.*x2.^3).^2;\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/beale.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422186079557, "lm_q2_score": 0.8856314647623016, "lm_q1q2_score": 0.842361476263029}} {"text": "function val=superfactorial(n)\n%%SUPERFACTORIAL Evaluate the superfactorial of a nonnegative real integer.\n% This is factorial(1)*factorial(2)*...factorial(n).\n%\n%INPUTS: n A scalar or matrix of real integers >=0.\n%\n%OUTPUTS: val A matrix having the same dimensions as n holding the\n% superfactorial of the values in n.\n%\n%The superfactorial is defined in [1]. For values 18 and below, the value\n%is taken from a tabel. For higher values, the value is computed from the\n%definition starting from the value at 18, maintaining the current\n%factorial value at each step. Values 27 and higher overflow with double\n%precision arithmetic.\n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Superfactorial.\" From MathWorld--A Wolfram Web\n% Resource. http://mathworld.wolfram.com/Superfactorial.html\n%\n%September 2017 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n%A table of values for 0<=n<=18\nvalTable=[1;\n 1;\n 2;\n 12;\n 288;\n 34560;\n 24883200;\n 125411328000;\n 5056584744960000;\n 1834933472251084800000;\n 6658606584104736522240000000;\n 265790267296391946810949632000000000;\n 127313963299399416749559771247411200000000000;\n 792786697595796795607377086400871488552960000000000000;\n 69113789582492712943486800506462734562847413501952000000000000000;\n 90378331112371142262979521568630736335023247731599748366336000000000000000000;\n 1890966832292234727042877370627225068196418587883634153182519380410368000000000000000000000;\n 672593129192865130334217631473916658864122332882577979675277211683839238972899328000000000000000000000000;\n 4306192564997715382115598640379294845786123319603755168023536027873932927153136831171640950784000000000000000000000000000];\n\nif(any(n(:)<0)||any(n(:)~=fix(n(:)))||any(~isreal(n(:))))\n error('n must be a positive integer.') \nend\nval=zeros(size(n));\n\nnumVals=numel(n);\n\nfor curEl=1:numVals\n nCur=n(curEl);\n \n if(nCur<=18)\n val(curEl)=valTable(nCur+1);\n else\n factVal=6402373705728000;%factorial(18)\n val(curEl)=valTable(18+1);\n \n for curN=19:nCur\n %Quit if there was an overflow.\n if(~isfinite(val(curEl)))\n break;\n end\n factVal=factVal*curN;\n val(curEl)=val(curEl)*factVal;\n end\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/superfactorial.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.9073122182277757, "lm_q1q2_score": 0.842356646456913}} {"text": "function J = computeCostMulti(X, y, theta)\n%COMPUTECOSTMULTI Compute cost for linear regression with multiple variables\n% J = COMPUTECOSTMULTI(X, y, theta) computes the cost of using theta as the\n% parameter for linear regression to fit the data points in X and y\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta\n% You should set J to the cost.\n\nJ = sum((X * theta .- y) .^ 2) / (2 * m);\n\n% =========================================================================\n\nend\n", "meta": {"author": "sfvsfv", "repo": "Mathematical-modeling", "sha": "cef1a3688246851f067777b3599b1b3831d3d948", "save_path": "github-repos/MATLAB/sfvsfv-Mathematical-modeling", "path": "github-repos/MATLAB/sfvsfv-Mathematical-modeling/Mathematical-modeling-cef1a3688246851f067777b3599b1b3831d3d948/matlab吴恩达机器学习/machine-learning-ex1/ex1/computeCostMulti.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9597620550745211, "lm_q2_score": 0.8774767842777551, "lm_q1q2_score": 0.8421689217586005}} {"text": "function [centroid, area] = polygonCentroid(varargin)\n%POLYGONCENTROID Compute the centroid (center of mass) of a polygon\n%\n% CENTROID = polygonCentroid(POLY)\n% CENTROID = polygonCentroid(PTX, PTY)\n% Computes center of mass of a polygon defined by POLY. POLY is a N-by-2\n% array of double containing coordinates of vertices.\n%\n% [CENTROID AREA] = polygonCentroid(POLY)\n% Also returns the (signed) area of the polygon. \n%\n% Example\n% % Draws the centroid of a paper hen\n% x = [0 10 20 0 -10 -20 -10 -10 0];\n% y = [0 0 10 10 20 10 10 0 -10];\n% poly = [x' y'];\n% centro = polygonCentroid(poly);\n% drawPolygon(poly);\n% hold on; axis equal;\n% drawPoint(centro, 'bo');\n% \n% References\n% algo adapted from P. Bourke web page\n%\n% See also:\n% polygons2d, polygonArea, polygonSecondAreaMoments, drawPolygon\n%\n\n% ---------\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 05/05/2004.\n%\n\n% Algorithme P. Bourke, vectorized version\n\n% HISTORY\n% 2012.02.24 vectorize code\n\n\n% parse input arguments\nif nargin == 1\n var = varargin{1};\n px = var(:,1);\n py = var(:,2);\nelseif nargin == 2\n px = varargin{1};\n py = varargin{2};\nend\n\n% vertex indices\nN = length(px);\niNext = [2:N 1];\n\n% compute cross products\ncommon = px .* py(iNext) - px(iNext) .* py;\nsx = sum((px + px(iNext)) .* common);\nsy = sum((py + py(iNext)) .* common);\n\n% area and centroid\narea = sum(common) / 2;\ncentroid = [sx sy] / 6 / area;\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/polygons2d/polygonCentroid.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.93812402119614, "lm_q2_score": 0.8976952934758465, "lm_q1q2_score": 0.8421495185244102}} {"text": "function cx = legendre_associated_normalized ( n, m, x )\n\n%*****************************************************************************80\n%\n%% LEGENDRE_ASSOCIATED: normalized associated Legendre functions.\n%\n% Discussion:\n%\n% The unnormalized associated Legendre functions P_N^M(X) have\n% the property that\n%\n% Integral ( -1 <= X <= 1 ) ( P_N^M(X) )^2 dX\n% = 2 * ( N + M )! / ( ( 2 * N + 1 ) * ( N - M )! )\n%\n% By dividing the function by the square root of this term,\n% the normalized associated Legendre functions have norm 1.\n%\n% However, we plan to use these functions to build spherical\n% harmonics, so we use a slightly different normalization factor of\n%\n% sqrt ( ( ( 2 * N + 1 ) * ( N - M )! ) / ( 4 * pi * ( N + M )! ) )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 March 2005\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% Parameters:\n%\n% Input, integer N, the maximum first index of the Legendre\n% function, which must be at least 0.\n%\n% Input, integer M, the second index of the Legendre function,\n% which must be at least 0, and no greater than N.\n%\n% Input, real X, the point at which the function is to be\n% evaluated. X must satisfy -1 <= X <= 1.\n%\n% Output, real CX(1:N+1), the values of the first N+1 function.\n%\n if ( m < 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LEGENDRE_ASSOCIATED_NORMALIZED - Fatal error!\\n' );\n fprintf ( 1, ' Input value of M is %d\\n', m );\n fprintf ( 1, ' but M must be nonnegative.\\n' );\n error ( 'LEGENDRE_ASSOCIATED_NORMALIZED - Fatal error!' );\n end\n \n if ( n < m )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LEGENDRE_ASSOCIATED_NORMALIZED - Fatal error!\\n' );\n fprintf ( 1, ' Input value of M = %d\\n', m );\n fprintf ( 1, ' Input value of N = %d\\n', n );\n fprintf ( 1, ' but M must be less than or equal to N.\\n' );\n error ( 'LEGENDRE_ASSOCIATED_NORMALIZED - Fatal error!' );\n end\n \n if ( x < -1.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LEGENDRE_ASSOCIATED_NORMALIZED - Fatal error!\\n' );\n fprintf ( 1, ' Input value of X = %f\\n', x );\n fprintf ( 1, ' but X must be no less than -1.\\n' );\n error ( 'LEGENDRE_ASSOCIATED_NORMALIZED - Fatal error!' );\n end\n\n if ( 1.0 < x )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LEGENDRE_ASSOCIATED_NORMALIZED - Fatal error!\\n' );\n fprintf ( 1, ' Input value of X = %f\\n', x );\n fprintf ( 1, ' but X must be no more than 1.\\n' );\n error ( 'LEGENDRE_ASSOCIATED_NORMALIZED - Fatal error!' );\n end\n \n cx(1:m) = 0.0;\n\n cx(m+1) = 1.0;\n somx2 = sqrt ( 1.0 - x * x );\n \n fact = 1.0;\n for i = 1 : m\n cx(m+1) = -cx(m+1) * fact * somx2;\n fact = fact + 2.0;\n end\n \n if ( m < n )\n cx(m+2) = x * ( 2 * m + 1 ) * cx(m+1);\n end\n\n for i = m+2 : n\n cx(i+1) = ( ( 2 * i - 1 ) * x * cx(i) ...\n + ( - i - m + 1 ) * cx(i-1) ) ...\n / ( i - m );\n end\n%\n% Normalization.\n%\n for mm = m : n\n factor = sqrt ( ( ( 2 * mm + 1 ) * r8_factorial ( mm - m ) ) ...\n / ( 4.0 * pi * r8_factorial ( mm + m ) ) );\n cx(mm+1) = cx(mm+1) * factor;\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/spherical_harmonic/legendre_associated_normalized.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240073565739, "lm_q2_score": 0.8976952893703477, "lm_q1q2_score": 0.8421495022492298}} {"text": "function result = p00_simpson ( prob, int_num )\n\n%*****************************************************************************80\n%\n%% P00_SIMPSON applies the composite Simpson rule to integrate a function.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 30 December 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer PROB, the problem index.\n%\n% Input, integer INT_NUM, the number of subintervals.\n%\n% Output, real RESULT, the approximate integral.\n%\n [ a, b ] = p00_lim ( prob );\n\n h = ( b - a ) / ( int_num );\n%\n% This section of the code was rewritten to vectorize.\n%\n x(1:2*int_num+1) = ( ( 2*int_num - ( 0 : 2*int_num ) ) * a ...\n + ( ( 0 : 2*int_num ) ) * b ) ...\n / ( 2*int_num );\n \n if ( 1 == int_num )\n result = ...\n p00_fun ( prob, 1, x(1) ) ...\n + 4.0 * p00_fun ( prob, int_num, x(2) ) ...\n + p00_fun ( prob, 1, x(3) );\n else\n result = ...\n p00_fun ( prob, 1, x(1) ) ...\n + 2.0 * sum ( p00_fun ( prob, int_num - 1, x(3:2:2*int_num-1) ) ) ...\n + 4.0 * sum ( p00_fun ( prob, int_num, x(2:2:2*int_num) ) )...\n + p00_fun ( prob, 1, x(2*int_num+1) );\n end\n\n result = result * h / 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/test_int/p00_simpson.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164656, "lm_q2_score": 0.8976952818435994, "lm_q1q2_score": 0.8421494982941349}} {"text": "% Equality constrained norm minimization.\n%\n% This script constructs a random equality-constrained norm minimization\n% problem and solves it using CVX. You can also change p to +2 or +Inf\n% to produce different results. Alternatively, you an replace\n% norm( A * x - b, p )\n% with\n% norm_largest( A * x - b, 'largest', p )\n% for 1 <= p <= 2 * n.\n\n% Generate data\np = 1;\nn = 10; m = 2*n; q=0.5*n;\nA = randn(m,n);\nb = randn(m,1);\nC = randn(q,n);\nd = randn(q,1);\n\n% Create and solve problem\ncvx_begin\n variable x(n)\n dual variable y\n minimize( norm( A * x - b, p ) )\n subject to\n y : C * x == d;\ncvx_end\n\n% Display results\ndisp( sprintf( 'norm(A*x-b,%g):', p ) );\ndisp( [ ' ans = ', sprintf( '%7.4f', norm(A*x-b,p) ) ] );\ndisp( 'Optimal vector:' );\ndisp( [ ' x = [ ', sprintf( '%7.4f ', x ), ']' ] );\ndisp( 'Residual vector:' );\ndisp( [ ' A*x-b = [ ', sprintf( '%7.4f ', A*x-b ), ']' ] );\ndisp( 'Equality constraints:' );\ndisp( [ ' C*x = [ ', sprintf( '%7.4f ', C*x ), ']' ] );\ndisp( [ ' d = [ ', sprintf( '%7.4f ', d ), ']' ] );\ndisp( 'Lagrange multiplier for C*x==d:' );\ndisp( [ ' y = [ ', sprintf( '%7.4f ', y ), ']' ] );\n", "meta": {"author": "cvxr", "repo": "CVX", "sha": "a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd", "save_path": "github-repos/MATLAB/cvxr-CVX", "path": "github-repos/MATLAB/cvxr-CVX/CVX-a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd/examples/equality_constr_norm_min.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811651448431, "lm_q2_score": 0.8723473763375643, "lm_q1q2_score": 0.8421477265798047}} {"text": "% Minimize stopband ripple of a linear phase lowpass FIR filter\n% \"Filter design\" lecture notes (EE364) by S. Boyd\n% (figures are generated)\n%\n% Designs a linear phase FIR lowpass filter such that it:\n% - minimizes the maximum passband ripple\n% - has a constraint on the maximum stopband attenuation\n%\n% This is a convex problem.\n%\n% minimize delta\n% s.t. 1/delta <= H(w) <= delta for w in the passband\n% |H(w)| <= atten_level for w in the stopband\n%\n% where H is the frequency response function and variables are\n% delta and h (the filter impulse response).\n%\n% Written for CVX by Almir Mutapcic 02/02/06\n\n%********************************************************************\n% user's filter specifications\n%********************************************************************\n% filter order is 2n+1 (symmetric around the half-point)\nn = 10;\n\nwpass = 0.12*pi; % passband cutoff freq (in radians)\nwstop = 0.24*pi; % stopband start freq (in radians)\natten_level = -30; % stopband attenuation level in dB\n\n%********************************************************************\n% create optimization parameters\n%********************************************************************\nN = 30*n+1; % freq samples (rule-of-thumb)\nw = linspace(0,pi,N);\nA = [ones(N,1) 2*cos(kron(w',[1:n]))]; % matrix of cosines\n\n% passband 0 <= w <= w_pass\nind = find((0 <= w) & (w <= wpass)); % passband\nAp = A(ind,:);\n\n% transition band is not constrained (w_pass <= w <= w_stop)\n\n% stopband (w_stop <= w)\nind = find((wstop <= w) & (w <= pi)); % stopband\nUs = 10^(atten_level/20)*ones(length(ind),1);\nAs = A(ind,:);\n\n%********************************************************************\n% optimization\n%********************************************************************\n% formulate and solve the linear-phase lowpass filter design\ncvx_begin\n variable delta\n variable h(n+1,1);\n\n minimize( delta )\n subject to\n % passband bounds\n Ap*h <= delta;\n inv_pos(Ap*h) <= delta;\n\n % stopband bounds\n abs( As*h ) <= Us;\ncvx_end\n\n% check if problem was successfully solved\ndisp(['Problem is ' cvx_status])\nif ~strfind(cvx_status,'Solved')\n return\nelse\n % construct the full impulse response\n h = [flipud(h(2:end)); h];\n fprintf(1,'The optimal minimum passband ripple is %4.3f dB.\\n\\n',...\n 20*log10(delta));\nend\n\n%********************************************************************\n% plots\n%********************************************************************\nfigure(1)\n% FIR impulse response\nplot([0:2*n],h','o',[0:2*n],h','b:')\nxlabel('t'), ylabel('h(t)')\n\nfigure(2)\n% frequency response\nH = exp(-j*kron(w',[0:2*n]))*h;\n% magnitude\nsubplot(2,1,1)\nplot(w,20*log10(abs(H)),[wstop pi],[atten_level atten_level],'r--');\naxis([0,pi,-40,10])\nxlabel('w'), ylabel('mag H(w) in dB')\n% phase\nsubplot(2,1,2)\nplot(w,angle(H))\naxis([0,pi,-pi,pi])\nxlabel('w'), ylabel('phase H(w)')\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/fir_lin_phase_lowpass_min_ripple.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741322079104, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.842112960377703}} {"text": "function fx = camel ( n, x )\n\n%*****************************************************************************80\n%\n%% CAMEL evaluates the six-hump camel back function.\n%\n% Discussion:\n%\n% This function has been modified from its original definition by\n% multiplying by -1 and then adding 1, so that there is a small island\n% of positivity within the box [-2.5,2.5]x[-2.5,2.5].\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 27 December 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of points.\n%\n% Input, real X(N,2), the point coordinates.\n%\n% Output, real FX(N), the function values.\n%\n fx = zeros ( n, 1 );\n\n fx = - ...\n ( ...\n ( 4 - 2.1 * x(:,1).^2 + 0.33 * x(:,1).^4 ) .* x(:,1).^2 ...\n + x(:,1) .* x(:,2) + 4 * ( x(:,2).^2 - 1 ) .* x(:,2).^2 ...\n ) + ones ( 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/shoreline/camel.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741214369554, "lm_q2_score": 0.8840392893839085, "lm_q1q2_score": 0.8421129494006271}} {"text": "function [ vX ] = LevinsonRecursion( mT, vY )\n% ----------------------------------------------------------------------------------------------------- %\n%[ vX ] = LevinsonRecursion( mT, vY )\n% Solves Linear System mT * vX = vY where the Matrix 'mT' is a Toeplitz\n% Matrix using Levinson Recursion improved speed (Complexity of N^2 instead\n% of N^3). Input:\n% - mT - Input Matrix.\n% Matrix with a Toeplitz Structure.\n% Structure: Matrix (N x N).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - vY - Input Vector.\n% Structure: Column Vector (N x 1).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% Output:\n% - vX - Output Vector.\n% The solution of the system mT * vX = vY.\n% Structure: Column Vector (N x 1).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% References\n% 1. Levinson Recursion (Wikipedia) - https://en.wikipedia.org/wiki/Levinson_recursion\n% Remarks:\n% 1. Joint work with Yair Shemer.\n% 2. This implementation supports only rectangular matrices.\n% TODO:\n% 1. A\n% Release Notes:\n% - 1.0.000 15/02/2017 Royi Avital\n% * First realease version.\n% ----------------------------------------------------------------------------------------------------- %\n\nnumRows = size(mT, 1); % 2\n plot(0:Nb_receivers-1,criterion_value);\n grid;\n hold on\n plot(nb_sources,criterion_value_min,'ro');\n hold off\n ylabel('Criterion value')\n xlabel('Number of sources')\nend \n\n%Created by: Vincent Choqueuse, PhD (vincent.choqueuse@gmail.com)\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/22990-blind-detection-of-the-number-of-sources-with-information-criteria/source_number_detection_IC.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012732322216, "lm_q2_score": 0.8902942304882371, "lm_q1q2_score": 0.8420414167470757}} {"text": "function par = parametrize(varargin)\n%PARAMETRIZE Parametrization of a polyline, based on edges lengths.\n%\n% PAR = parametrize(POLY);\n% Returns a parametrization of the curve defined by the serie of points,\n% based on euclidean distance between two consecutive points. \n% POLY is a N-by-2 array, representing coordinates of vertices. The\n% result PAR is N-by-1, and contains the cumulative length of edges until\n% corresponding vertex.\n%\n% PAR = parametrize(PX, PY);\n% is the same, but specify points coordinates in separate column vectors.\n%\n% PAR = parametrize(..., 'normalize', 1);\n% PAR = parametrize(..., 'normalize', true);\n% Rescales the result such that the last element of PAR is 1.\n% \n% Example\n% % Parametrize a circle approximation\n% poly = circleToPolygon([0 0 1], 200);\n% p = parametrize(poly);\n% p(end)\n% ans = \n% 6.2829\n%\n% See also \n% polygons2d, polylineLength\n\n% ------\n% Author: David Legland \n% E-mail: david.legland@inrae.fr\n% Created: 2003-04-06\n% Copyright 2003-2022 INRA - TPV URPOI - BIA IMASTE\n\n%% Process inputs\n\n% extract vertex coordinates\nif size(varargin{1}, 2) > 1\n % vertices in a single array\n pts = varargin{1};\n varargin(1) = [];\n \nelseif length(varargin) == 2\n % points as separate arrays\n pts = [varargin{1} varargin{2}];\n varargin(1:2) = [];\n \nend\n\n% by default, do not normalize\nnormalize = false;\n\n% extract options\nwhile length(varargin) > 1\n param = varargin{1};\n switch lower(param)\n case 'normalize'\n normalize = varargin{2};\n otherwise\n error('Unknown parameter name: %s', param);\n end\n varargin(1:2) = [];\nend\n\n\n%% Parametrize polyline\n\n% compute cumulative sum of euclidean distances between consecutive\n% vertices, setting distance of first vertex to 0.\nif size(pts, 2) == 2\n % process points in 2D\n par = [0 ; cumsum(hypot(diff(pts(:,1)), diff(pts(:,2))))];\nelse\n % process points in arbitrary dimension\n par = [0 ; cumsum(sqrt(sum(diff(pts).^2, 2)))];\nend\n\n% eventually rescale between 0 and 1\nif normalize\n par = par / par(end);\nend\n\n", "meta": {"author": "mattools", "repo": "matGeom", "sha": "1fd2c937064be1ee1f4fd09fbfdf96145ebe5271", "save_path": "github-repos/MATLAB/mattools-matGeom", "path": "github-repos/MATLAB/mattools-matGeom/matGeom-1fd2c937064be1ee1f4fd09fbfdf96145ebe5271/matGeom/polygons2d/parametrize.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768557238083, "lm_q2_score": 0.8918110368115781, "lm_q1q2_score": 0.8420273406365453}} {"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% Discussion:\n%\n% If the triangle's vertices are given in counterclockwise order,\n% the area will be positive. If the triangle's vertices are given\n% in clockwise order, the area will be negative!\n%\n% An earlier version of this routine always returned the absolute\n% value of the computed area. I am convinced now that that is\n% a less useful result! For instance, by returning the signed \n% area of a triangle, it is possible to easily compute the area \n% of a nonconvex polygon as the sum of the (possibly negative) \n% areas of triangles formed by node 1 and successive pairs of vertices.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 17 October 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 area of the triangle.\n%\n area = 0.5 * ( ...\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/geometry/triangle_area_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.8947894724152068, "lm_q1q2_score": 0.8418087663637559}} {"text": "function [U, S] = pca(X)\n%PCA Run principal component analysis on the dataset X\n% [U, S, X] = pca(X) computes eigenvectors of the covariance matrix of X\n% Returns the eigenvectors U, the eigenvalues (on diagonal) in S\n%\n\n% Useful values\n[m, n] = size(X);\n\n% You need to return the following variables correctly.\nU = zeros(n);\nS = zeros(n);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: You should first compute the covariance matrix. Then, you\n% should use the \"svd\" function to compute the eigenvectors\n% and eigenvalues of the covariance matrix. \n%\n% Note: When computing the covariance matrix, remember to divide by m (the\n% number of examples).\n%\n\nSigma = (X'*X) ./ m;\n[U, S, V] = svd(Sigma);\n\n\n% =========================================================================\n\nend\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/ex7/pca.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897558991953, "lm_q2_score": 0.8947894618940992, "lm_q1q2_score": 0.841808759436522}} {"text": "function value = angle_rad_nd ( dim_num, v1, v2 )\n\n%*****************************************************************************80\n%\n%% ANGLE_RAD_ND returns the angle in radians between two rays in ND.\n%\n% Discussion:\n%\n% This routine always computes the SMALLER of the two angles between\n% two rays. Thus, if the rays make an (exterior) angle of 1.5 PI,\n% then the (interior) angle of 0.5 PI is reported.\n%\n% X dot Y = Norm(X) * Norm(Y) * Cos( Angle(X,Y) )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 04 March 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the spatial dimension.\n%\n% Input, real V1(DIM_NUM), V2(DIM_NUM), the two rays.\n%\n% Output, real ANGLE_RAD_ND, the angle between the rays,\n% in radians. This value will always be between 0 and PI.\n%\n dot = v1(1:dim_num) * v2(1:dim_num)';\n\n v1norm = sqrt ( sum ( v1(1:dim_num).^2 ) );\n\n if ( v1norm == 0.0 )\n value = 0.0;\n return\n end\n\n v2norm = sqrt ( sum ( v2(1:dim_num).^2 ) );\n\n if ( v2norm == 0.0 )\n value = 0.0;\n return\n end\n\n value = r8_acos ( dot / ( v1norm * v2norm ) );\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_rad_nd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478307, "lm_q2_score": 0.8962513738264114, "lm_q1q2_score": 0.8416022872655955}} {"text": "function [img, nSamples] = ellipseInterior(varargin)\n% Return an image (matrix) marking the interior of an ellipse\n%\n% Syntax\n% [img, nSamples] = ellipseInterior(varargin)\n%\n% Inputs\n% N/A\n%\n% Optional key/value pairs\n% center - Center of the ellipse\n% sigma - Sigma major and minor as a 2-vector\n% theta - Angle of sigma major from the x-axis (counter clockwise)\n%\n% Returns\n% img: 1 in the interior and 0 in the exterior\n% nSamples: Number of interior samples\n%\n% Description\n% We start with an ellipse with its major axis aligned to the\n% x-axis. We then rotate (counter clockwise) by an amount theta.\n%\n% This is the equation for the contour of the ellipse\n%\n% 1 = A*(x-h)^2 + 2B*(x-h)*(y-k) + C*(y-k)^2\n% \n% The quadratic form is Q = [A B; B C];\n% We test that the parameters are valid (i.e., Q is positive-definite\n% (i.e., Q = M*M') by \n%\n% A > 0\n% det(Q) > 0\n%\n% We convert from sigma(1), sigma(2), theta to Q and inversely using\n%\n% Q = Rotate(theta)'*[diag(a^2,b^2)]*Rotate(theta)\n%{\n% [U,S,V] = svd(Q)\n% Figure out theta from U and get a, b from sqrt(S)\n% Since\n% rotMat = [cos(theta) -sin(theta); -sin(theta) -cos(theta)];\n% theta = acos(U(1,1))\n%\n% Some experimenting\n%\n% It must be a > b for major/minor axes\na = 3; b = 2; theta = pi/6;\nrotMat = [cos(theta) -sin(theta); -sin(theta) -cos(theta)];\nQ = rotMat' * diag([a^2, b^2]) * rotMat;\n\n[U,S,V] = svd(Q);\nabs(U) - abs(rotMat) % Not sure why there can be a sign difference\nthetaEst = min(acos(U(1,1)),acos(-1*U(1,1)));\ntheta - thetaEst\n%}\n%\n% Notes:\n%\n% https://math.stackexchange.com/questions/264446/the-fastest-way-to-obtain-orientation-%CE%B8-from-this-ellipse-formula\n%\n% Wandell, January 13 2020\n% \n% See also\n% ellipsePlot()\n\n% Examples:\n%{\n img = ellipseInterior;\n mrvNewGraphWin; imagesc(img); axis equal\n%}\n%{\n samples = [-3:0.1:3];\n [img, nSamples] = ellipseInterior('center',[1 2],'spatial samples',samples);\n [img2, nSamples] = ellipseInterior('center',[0.5 2],'spatial samples',samples);\n\n % mrvNewGraphWin; imagesc(img); axis image\n % mrvNewGraphWin; imagesc(img2); axis image\n overlap = dot(img(:), img2(:))/nSamples;\n fprintf('Overlap is %f\\n',overlap);\n%}\n%{ \n samples = [-10:0.1:10];\n sigma = [3,1];\n [img, nSamples] = ellipseInterior('center',[0 0],'sigma',sigma,'spatial samples',samples);\n [img2, nSamples] = ellipseInterior('center',[-1 -4],'sigma',sigma,'spatial samples',samples);\n mrvNewGraphWin; imagesc(samples,samples,img); axis image\n mrvNewGraphWin; imagesc(samples,samples,img2); axis image\n overlap = dot(img(:), img2(:))/nSamples;\n fprintf('Overlap is %f\\n',overlap);\n%}\n%{\n img = ellipseInterior('center',[1 1],'quadratic',0.3*eye(2));\n mrvNewGraphWin; imagesc(img);\n%}\n%% Input parameters\n\nvarargin = mrvParamFormat(varargin);\n\np = inputParser;\np.addParameter('center',[0 0],@isvector);\np.addParameter('spatialsamples',(-3:0.05:3),@isvector);\nvFunc = @(x)(length(x) == 2 && x(1) >= x(2) && isnumeric(x));\np.addParameter('sigma',[1 1],vFunc); % Length in degrees\np.addParameter('theta',0,@isvector); % Radians\n\np.parse(varargin{:});\nc = p.Results.center;\nsamples = p.Results.spatialsamples;\nsigma = p.Results.sigma;\ntheta = p.Results.theta;\n\n%% Test that we have a true ellipse formula\n\nrotMat = [cos(theta) -sin(theta); -sin(theta) -cos(theta)];\nQ = rotMat' * diag([1/sigma(1)^2, 1/sigma(2)^2]) * rotMat;\nif Q(1,1) <= 0 || det(Q) <= 0 || Q(1,2) ~= Q(2,1)\n error('Q is not positive definite');\nend\n\n%% Create the spatial samples and compute the values\n\n[X,Y] = meshgrid(samples,samples);\n\nX = X - c(1);\nY = Y - c(2);\nV = Q(1,1)*X.^2 + 2*Q(1,2)*X.*Y + Q(2,2)*Y.^2;\n% mrvNewGraphWin; mesh(V)\n\n%% Binarize\nimg = zeros(size(X));\nimg(V<=1) = 1;\n\n% mrvNewGraphWin; imagesc(img)\n\nif nargout > 1\n nSamples = sum(img(:));\nend\n\nend", "meta": {"author": "vistalab", "repo": "vistasoft", "sha": "7f0102c696c091c858233340cc7e1ab02f064d4c", "save_path": "github-repos/MATLAB/vistalab-vistasoft", "path": "github-repos/MATLAB/vistalab-vistasoft/vistasoft-7f0102c696c091c858233340cc7e1ab02f064d4c/mrBOLD/Stats/ellipse/ellipseInterior.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632261523029, "lm_q2_score": 0.8840392817460332, "lm_q1q2_score": 0.8414844827681438}} {"text": "% Figure 8.10: Approximate linear discrimination via linear programming\n% Section 8.6.1, Boyd & Vandenberghe \"Convex Optimization\"\n% Original by Lieven Vandenberghe\n% Adapted for CVX by Joelle Skaf - 10/16/05\n% (a figure is generated)\n%\n% The goal is to find a function f(x) = a'*x - b that classifies the non-\n% separable points {x_1,...,x_N} and {y_1,...,y_M} by allowing some\n% misclassification. a and b can be obtained by solving the following\n% problem:\n% minimize 1'*u + 1'*v\n% s.t. a'*x_i - b >= 1 - u_i for i = 1,...,N\n% a'*y_i - b <= -(1 - v_i) for i = 1,...,M\n% u >= 0 and v >= 0\n\n% data generation\nn = 2;\nrandn('state',2);\nN = 50; M = 50;\nY = [1.5+0.9*randn(1,0.6*N), 1.5+0.7*randn(1,0.4*N);\n 2*(randn(1,0.6*N)+1), 2*(randn(1,0.4*N)-1)];\nX = [-1.5+0.9*randn(1,0.6*M), -1.5+0.7*randn(1,0.4*M);\n 2*(randn(1,0.6*M)-1), 2*(randn(1,0.4*M)+1)];\nT = [-1 1; 1 1];\nY = T*Y; X = T*X;\n\n% Solution via CVX\ncvx_begin\n variables a(n) b(1) u(N) v(M)\n minimize (ones(1,N)*u + ones(1,M)*v)\n X'*a - b >= 1 - u; %#ok\n Y'*a - b <= -(1 - v); %#ok\n u >= 0; %#ok\n v >= 0; %#ok\ncvx_end\n\n% Displaying results\nlinewidth = 0.5; % for the squares and circles\nt_min = min([X(1,:),Y(1,:)]);\nt_max = max([X(1,:),Y(1,:)]);\ntt = linspace(t_min-1,t_max+1,100);\np = -a(1)*tt/a(2) + b/a(2);\np1 = -a(1)*tt/a(2) + (b+1)/a(2);\np2 = -a(1)*tt/a(2) + (b-1)/a(2);\n\ngraph = plot(X(1,:),X(2,:), 'o', Y(1,:), Y(2,:), 'o');\nset(graph(1),'LineWidth',linewidth);\nset(graph(2),'LineWidth',linewidth);\nset(graph(2),'MarkerFaceColor',[0 0.5 0]);\nhold on;\nplot(tt,p, '-r', tt,p1, '--r', tt,p2, '--r');\naxis equal\ntitle('Approximate linear discrimination via linear programming');\n% print -deps svc-discr.eps\n\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/cvxbook/Ch08_geometric_probs/svm_1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.9005297774417915, "lm_q1q2_score": 0.8414506727012245}} {"text": "% GAUSS3D - generate a 3-dimensional gaussian matrix\n%\n% Usage:\n% >> [ gaussmatrix ] = gauss2d( nX, nY, nZ);\n% >> [ gaussmatrix ] = gauss2d( nX, nY, nZ, ...\n% sigmaX, sigmaY, sigmaZ, ...\n% centerX, centerY, centerZ, mask)\n%\n% Example:\n% >> gauss3d(3,3,3); % generate a 3x3x3 gaussian matrix\n%\n% Inputs:\n% nX - number of values in first dimension\n% nY - number of values in second dimension\n% nZ - number of values in third dimension\n% sigmaX - width of standard deviation in first dim (default: nX/5)\n% sigmaY - width of standard deviation in second dim (default: nY/5)\n% sigmaZ - width of standard deviation in third dim (default: nZ/5)\n% centerX - location of center (default: nX/2)\n% centerY - location of center (default: nY/2)\n% centerZ - location of center (default: nZ/2)\n% mask - (0->1) percentage of low values in the matrix to mask \n% with zeros (default: 0 or none)\n%\n% Output:\n% gaussmatrix - 3-D gaussian matrix\n%\n% Author: Arnaud Delorme, 2009\n\n% Copyright (C) 2009 Arnaud Delorme, Salk Institute, arno@salk.edu\n%\n% This file is part of EEGLAB, see http://www.eeglab.org\n% for the documentation and details.\n%\n% Redistribution and use in source and binary forms, with or without\n% modification, are permitted provided that the following conditions are met:\n%\n% 1. Redistributions of source code must retain the above copyright notice,\n% this list of conditions and the following disclaimer.\n%\n% 2. Redistributions in binary form must reproduce the above copyright notice,\n% this list of conditions and the following disclaimer in the documentation\n% and/or other materials provided with the distribution.\n%\n% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\n% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\n% THE POSSIBILITY OF SUCH DAMAGE.\n\nfunction mat = gauss3d( sizeX, sizeY, sizeZ, sigmaX, sigmaY, sigmaZ, meanX, meanY, meanZ, cut);\n\nif nargin < 2\n\thelp gauss2d\n\treturn; \nend\nif nargin < 4\n\tsigmaX = sizeX/5;\nend\nif nargin < 5\n\tsigmaY = sizeY/5;\nend\nif nargin < 6\n\tsigmaZ = sizeZ/5;\nend\nif nargin < 7\n\tmeanX = (sizeX+1)/2;\nend\nif nargin < 8\n\tmeanY = (sizeY+1)/2;\nend\nif nargin < 9\n\tmeanZ = (sizeZ+1)/2;\nend\nif nargin < 10\n\tcut = 0;\nend\n\n[X,Y,Z] = ndgrid(1:sizeX,1:sizeY,1:sizeZ);\n\nmat = exp(-0.5*( ((X-meanX)/sigmaX).*((X-meanX)/sigmaX)...\n\t\t\t\t +((Y-meanY)/sigmaY).*((Y-meanY)/sigmaY)... \n\t\t\t\t +((Z-meanZ)/sigmaZ).*((Z-meanZ)/sigmaZ)))... \n \t\t\t/((sigmaX*sigmaY*sigmaZ)^(0.5)*pi); \n\nif cut > 0\n\tmaximum = max(mat(:))*cut;\n\tI = find(mat < maximum);\n\tmat(I) = 0;\nend\n\nreturn;\n\n", "meta": {"author": "sccn", "repo": "eeglab", "sha": "36d3982a63cde83fb279ab465b7a026ec2807c0a", "save_path": "github-repos/MATLAB/sccn-eeglab", "path": "github-repos/MATLAB/sccn-eeglab/eeglab-36d3982a63cde83fb279ab465b7a026ec2807c0a/functions/miscfunc/gauss3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191335436404, "lm_q2_score": 0.880797071719777, "lm_q1q2_score": 0.841442295383113}} {"text": "x = load('ex3x.dat');\ny = load('ex3y.dat');\nm = length(y);\nx = [ones(m, 1), x];\n\n# figure;\n# plot(x(:,2), y, 'x');\n# ylabel('Price in $');\n# xlabel('Living area in square feet');\n\n# figure;\n# plot(x(:,3), y, 'x');\n# ylabel('Price in $');\n# xlabel('Number of bedrooms');\n\nsigma = std(x);\nmu = mean(x);\nx(:,2) = (x(:,2) - mu(2)) ./ sigma(2);\nx(:,3) = (x(:,3) - mu(3)) ./ sigma(3);\n\nnum_iterations = 50;\n\nalphas = [0.001, 0.003, 0.01, 0.03, 0.1, 0.3, 1, 1.3, 3, 10];\nJ = zeros(num_iterations, length(alphas));\n\nfor iter = 1:length(alphas)\n theta = zeros(size(x(1,:)))';\n alpha = alphas(iter);\n for num_iterations = 1:50\n J(num_iterations, iter) = (1/2*m) * (x * theta - y)' * (x * theta - y);\n theta = theta - alpha * (1/m) * x' * (x * theta - y);\n end\nend\n\nfigure;\nhold on;\n\nfor iter = 1:length(alphas)-2\n alpha = alphas(iter);\n\n % now plot J\n % technically, the first J starts at the zero-eth iteration\n % but Matlab/Octave doesn't have a zero index\n plot(0:49, J(1:50, iter), '-');\n xlabel(['Number of iterations, alpha = ' num2str(alpha)]);\n ylabel('Cost J');\nend\n\nalpha = 1;\ntheta = zeros(size(x(1,:)))';\nfor num_iterations = 1:100\n theta = theta - alpha * (1/m) * x' * (x * theta - y);\nend\n\ntheta\n\nx1 = ([2, 1650, 3] - mu) ./ (sigma + [1,0,0]);\ny_predicted_1 = x1 * theta\n\n\n% Normal Equations\n\n% Reload data\nx = load('ex3x.dat');\ny = load('ex3y.dat');\nm = length(y);\nx = [ones(m, 1), x];\n\ntheta = (x' * x) \\ (x' * y)\n\nx2 = [1 1650 3];\ny_predicted_2 = x2 * theta\n\n", "meta": {"author": "zellyn", "repo": "deeplearning-class-2011", "sha": "d44b6c8695baa0d80b9fea21538f877e6d2eaddb", "save_path": "github-repos/MATLAB/zellyn-deeplearning-class-2011", "path": "github-repos/MATLAB/zellyn-deeplearning-class-2011/deeplearning-class-2011-d44b6c8695baa0d80b9fea21538f877e6d2eaddb/ex3-multivariate-linear-regression/ex3.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567176, "lm_q2_score": 0.897695292107347, "lm_q1q2_score": 0.841329716728978}} {"text": "function [post,lik,lli] = logistK_eval(beta,x,y)\n% [post,lik,lli] = logistK_eval(beta,x,y)\n%\n% Evaluate logistic regression model.\n% \n% INPUT\n% \tbeta \tdxk model coefficients (as returned by logistK)\n% \tx \tdxn matrix of n input column vectors\n% \t[y] \tkxn vector of class assignments\n%\n% OUTPUT\n% \tpost \tkxn fitted class posteriors\n% \tlik \t1xn vector of sample likelihoods\n%\tlli\tlog likelihood\n%\n% Let p(i,j) = exp(beta(:,j)'*x(:,i)),\n% Class j posterior for observation i is:\n%\tpost(j,i) = p(i,j) / (p(i,1) + ... p(i,k))\n% The likelihood of observation i given soft class assignments\n% y(:,i) is: \n%\tlik(i) = prod(post(:,i).^y(:,i))\n% The log-likelihood of the model given the labeled samples is:\n%\tlli = sum(log(lik))\n% \n% See also logistK.\n%\n% David Martin \n% May 7, 2002\n\n% Copyright (C) 2002 David R. Martin \n%\n% This program is free software; you can redistribute it and/or\n% modify it under the terms of the GNU General Public License as\n% published by the Free Software Foundation; either version 2 of the\n% License, or (at your option) any later version.\n% \n% This program is distributed in the hope that it will be useful, but\n% WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n% 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., 59 Temple Place - Suite 330, Boston, MA\n% 02111-1307, USA, or see http://www.gnu.org/copyleft/gpl.html.\n\nerror(nargchk(2,3,nargin));\n\n% check sizes\nif size(beta,1) ~= size(x,1),\n error('Inputs beta,x not the same height.');\nend\nif nargin > 3 & size(y,2) ~= size(x,2), \n error('Inputs x,y not the same length.'); \nend\n\n% get sizes\n[d,k] = size(beta);\n[d,n] = size(x);\n\n% class posteriors\npost = zeros(k,n);\nbx = zeros(k,n);\nfor j = 1:k, \n bx(j,:) = beta(:,j)'*x; \nend\nfor j = 1:k, \n post(j,:) = 1 ./ sum(exp(bx - repmat(bx(j,:),k,1)),1);\nend\nclear bx;\n\n% likelihood of each sample\nif nargout > 1,\n y = y ./ repmat(sum(y,1),k,1); % L1-normalize class assignments\n lik = prod(post.^y,1);\nend\n\n% total log likelihood\nif nargout > 2,\n lli = sum(log(lik+eps));\nend;\n\n% eof\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/dmlt/external/murphy/KPMstats/logistK_eval.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993028, "lm_q2_score": 0.8918110440002044, "lm_q1q2_score": 0.8412877840207484}} {"text": "function distVal=GaussianSimilarity(mu1,Sigma1,mu2,Sigma2)\n%%GAUSSIANSIMILARITY This is the normalized similarity measure used between\n% two Gaussian distributions in the Appendix of [1]. It\n% ranges from 0 (completely different) to 1 (same\n% distribution).\n%\n%INPUTS: mu1 The xDimX1 mean of the first Gaussian distribution.\n% Sigma1 The xDimXxDim covariance matrix of the first Gaussian\n% distribution.\n% mu2 The xDimX1 mean of the second Gaussian distribution.\n% Sigma2 The xDimXxDim covariance matrix of the second Gaussian\n% distribution.\n%\n%OUTPUTS: distVal The scalar distance between the two distributions.\n%\n%EXAMPLE:\n%We show the similairty of identical distirbutions, extremely different\n%distributions, and distributions that just differ a little bit.\n% mu1=[12;3];\n% mu2=[2000;8000];\n% Sigma1=[10, 6;\n% 6, 9];\n% Sigma2=[8, -3;\n% -3, 14];\n% %Identical Distributions (Similarity is 1).\n% GaussianSimilarity(mu1,Sigma1,mu1,Sigma1)\n% %Distributions that are very different (Similarity is 0).\n% GaussianSimilarity(mu1,Sigma1,mu2,Sigma2)\n% %Distributions that only differ a little bit (Similarity is about\n% %0.2163).\n% GaussianSimilarity(mu1,Sigma1,mu1*0.5,Sigma1*0.5)\n%\n%REFERENCES:\n%[1] F. Faubel, J. McDonough, and D. Klakow, \"The split and merge unscented\n% Gaussian mixture filter,\" IEEE Signal Processing Letters, vol. 16, no.\n% 9, pp. 786-789, Sep. 2009.\n%\n%January 2021 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n%Equation 16.\nSigma12Inv=inv(Sigma1)+inv(Sigma2);\n%Equation 15.\nmu12=Sigma12Inv\\(Sigma1\\mu1+Sigma2\\mu2);\n\nnumDim=size(mu1,1);\nz=zeros(numDim,1);\n\np1=GaussianD.PDF(z,mu1,Sigma1/2);\np2=GaussianD.PDF(z,mu2,Sigma2/2);\np12=GaussianD.PDFI(z,mu12,Sigma12Inv);\n\nif(p1==0||p2==0||p12==0||p1*p2==0)\n distVal=0;\nelse\n distVal=sqrt(p1*p2)/p12;\nend\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/Clustering_and_Mixture_Reduction/GaussianSimilarity.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545377452443, "lm_q2_score": 0.8872046041554923, "lm_q1q2_score": 0.8412070713385033}} {"text": "function value = pyramid_volume_3d ( r, h )\n\n%*****************************************************************************80\n%\n%% PYRAMID_VOLUME_3D returns the volume of a pyramid with square base in 3D.\n%\n% Integration region:\n%\n% Z - 1 <= X <= 1 - Z\n% Z - 1 <= Y <= 1 - Z\n% 0 <= Z <= 1.\n%\n% Discussion:\n%\n% A pyramid with square base can be regarded as the upper half of a\n% 3D octahedron.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 26 May 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R, the \"radius\" of the pyramid, that is, half the\n% length of one of the sides of the square base.\n%\n% Input, real H, the height of the pyramid.\n%\n% Output, real PYRAMID_VOLUME_3D, the volume of the pyramid.\n%\n value = ( 4.0 / 3.0 ) * h * r * r;\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/stroud/pyramid_volume_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545377452443, "lm_q2_score": 0.8872045966995027, "lm_q1q2_score": 0.8412070642690729}} {"text": "function value = lens_half_w_area_2d ( r, w )\n\n%*****************************************************************************80\n%\n%% LENS_HALF_W_AREA_2D returns the area of a circular half lens in 2D.\n%\n% Discussion:\n%\n% A circular half lens is formed by drawing a circular arc, and joining its endpoints.\n% This particular half lens is described by the \"width\" of the region. In other words,\n% it is the portion of the circle under water if the width\n% of the water surface is W. There are two possible values for this\n% area, A and (PI*R**2-A). The routine returns the smaller of the\n% two values.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 20 May 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R, the radius of the circle.\n%\n% Input, real W, the width of the half lens.\n%\n% Output, real VALUE, the area of the half lens.\n%\n if ( w <= 0.0E+00 )\n\n value = 0.0E+00;\n\n elseif ( 2.0E+00 * r <= w )\n\n value = 0.5E+00 * pi * r * r;\n\n else\n\n half_width = 0.5E+00 * w;\n h = r - sqrt ( r * r - half_width * half_width );\n angle = 2.0E+00 * atan2 ( half_width, r - h );\n sector = r * r * angle / 2.0E+00;\n triangle = ( r - h ) * half_width;\n value = sector - triangle;\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/stroud/lens_half_w_area_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541626630935, "lm_q2_score": 0.8933094159957173, "lm_q1q2_score": 0.8411885301185044}} {"text": "function intVal=monomialIntSpherSurf(alpha)\n%%MONOMIALINTSPHERSURF Evaluate the integral of prod_{i=1}^Nx(i)^alpha(i)\n% over the surface defined by sum(x.^2)=1. That is, this function\n% gives the value of the desired monomial integral taken over the\n% surface of an n-dimensional hypersphere. The region is\n% designated as U_n in [1].\n%\n%INPUTS: alpha An NX1 or 1XN vector of the integer exponents of the\n% monomial term. All elements must be >=0.\n%\n%OUTPUTS: intVal The value of the specified integral.\n%\n%The formula is taken from Chapter 7.6 of [1]. These types of explicit\n%moment formulae are useful for testing cubature integration points.\n%\n%EXAMPLE:\n%Here we verify that the moment value produced here equals that obtained\n%using cubature points of an appropriate order.\n% [xi,w]=seventhOrderSpherSurfCubPoints(3);\n% alpha=[0;4;2];\n% theMoment=findMomentFromSamp(alpha,xi,w)\n% intVal=monomialIntSpherSurf(alpha)\n%One will see that theMoment and intVal are both about 0.3590.\n%\n%REFERENCES:\n%[1] A.H. Stroud, Approximate Calculation of Multiple Integrals. Cliffs,\n% NJ: Prentice-Hall, Inc., 1971.\n%\n%February 2017 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(all(mod(alpha,2)==0))\n n=length(alpha);\n\n intVal=2*exp(sum(gammaln((alpha+1)/2))-gammaln((n+sum(alpha))/2));\nelse\n intVal=0;\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/Specific_Integrals/Monomial_Integrals/monomialIntSpherSurf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428691, "lm_q2_score": 0.8947894710123925, "lm_q1q2_score": 0.8410245675822445}} {"text": "\n\nfunction call_price=american_call_futures_currcy_bin(S, K, r, r_f, sigma, time, no_steps)\n\n\n%--------------------------------------------------------------------------\n%\n% DESCRIPTION:\n%\n% Pricing a futures currency option using a binomial approximation\n%\n%\n% Reference:\n%\n% John Hull, \"Options, Futures and other Derivative Securities\",\n% Prentice-Hall, second edition, 1993.\n% \n%--------------------------------------------------------------------------\n%\n% INPUTS:\n%\n% S: spot price\n% K: exercice price\n% r: domestic interest rate\n% r_f: foreign interest rate\n% sigma: volatility\n% time: time to maturity\n% no_steps: number of steps in binomial tree\n%\n%--------------------------------------------------------------------------\n%\n% OUTPUT:\n%\n% call_price: price of a call option\n%\n%--------------------------------------------------------------------------\n%\n% Author: Paolo Z., February 2012\n%\n%--------------------------------------------------------------------------\n\n\nexchange_rates=zeros(no_steps+1,1);\n\ncall_values=zeros(no_steps+1,1);\n\nt_delta= time/no_steps;\nRinv = exp(-r*(t_delta));\nu = exp(sigma*sqrt(t_delta));\nd = 1.0/u;\nuu= u*u;\npUp = (exp((r-r_f)*t_delta)-d)/(u-d); \npDown = 1.0 - pUp;\nexchange_rates(1) = S*(d^no_steps);\n\n\nfor ( i=2:(no_steps+1) ) \n exchange_rates(i) = uu*exchange_rates(i-1); \nend\n\n\nfor ( i=1:(no_steps+1) ) \n call_values(i) = max(0.0, (exchange_rates(i)-K));\nend\n \n\nfor ( step=no_steps:-1:1 ) \n for ( i=1:1:(step) ) \n exchange_rates(i) = d*exchange_rates(i+1);\n call_values(i) = (pDown*call_values(i)+pUp*call_values(i+1))*Rinv;\n call_values(i) = max(call_values(i), exchange_rates(i)-K); \n end\nend\n\n\ncall_price = call_values(1);\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/35351-option-pricing-package/american_call_futures_currcy_bin.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.956634206181515, "lm_q2_score": 0.8791467738423874, "lm_q1q2_score": 0.841021876111752}} {"text": "function J=polarU2DCrossGrad(uList,systemType)\n%%POLARU2DCROSSGRAD Given the direction cosine value u in 2D, obtain the\n% derivative of the polar azimuth angle with respect to u.\n%\n%INPUTS: uList A 1XnumPoints (for only u) or a 2XnumPoints (if full unit\n% vectors are given) set of direction cosines in 2D.\n% systemType An optional parameter specifying the axis from which the\n% angles are measured. Possible values are\n% 0 (The default if omitted or an empty matrix is passed) The\n% azimuth angle is counterclockwise from the x axis.\n% 1 The azimuth angle is measured clockwise from the y axis.\n%\n%OUTPUTS: J A 1XnumPoints set of derivatives of the azimuth angle with\n% respect to u evaluated at the given u values.\n%\n%EXAMPLE:\n%Here, we verify that the derivatives returned by this function are about\n%equal to those returned via numeric differentiation (forward\n%differencing).\n% points=[0.1,0.2,-0.2,0,-0.9];%u points\n% systemType=1;\n% epsVal=1e-9;\n% \n% az=u2PolAng2D(points,systemType);\n% az1=u2PolAng2D(points+epsVal,systemType);\n% JNumDiff=(az1-az)/epsVal;\n% J=polarU2DCrossGrad(points,systemType);\n% \n% max(abs(JNumDiff-J))\n%One will see that the difference is on the order of 3e-8, which is a good\n%agreement.\n%\n%June 2017 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<2||isempty(systemType))\n systemType=0; \nend\n\nhasV=size(uList,1)>1;\n\nN=size(uList,2);\n\nJ=zeros(1,N);\nfor curPoint=1:N\n u=uList(1,curPoint);\n \n if(hasV)\n v=uList(2,curPoint);\n else\n v=sqrt(1-u^2);\n end\n\n switch(systemType)\n case 0\n J(curPoint)=-1/v;\n case 1\n J(curPoint)=1/v;\n otherwise\n error('Invalid system type specified.')\n end\nend\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/Jacobians/Cross_Gradients/polarU2DCrossGrad.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374443, "lm_q2_score": 0.9019206824612296, "lm_q1q2_score": 0.8409989263835488}} {"text": "function area = polygonArea(poly, varargin)\n%POLYGONAREA Compute the signed area of a polygon.\n%\n% A = polygonArea(POINTS);\n% Compute area of a polygon defined by POINTS. POINTS is a N-by-2 array\n% of double containing coordinates of vertices.\n% \n% Vertices of the polygon are supposed to be oriented Counter-Clockwise\n% (CCW). In this case, the signed area is positive.\n% If vertices are oriented Clockwise (CW), the signed area is negative.\n%\n% If polygon is self-crossing, the result is undefined.\n%\n% Examples\n% % compute area of a simple shape\n% poly = [10 10;30 10;30 20;10 20];\n% area = polygonArea(poly)\n% area = \n% 200\n%\n% % compute area of CW polygon\n% area2 = polygonArea(poly(end:-1:1, :))\n% area2 = \n% -200\n%\n% % Computes area of a paper hen\n% x = [0 10 20 0 -10 -20 -10 -10 0];\n% y = [0 0 10 10 20 10 10 0 -10];\n% poly = [x' y'];\n% area = polygonArea(poly)\n% area =\n% 400\n%\n% % Area of unit square with 25% hole\n% pccw = [0 0; 1 0; 1 1; 0 1];\n% pcw = pccw([1 4 3 2], :) * .5 + .25;\n% polygonArea ([pccw; nan(1,2); pcw])\n% ans =\n% 0.75\n%\n% References\n% algo adapted from P. Bourke web page\n% http://paulbourke.net/geometry/polygonmesh/\n%\n% See also \n% polygons2d, polygonCentroid, polygonSecondAreaMoments, triangleArea\n%\n\n% ------\n% Author: David Legland \n% E-mail: david.legland@inrae.fr\n% Created: 2004-05-05\n% Copyright 2004-2022 INRA - TPV URPOI - BIA IMASTE\n\n%% Process special cases\n\n% in case of polygon sets, computes the sum of polygon areas\nif iscell(poly)\n area = 0;\n for i = 1:length(poly)\n area = area + polygonArea(poly{i});\n end\n return;\nend\n\n% check there are enough points\nif size(poly, 1) < 2\n area = 0;\n return;\nend\n\n% case of polygons with holes -> computes the sum of areas\nif any(isnan(poly))\n area = sum(polygonArea(splitPolygons(poly)));\n return;\nend\n\n\n%% Process single polygons or single rings\n\n% extract coordinates\nif nargin == 1\n % polygon given as N-by-2 array\n px = poly(:, 1);\n py = poly(:, 2);\n \nelseif nargin == 2\n % poylgon given as two N-by-1 arrays\n px = poly;\n py = varargin{1};\nend\n\n% indices of next vertices\nN = length(px);\niNext = [2:N 1];\n\n% compute area (vectorized version)\narea = sum(px .* py(iNext) - px(iNext) .* py) / 2;\n", "meta": {"author": "mattools", "repo": "matGeom", "sha": "1fd2c937064be1ee1f4fd09fbfdf96145ebe5271", "save_path": "github-repos/MATLAB/mattools-matGeom", "path": "github-repos/MATLAB/mattools-matGeom/matGeom-1fd2c937064be1ee1f4fd09fbfdf96145ebe5271/matGeom/polygons2d/polygonArea.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291501, "lm_q2_score": 0.9019206864156891, "lm_q1q2_score": 0.8409989232990117}} {"text": "function [ c, ierror ] = r8mat_cholesky_factor ( n, a )\n\n%*****************************************************************************80\n%\n%% R8MAT_CHOLESKY_FACTOR computes the Cholesky factor of a symmetric matrix.\n%\n% Discussion:\n%\n% The matrix must be symmetric and positive semidefinite.\n%\n% For a positive semidefinite symmetric matrix A, the Cholesky factorization\n% is a lower triangular matrix L such that:\n%\n% A = L * L'\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n%\n% Input, real A(N,N), the matrix.\n%\n% Output, real C(N,N), the lower triangular Cholesky factor.\n%\n% Output, integer IERROR, error flag.\n% 0, no error.\n% 1, warning, the matrix is positive semidefinite. The factorization\n% was carried out, but the matrix is singular.\n% 2, error, the matrix has at least one negative eigenvalue. The\n% factorization could not be completed.\n%\n ierror = 0;\n\n c(1:n,1:n) = a(1:n,1:n);\n\n for j = 1 : n\n\n c(1:j-1,j) = 0.0;\n\n for i = j : n\n\n ctc = c(j,i) - c(i,1:j-1) c(j,1:j-1)';\n\n if ( i == j )\n if ( ctc < 0.0 )\n ierror = 2;\n return\n elseif ( ctc == 0.0 )\n ierror = 1;\n else\n c(i,j) = sqrt ( ctc );\n end\n else\n if ( c(j,j) ~= 0.0 )\n c(i,j) = ctc / c(j,j);\n else\n c(i,j) = 0.0;\n end\n end\n\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/r8mat_cholesky_factor.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533013520764, "lm_q2_score": 0.9019206752113866, "lm_q1q2_score": 0.8409989111585513}} {"text": "function value = sphere_area_3d ( r )\n\n%*****************************************************************************80\n%\n%% SPHERE_AREA_3D computes the area of a sphere in 3D.\n%\n% Integration region:\n%\n% Points (X,Y,Z) such that\n%\n% X**2 + Y**2 + Z**2 = R**2\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 20 May 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R, the radius of the sphere.\n%\n% Output, real SPHERE_AREA_3D, the area of the sphere.\n%\n value = 4.0E+00 * pi * r * r;\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/stroud/sphere_area_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465098415279, "lm_q2_score": 0.8991213698363247, "lm_q1q2_score": 0.84099003520034}} {"text": "function s = gen(mode, len, frequency, samplerate, amplitude, startphase, yunit)\n\n% signal/gen\n%\n% generate various kind of signals with time axis\n%\n% si = gen(mode, len, frequency, samplerate, amplitude, startphase, yunit)\n%\n% len is measured in seconds\n% frequency, samplerate in Hertz\n% amplitude is measured in the current yunit (default is dimensionless)\n% startphase in radians\n% yunit is an optional argument\n%\n% mode may be one of the following :\n% sine - sinusodial signal between [-amplitude +amplitude]\n% unoise - uniform distrubuted random numbers in interval [-amplitude +amplitude]\n% gnoise - gaussian random numbers with zero mean\n% fnoise - spectral flat noise with zero mean (DC value = 0)\n% rect\t\t\t\t- rectangular signal with values discret values 0 and amplitude\n% symmrect - rectangular signal with values discret values -amplitude and amplitude\n% comb - train of (one sample wide) spikes of height amplitude, otherwise signal is zero\n% \n%\n% cmerk Feb. 1998\n\nif nargin < 1\n\tmode = 'sine';\t\t% sine, uniform noise, gaussian noise, rect, puls ...\nend\nif nargin < 2\n\tlen = 1;\t\t% one second \nend\nif nargin < 3\n\tfrequency = 1000;\t% 1000 Hz\nend\nif nargin < 4\n\tsamplerate = 8000;\t% Hertz\nend\nif nargin < 5\n\tamplitude = 1.0;\t\nend\nif nargin < 6\n\tstartphase = 0; \t% radian, 0..2pi\nend\nif nargin < 7\n\tyunit = unit;\t\t% no dimension\nend\n\n\nlen = ceil(len*samplerate);\nxfirst = 0;\noptinaltext = '';\nswitch mode\ncase\t'sine'\n\tt = (2*pi*frequency/samplerate)*(0:len-1)' + startphase;\n\ttmp = amplitude * sin(t);\n\toptinaltext = [' with frequency : ' num2str(frequency) 'Hz'];\ncase\t'unoise'\n\ttmp = (2* amplitude) * (rand(len,1)-0.5);\ncase\t'gnoise'\n\ttmp = amplitude * gauss(len);\ncase\t'fnoise'\n\tif mod(len, 2)\n\t\tN = (len-1)/2;\n\t\tr = exp(2*pi*i*rand(N,1));\n\t\ttmp = [0; r; conj(r(end:-1:1))];\n\telse\t\t\t\t\t\t\t% even length \n\t\tN = (len/2)-1;\n\t\tr = exp(2*pi*i*rand(N,1));\n\t\ttmp = [0; r; 1; conj(r(end:-1:1))];\n\tend\n\ttmp = (amplitude/2) * real(ifft(tmp));\ncase\t'rect'\n\ttolerance = 1e-8;\n\tt = (2*pi*frequency/samplerate)*(0:len-1)' + startphase;\n\ttmp = sin(t);\n\tind = find(tmp>tolerance);\n\ttmp(ind) = amplitude;\n\tind = find(abs(tmp)<=tolerance);\n\ttmp(ind(1:2:end)) = amplitude;\t% zeros values are set to amplitude zero amplitude zero ...\n\ttmp(ind(2:2:end)) = 0;\n\tind = find(tmptolerance);\n\ttmp(ind) = amplitude;\n\tind = find(abs(tmp)<=tolerance);\n\ttmp(ind(1:2:end)) = amplitude;\t% zeros values are set to amplitude zero amplitude zero ...\n\ttmp(ind(2:2:end)) = 0;\n\tind = find(tmp= 0))\n % The input is already within the Simplex.\n vX = vY;\n return;\nend\n\nvZ = sort(vY, 'ascend');\n\nvParamMu = [vZ(1) - ballRadius; vZ; vZ(numElements) + ballRadius];\nhObjFun = @(paramMu) sum( max(vY - paramMu, 0) ) - ballRadius;\n\nvObjVal = zeros(numElements + 2, 1);\nfor ii = 1:(numElements + 2)\n\tvObjVal(ii) = hObjFun(vParamMu(ii));\nend\n\nif(any(vObjVal == 0))\n paramMu = vParamMu(vObjVal == 0);\nelse\n % Working on when an Affine Function have the value zero\n valX1Idx = find(vObjVal > 0, 1, 'last');\n valX2Idx = find(vObjVal < 0, 1, 'first');\n\n valX1 = vParamMu(valX1Idx);\n valX2 = vParamMu(valX2Idx);\n valY1 = vObjVal(valX1Idx);\n valY2 = vObjVal(valX2Idx);\n\n paramA = (valY2 - valY1) / (valX2 - valX1);\n paramB = valY1 - (paramA * valX1);\n paramMu = -paramB / paramA;\nend\n\nvX = max(vY - paramMu, 0);\n\n\nend\n\n", "meta": {"author": "RoyiAvital", "repo": "StackExchangeCodes", "sha": "d2a934616995fa8a9f4df1ca29029402435b9e6f", "save_path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes", "path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes/StackExchangeCodes-d2a934616995fa8a9f4df1ca29029402435b9e6f/Mathematics/Q2327504/ProjectSimplexExact.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542864252022, "lm_q2_score": 0.8757869803008764, "lm_q1q2_score": 0.8400148361509697}} {"text": "function [ n_data_new, 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% 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% 26 May 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% Parameters:\n%\n% Input, integer N_DATA, indicates the index of the previous test data\n% returned, or is 0 if this is the first call. For repeated calls,\n% set the input value of N_DATA to the output value of N_DATA_NEW\n% from the previous call.\n%\n% Output, integer N_DATA_NEW, the index of the test data.\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 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_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 n_data_new = n_data;\n\n if ( n_data_new < 0 )\n n_data_new = 0;\n end\n\n n_data_new = n_data_new + 1;\n\n if ( n_max < n_data_new )\n n_data_new = 0;\n n = 0;\n c = 0;\n else\n n = n_vec(n_data_new);\n c = c_vec(n_data_new);\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/polpak/tau_values.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672954, "lm_q2_score": 0.9230391701259804, "lm_q1q2_score": 0.8398798145103576}} {"text": "function value = halfplane_contains_point_2d ( p1, p2, p )\n\n%*****************************************************************************80\n%\n%% HALFPLANE_CONTAINS_POINT_2D reports if a half-plane contains a point in 2d.\n%\n% Discussion:\n%\n% The halfplane is assumed to be all the points \"to the left\" of the\n% line that passes from P1 through P2. Thus, one way to\n% understand where the point P = (X,Y) is, is to compute the signed\n% area of the triangle ( P1, P2, P ).\n%\n% If this area is\n% positive, the point is strictly inside the halfplane,\n% zero, the point is on the boundary of the halfplane,\n% negative, the point is strictly outside the halfplane.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 17 February 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real P1(2,1), P2(2,1), two distinct points\n% on the line defining the half plane.\n%\n% Input, real P(2,1), the point to be checked.\n%\n% Output, logical VALUE, is TRUE if the halfplane\n% contains the point.\n%\n area_signed = 0.5 * ...\n ( p1(1,1) * ( p2(2,1) - p(2,1) ) ...\n + p2(1,1) * ( p(2,1) - p1(2,1) ) ...\n + p(1,1) * ( p1(2,1) - p2(2,1) ) );\n\n value = ( 0.0 <= area_signed );\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/halfplane_contains_point_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947179030094, "lm_q2_score": 0.8887587883361618, "lm_q1q2_score": 0.8398723604675516}} {"text": "%% Structured grid\n% This is a sample code showing how to use ConstructProjector3D().\n% This example is going to setup a transformation matrix based on forth\n% order polynomials in 3D. \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;\nzMin=0;\nzMax=2*pi;\n\nnx=20;\nny=20;\nnz=20;\n\ndx=(xMax-xMin)/(nx-1);\ndy=(yMax-yMin)/(ny-1);\ndz=(zMax-zMin)/(nz-1);\n\nnPoly=1; % We gonna fit a fourth order polynomial, \n % i.e. sum_{n,m,t=0}^{n,m,t=nPoly} x^n*y^m*z^t \nnInterp=8; % nPoly=4 requires 125 points. However, \n % we are going to use 150 points. This would be \n % the least-square fit of the surface.\n % Note that: min(nInterp)=(nPoly+1)^3. 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,zn]=meshgrid(linspace(xMin,xMax,nx),linspace(yMin,yMax,ny),linspace(zMin,zMax,nz));\n\n%% Finding the cell centers\ndisp('- Generating the destination grid')\nxc=xn(1:ny-1,1:nx-1,1:nz-1)+dx/2;\nyc=yn(1:ny-1,1:nx-1,1:nz-1)+dy/2;\nzc=zn(1:ny-1,1:nx-1,1:nz-1)+dz/2;\n\nfigure\nplot3(xn(:),yn(:),zn(:),'k.','MarkerSize',20);\nhold on\nplot3(xc(:),yc(:),zc(:),'b.','MarkerSize',20);\naxis tight;\naxis square;\ntitle('Source Grid, black dots, & the destination grid, blue dots.', ...\n 'FontName','Arial','FontSize',12,'FontWeight','Bold');\n\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=ConstructProjector3D(xn(:),yn(:),zn(:),xc(:),yc(:),zc(:),nPoly,nInterp);\n\n%% Generarting some Data\ndisp('- Generating some data and interpolating')\nF1=@(x,y,z) (sin(sqrt(x.^2+y.^2+z.^2)));\nVn=F1(xn,yn,zn);\nVc_interp=reshape(P*Vn(:),size(xc));\nVc_Analytic=F1(xc,yc,zc);\nRMSE=sqrt(mean((Vc_Analytic(:)-Vc_interp(:)).^2));\ndisp(['RMSE: ' num2str(RMSE)])\n\n%% Generating some more data\ndisp('- Generating multiple data field on the source grid and interpolating them.')\nF2=@(x,y,z) (sin(x).*cos(y).*sin(z));\nF3=@(x,y,z) (exp(-sqrt(x.^2+y.^2+z.^2)));\nF4=@(x,y,z,x0,y0,z0) (exp(-sqrt((x-x0).^2+(y-y0).^2+(z-z0).^2)));\n\nVn(:,:,:,1)=F1(xn,yn,zn);\nVn(:,:,:,2)=F2(xn,yn,zn);\nVn(:,:,:,3)=F3(xn,yn,zn);\nVn(:,:,:,4)=F4(xn,yn,zn,mean(mean(mean(xn))),mean(mean(mean(yn))),mean(mean(mean(zn))));\n\nVc_Analytic(:,:,:,1)=F1(xc,yc,zc);\nVc_Analytic(:,:,:,2)=F2(xc,yc,zc);\nVc_Analytic(:,:,:,3)=F3(xc,yc,zc);\nVc_Analytic(:,:,:,4)=F4(xc,yc,zc,mean(mean(mean(xn))),mean(mean(mean(yn))),mean(mean(mean(zn))));\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.\nVc_interp=P*reshape(Vn,nx*ny*nz,4); % There are 4 data fields.\nVc_interp=reshape(Vc_interp,(ny-1),(nx-1),(nz-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);\nfor i=1:4\n RMSE(i)=sqrt(mean((reshape(Vc_Analytic(:,:,:,i),(nx-1)*(ny-1)*(nz-1),1)-reshape(Vc_interp(:,:,:,i),(nx-1)*(ny-1)*(nz-1),1)).^2));\n disp(['F' num2str(i) ', nPoly: ' num2str(nPoly) ', RMSE:' num2str(RMSE(i))])\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_3D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191284552528, "lm_q2_score": 0.8791467580102418, "lm_q1q2_score": 0.8398657146466052}} {"text": "function b = bell ( n )\n\n%*****************************************************************************80\n%\n%% BELL returns the Bell numbers from 0 to N.\n%\n% Discussion:\n%\n% The Bell number B(N) is the number of restricted growth functions\n% on N.\n%\n% Note that the Stirling numbers of the second kind, S^m_n, count the\n% number of partitions of N objects into M classes, and so it is\n% true that\n%\n% B(N) = S^1_N + S^2_N + ... + S^N_N.\n%\n% Definition:\n%\n% The Bell number B(N) is defined as the number of partitions (of\n% any size) of a set of N distinguishable objects.\n%\n% A partition of a set is a division of the objects of the set into\n% subsets.\n%\n% Examples:\n%\n% There are 15 partitions of a set of 4 objects:\n%\n% (1234), (123)(4), (124)(3), (12)(34), (12)(3)(4),\n% (134)(2), (13)(24), (13)(2)(4), (14)(23), (1)(234),\n% (1)(23)(4), (14)(2)(3), (1)(24)(3), (1)(2)(34), (1)(2)(3)(4)\n%\n% and so B(4) = 15.\n%\n% First values:\n%\n% N B(N)\n% 0 1\n% 1 1\n% 2 2\n% 3 5\n% 4 15\n% 5 52\n% 6 203\n% 7 877\n% 8 4140\n% 9 21147\n% 10 115975\n%\n% Recursion:\n%\n% B(I) = sum ( 1 <= J <= I ) Binomial ( I-1, J-1 ) * B(I-J)\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 June 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of Bell numbers desired.\n%\n% Output, integer B(1:N+1), the Bell numbers from 0 to N.\n%\n b(1) = 1;\n\n for i = 1 : n\n b(i+1) = 0;\n for j = 1 : i\n b(i+1) = b(i+1) + i4_choose ( i-1, j-1 ) * b(i-j+1);\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/polpak/bell.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993027, "lm_q2_score": 0.8902942355821459, "lm_q1q2_score": 0.8398569064807162}} {"text": "function wMed = weightedMedian(D,W)\n\n% ----------------------------------------------------------------------\n% Function for calculating the weighted median \n% Sven Haase\n%\n% For n numbers x_1,...,x_n with positive weights w_1,...,w_n, \n% (sum of all weights equal to one) the weighted median is defined as\n% the element x_k, such that:\n% -- --\n% ) w_i <= 1/2 and ) w_i <= 1/2\n% -- --\n% x_i < x_k x_i > x_k\n%\n%\n% Input: D ... matrix of observed values\n% W ... matrix of weights, W = ( w_ij )\n% Output: wMed ... weighted median \n% ----------------------------------------------------------------------\n\n\nif nargin ~= 2\n error('weightedMedian:wrongNumberOfArguments', ...\n 'Wrong number of arguments.');\nend\n\nif size(D) ~= size(W)\n error('weightedMedian:wrongMatrixDimension', ...\n 'The dimensions of the input-matrices must match.');\nend\n\n% normalize the weights, such that: sum ( w_ij ) = 1\n% (sum of all weights equal to one)\n\nWSum = sum(W(:));\nW = W / WSum;\n\n% (line by line) transformation of the input-matrices to line-vectors\nd = reshape(D',1,[]); \nw = reshape(W',1,[]); \n\n% sort the vectors\nA = [d' w'];\nASort = sortrows(A,1);\n\ndSort = ASort(:,1)';\nwSort = ASort(:,2)';\nsumVec = cumsum(wSort);\n\nwMed = []; \nj = 0; \n\nwhile isempty(wMed)\n j = j + 1;\n if sumVec(j) >= 0.5\n wMed = dSort(j); % value of the weighted median\n end\nend\n\n\n% final test to exclude errors in calculation\nif ( sum(wSort(1:j-1)) > 0.5 ) & ( sum(wSort(j+1:length(wSort))) > 0.5 )\n error('weightedMedian:unknownError', ...\n 'The weighted median could not be calculated.');\nend", "meta": {"author": "Cloud-CV", "repo": "object-proposals", "sha": "597a89520bc1b0b261420d7627b8c36439a24c7a", "save_path": "github-repos/MATLAB/Cloud-CV-object-proposals", "path": "github-repos/MATLAB/Cloud-CV-object-proposals/object-proposals-597a89520bc1b0b261420d7627b8c36439a24c7a/rigor/rigor_src/extern_src/fuxin_lib_src/boosting/weightedMedian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731147976794, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.8397853627696334}} {"text": "function outsig = noise(siglen,varargin)\n% NOISE Stochastic noise generator\n% Usage: outsig = noise(siglen,nsigs,type);\n%\n% Input parameters:\n% siglen : Length of the noise (samples)\n% nsigs : Number of signals (default is 1)\n% type : type of noise. See below.\n%\n% Output parameters:\n% outsig : $siglen \\times nsigs$ signal vector\n%\n% `noise(siglen,nsigs)` generates *nsigs* channels containing white noise\n% of the given type with the length of *siglen*. The signals are arranged as\n% columns in the output. If only *siglen* is given, a column vector is\n% returned.\n%\n% `noise` takes the following optional parameters:\n%\n% 'white' Generate white (gaussian) noise. This is the default.\n%\n% 'pink' Generate pink noise.\n%\n% 'brown' Generate brown noise.\n%\n% 'red' This is the same as brown noise. \n%\n% By default, the noise is normalized to have a unit energy, but this can\n% be changed by passing a flag to |setnorm|.\n%\n% Examples:\n% ---------\n% \n% White noise in the time-frequency domain:::\n%\n% sgram(noise(5000,'white'),'dynrange',70);\n%\n% Pink noise in the time-frequency domain:::\n%\n% sgram(noise(5000,'pink'),'dynrange',70);\n%\n% Brown/red noise in the time-frequency domain:::\n%\n% sgram(noise(5000,'brown'),'dynrange',70);\n% \n% See also: setnorm\n\n% AUTHOR: Hagen Wierstorf and Peter L. Søndergaard.\n\n\n\n% ------ Checking of input parameter -------------------------------------\n\nif nargin<1\n error('%s: Too few input parameters.',upper(mfilename));\nend;\n\nif ~isnumeric(siglen) || ~isscalar(siglen) || siglen<=0\n error('%s: siglen has to be a positive scalar.',upper(mfilename));\nend\n\ndefinput.import={'setnorm'};\ndefinput.importdefaults={'2'};\ndefinput.flags.noisetype={'white','pink','brown','red'};\ndefinput.keyvals.nsigs=1;\n[flags,kv,nsigs] = ltfatarghelper({'nsigs'},definput,varargin);\n\nif flags.do_white\n outsig=randn(siglen,nsigs);\nend;\n\nif flags.do_brown || flags.do_red\n outsig=cumsum(randn(siglen,nsigs));\nend;\n\nif flags.do_pink\n % --- Handle trivial condition\n\n if siglen==1\n outsig=ones(1,nsigs);\n return;\n end;\n\n % ------ Computation -----------------------------------------------------\n fmax = floor(siglen/2)-1;\n f = (2:(fmax+1)).';\n % 1/f amplitude factor\n a = 1./sqrt(f);\n % Random phase\n p = randn(fmax,nsigs) + i*randn(fmax,nsigs);\n sig = bsxfun(@times,a,p);\n\n outsig = ifftreal([ones(1,nsigs); sig; 1/(fmax+2)*ones(1,nsigs)],siglen);\n\nend;\n\noutsig=setnorm(outsig,flags.norm);\n\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/signals/noise.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465188527685, "lm_q2_score": 0.8976952852648487, "lm_q1q2_score": 0.8396561600630192}} {"text": "function cdf = gumbel_cdf ( x )\n\n%*****************************************************************************80\n%\n%% GUMBEL_CDF evaluates the Gumbel CDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the CDF.\n%\n% Output, real CDF, the value of the CDF.\n%\n cdf = exp ( - exp ( - x ) );\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/gumbel_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9532750387190131, "lm_q2_score": 0.8807970701552505, "lm_q1q2_score": 0.8396418611558397}} {"text": "%Generate 2D Gabor Patch\n%\n% GABOR\n% Generates a spatially oriented sinusoidal grating multiplied by a gaussian\n% window. Gabor functions have been used to model simple cell receptive fields\n% and are commonly used filters for edge detection.\n%\n% USAGE\n% [x y F] = gabor(varargin)\n%\n% Returns:\n% x: grid of x-values\n% y: grid of y-values\n% F: gabor function evaluated at (x,y) points\n%\n% Parameters (Default):\n% theta (2*pi*rand): orientation of the gabor patch\n% lambda (20): spatial wavelength\n% Sigma (10): standard deviation of gaussian window\n% width (256): width of generated image\n% height (256): height of generated image\n% px (rand): horizontal center of gabor patch, relative to the image width (must be between 0 and 1)\n% py (rand): vertical center of gabor patch, relative to the image height (must be between 0 and 1)\n%\n% EXAMPLE\n% [x y F] = gabor;\n% pcolor(x,y,F); axis image;\n% shading('interp'); colormap copper;\n%\n% VERSION 1.0, Thu Jul 12 09:47:52 2012\n%\n% AUTHOR: Niru Maheswaranathan\n% nirum@stanford.edu\n\nfunction [x y F] = gabor(varargin)\n\n % Parse Input\n p = inputParser;\n addParamValue(p,'theta',2*pi*rand,@isnumeric);\n addParamValue(p,'lambda',20,@isnumeric);\n addParamValue(p,'Sigma',10,@isnumeric);\n addParamValue(p,'width',256,@isnumeric);\n addParamValue(p,'height',256,@isnumeric);\n addParamValue(p,'px',rand*0.8 + 0.1,@isnumeric);\n addParamValue(p,'py',rand*0.8 + 0.1,@isnumeric);\n p.KeepUnmatched = true;\n parse(p,varargin{:});\n\n % Generate mesh\n [x y] = meshgrid(1:p.Results.width, 1:p.Results.height);\n\n % Center of gaussian window\n cx = p.Results.px*p.Results.width;\n cy = p.Results.py*p.Results.height;\n\n % Orientation\n x_theta=(x-cx)*cos(p.Results.theta)+(y-cy)*sin(p.Results.theta);\n y_theta=-(x-cx)*sin(p.Results.theta)+(y-cy)*cos(p.Results.theta);\n\n % Generate gabor\n F = exp(-.5*(x_theta.^2/p.Results.Sigma^2+y_theta.^2/p.Results.Sigma^2)).*cos(2*pi/p.Results.lambda*x_theta);\n\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/37471-gabor-function/gabor.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693617046216, "lm_q2_score": 0.8840392863287585, "lm_q1q2_score": 0.8395450247696413}} {"text": "function [J, grad] = costFunctionReg(theta, X, y, lambda)\n%COSTFUNCTIONREG Compute cost and gradient for logistic regression with regularization\n% J = COSTFUNCTIONREG(theta, X, y, lambda) computes the cost of using\n% theta as the parameter for regularized logistic regression and the\n% gradient of the cost w.r.t. to the parameters. \n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n\nhx = sigmoid(X * theta); %hypothesis, m * 1\n\nJ = 1 / m * sum(-y' * log(hx) - (1 - y)' * log(1 - hx)) + lambda / (2 * m) * theta(2:end)' * theta(2:end);\n\ngradf = (1 / m) * (X(:, 1)' * (hx - y));\ngradb = (1 / m) * (X(:, 2:end)' * (hx - y)) + lambda * theta(2:end) / m;\n\ngrad = [gradf;gradb];\n\n\n% =============================================================\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-ex2/ex2/costFunctionReg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.960361162033533, "lm_q2_score": 0.8740772450055545, "lm_q1q2_score": 0.8394298387206034}} {"text": "function fd=pderiv(f,dim,difforder)\n%PDERIV Derivative of smooth periodic function\n% Usage: fd=pderiv(f);\n% fd=pderiv(f,dim);\n% fd=pderiv(f,dim,difforder);\n%\n% `pderiv(f)` will compute the derivative of *f* using a using a 4th order\n% centered finite difference scheme. *f* must have been obtained by a\n% regular sampling. If *f* is a matrix, the derivative along the columns\n% will be found.\n%\n% `pderiv(f,dim)` will do the same along dimension *dim*.\n%\n% `pderiv(f,dim,difforder)` uses a centered finite difference scheme of\n% order *difforder* instead of the default.\n%\n% `pderiv(f,dim,Inf)` will compute the spectral derivative using a DFT.\n%\n% `pderiv` assumes that *f* is a regular sampling of a function on the\n% torus $[0,1)$. The derivative of a function on a general torus $[0,T)$\n% can be found by scaling the output by $1/T$. \n\n% Assert correct input.\n\ncomplainif_argnonotinrange(nargin,1,3,mfilename);\n\nif nargin==1\n dim=[];\nend;\n\nif nargin<3\n difforder=4;\nend;\n\n[f,L,Ls,W,dim,permutedsize,order]=assert_sigreshape_pre(f,[],dim,'PDERIV');\n\nswitch(difforder)\n case 2\n fd = L*(circshift(f,-1)-circshift(f,1))/2;\n case 4\n fd = L*(-circshift(f,-2)+8*circshift(f,-1)-8*circshift(f,1)+ ...\n circshift(f,2))/12;\n case Inf\n n=fftindex(L,0);\n n=repmat(n,1,W);\n \n fd=2*pi*ifft(i*n.*fft(f));\n\n if isreal(f)\n fd=real(fd);\n end;\n\n otherwise\n error('The specified differentation order is not implemented.');\nend;\n\nfd=assert_sigreshape_post(fd,dim,permutedsize,order);\n\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/fourier/pderiv.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362489, "lm_q2_score": 0.8947894534772125, "lm_q1q2_score": 0.839423477124065}} {"text": "function xMax = SmoothMax(x,alpha)\n%\n% xMax = SmoothMax(x, alpha)\n%\n% This function is a smooth version of the max(x) function, commonly known\n% as the 'soft-max' function. In the limit as the smoothing parameter goes\n% to zero, this function will return max(x). In the limit as the smoothing\n% parameter goes to infinity, this will return sum(x).\n%\n%INPUTS:\n% x = a vector or matrix of inputs \n% alpha = a smoothing parameter. Asymtotes: 0->max(x), inf->sum(x) \n%\n%OUTPUTS:\n% xMax = the smooth maximum of x\n%\n%\n% Written by Matthew Kelly\n% October 2013\n% Cornell University\n%\n\nif nargin==1\n alpha = 1;\nend\n\nxMax = alpha*log(sum(exp(x/alpha)));\n\nif isinf(xMax)\n %Then the scaling was too sharp\n xMax = max(x);\nend\n\nend", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/smoothing/exponentialSmoothing/SmoothMax.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9511422186079558, "lm_q2_score": 0.8824278726384089, "lm_q1q2_score": 0.8393144045427949}} {"text": "function [J, grad] = costFunctionReg(theta, X, y, lambda)\n%COSTFUNCTIONREG Compute cost and gradient for logistic regression with regularization\n% J = COSTFUNCTIONREG(theta, X, y, lambda) computes the cost of using\n% theta as the parameter for regularized logistic regression and the\n% gradient of the cost w.r.t. to the parameters. \n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n\n\nh = sigmoid(X*theta);\n% J = (1/m)*sum(-y .* log(h) - (1 - y) .* log(1-h));\nshift_theta = theta(2:size(theta));\ntheta_reg = [0;shift_theta];\n\nJ = (1/m)*(-y'* log(h) - (1 - y)'*log(1-h))+(lambda/(2*m))*theta_reg'*theta_reg;\n\n% grad_zero = (1/m)*X(:,1)'*(h-y);\n% grad_rest = (1/m)*(shift_x'*(h - y)+lambda*shift_theta);\n% grad = cat(1, grad_zero, grad_rest);\n\ngrad = (1/m)*(X'*(h-y)+lambda*theta_reg);\n\n% =============================================================\n\nend\n", "meta": {"author": "schneems", "repo": "Octave", "sha": "411e8794574abb3fb042e178bf95861dfcee3b04", "save_path": "github-repos/MATLAB/schneems-Octave", "path": "github-repos/MATLAB/schneems-Octave/Octave-411e8794574abb3fb042e178bf95861dfcee3b04/mlclass-ex2/mlclass-ex2/costFunctionReg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075766298658, "lm_q2_score": 0.8723473746782093, "lm_q1q2_score": 0.8392920186310775}} {"text": "function v = getNonUniformGrid(m_0, lx, ux, gridMethod, center, manualPoint, gridMultParam)\n%UNTITLED Summary of this function goes here\n% Detailed explanation goes here\n\nnx = m_0; dx = (ux-lx)/nx;\n\nif gridMethod == 1 % uniform grid , doesn't include lower bound\n v = lx + (1:nx)'*dx; \nelseif gridMethod == 2 %%Mijatovic and Pistorious\n v = zeros(m_0,1);\n v(1) = lx; v(m_0) = ux;\n mid = floor(m_0/2); \n for k = 2: mid\n v(k) = center + sinh( (1-(k-1)/(mid -1))*asinh(v(1)-center) );\n end\n for k = mid+1:m_0-1\n v(k) = center + sinh( ((k - mid)/(mid))*asinh(v(m_0) - center) );\n end\nelseif gridMethod == 3 %%Carr and Mayo\n x=0:1/(m_0-1):1; %map [0,1] to new grid\n alpha = 0.8*(ux-lx);\n c1 = asinh((lx-center)/alpha);\n c2 = asinh((ux-center)/alpha);\n v = center + alpha*(c2*sinh(c2.*x+c1.*(1-x)));\nelseif gridMethod == 4 %% Tavella and Randall\n v = zeros(m_0,1);\n v(1) = lx;\n v(m_0) = ux;\n alpha = gridMultParam*(v(m_0) - v(1));\n c1 = asinh((v(1) - center)/alpha);\n c2 = asinh((v(m_0) - center)/alpha);\n v(2:m_0-1) = center + alpha*sinh(c2/m_0*(2:m_0-1) + c1*(1 - (2:m_0-1)/m_0));\nelseif gridMethod == 5 %% Tavella and Randall PLUS we put manualPoint (e.g. v0) on grid\n tol = 1e-7; \n v = zeros(m_0,1);\n v(1) = lx;\n v(m_0) = ux;\n alpha = gridMultParam*(v(m_0) - v(1));\n c1 = asinh((v(1) - center)/alpha);\n c2 = asinh((v(m_0) - center)/alpha);\n vtil = zeros(m_0-1,1);\n vtil(2:m_0-2) = center + alpha*sinh(c2/(m_0 - 1)*(2:m_0-2) + c1*(1 - (2:m_0-2)/(m_0-1)));\n nnot_til = 1;\n while vtil(nnot_til) < manualPoint %Find the index left of the manualPoint point\n nnot_til = nnot_til + 1;\n end\n nnot_til = nnot_til - 1;\n v(2:nnot_til) = vtil(2:nnot_til);\n v(nnot_til + 2: m_0 - 1) = vtil(nnot_til + 1: m_0 - 2);\n if manualPoint - vtil(nnot_til)=0.\n%\n%OUTPUTS: binomTable A (maxDeg+1)X(maxDeg+1) matrix where\n% binomTable(n+1,k+1) is the value of binomial(n,k). Unused\n% components are set to zero.\n%\n%This function can be useful when a large number of low-order binomial\n%values are needed. The recursion used to fill in the table is from [1].\n%\n%REFERENCES:\n%[1] Stover, Christopher and Weisstein, Eric W. \"Pascal's Triangle.\" From\n% MathWorld--A Wolfram Web Resource.\n% http://mathworld.wolfram.com/PascalsTriangle.html\n%\n%September 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n binomTable=zeros(maxDeg+1,maxDeg+1);\n binomTable(:,0+1)=1;%Boundary values.\n for n=1:maxDeg\n for k=1:(n-1)\n binomTable(n+1,k+1)=binomTable(n-1+1,k-1+1)+binomTable(n-1+1,k+1);\n end\n binomTable(n+1,n+1)=1;%Boundary value\n end\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/makeBinomTable.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.9136765245890102, "lm_q1q2_score": 0.8391938393034878}} {"text": "function [AnDartest] = AnDartest(x,alpha)\n%ANDARTEST Anderson-Darling test for assessing normality of a sample data.\n% The Anderson-Darling test (Anderson and Darling, 1952) is used to test if \n% a sample of data comes from a specific distribution. It is a modification\n% of the Kolmogorov-Smirnov (K-S) test and gives more weight to the tails\n% than the K-S test. The K-S test is distribution free in the sense that the\n% critical values do not depend on the specific distribution being tested.\n% The Anderson-Darling test makes use of the specific distribution in calculating\n% critical values. This has the advantage of allowing a more sensitive test\n% and the disadvantage that critical values must be calculated for each\n% distribution.\n% The Anderson-Darling test is only available for a few specific distributions.\n% The test is calculated as: \n% \n% AD2 = integral{[F_o(x)-F_t(x)]^2/[F_t(x)(1-F_t(x)0]}dF_t(x)\n%\n% AD2a = AD2*a\n%\n% Note that for a given distribution, the Anderson-Darling statistic may be\n% multiplied by a constant, a (which usually depends on the sample size, n).\n% These constants are given in the various papers by Stephens (1974, 1977a,\n% 1977b, 1979, 1986). This is what should be compared against the critical \n% values. Also, be aware that different constants (and therefore critical \n% values) have been published. You just need to be aware of what constant \n% was used for a given set of critical values (the needed constant is typically\n% given with the critical values). \n% The critical values for the Anderson-Darling test are dependent on the \n% specific distribution that is being tested. Tabulated values and formulas\n% have been published for a few specific distributions (normal, lognormal, \n% exponential, Weibull, logistic, extreme value type 1). The test is a one-sided\n% test and the hypothesis that the distribution is of a specific form is \n% rejected if the test statistic, AD2a, is greater than the critical value. \n% Here we develop the m-file for detecting departure from normality. It is \n% one of the most powerful statistics for test this.\n%\n% Syntax: function AnDartest(X) \n% \n% Input:\n% x - data vector\n% alpha - significance level (default = 0.05)\n%\n% Output:\n% - Complete Anderson-Darling normality test\n%\n% Example: From the Table 1 base data of secondary coating diameter, SCD \n% (micrometers) for an optical fiber manufacturing and testing [Application\n% and acceptance sampling in testing of optical fiber (Bhaumik and Bhargava,\n% 2005)], taked from Internet: \n% http://www.sterliteoptical.com/pdf/ProdWithContents/Application%20of%\n% 20acceptance%20sampling%20in%20testing%20of%20optical%20fiber.pdf\n% The measurements of the sample are analyzed for the normality using the\n% Anderson-Darling test with a significance of 0.05.\n% \n% Data vector is:\n% x=[245.3;245.6;245.0;244.7;244.6;244.6;245.9;245.2;245.5;246.1;246.5;246.7; \n% 246.0;245.8;245.3;245.3;246.0;245.5;246.7;245.3;245.8;245.8;245.2;245.7;\n% 244.8;246.7;246.5;245.5;246.0;244.8;244.8;244.4;244.8;245.6;245.5;244.0;\n% 245.2;244.8;245.4;246.1;245.9;245.6;245.2];\n%\n% Calling on Matlab the function: \n% AnDartest(x)\n%\n% Answer is:\n%\n% Sample size: 43\n% Anderson-Darling statistic: 0.2858\n% Anderson-Darling adjusted statistic: 0.2912\n% Probability associated to the Anderson-Darling statistic = 0.6088\n% With a given significance = 0.050\n% The sampled population is normally distributed.\n% Thus, this sample have been drawn from a normal population with a mean & variance = 245.4814 0.4139\n%\n% Created by A. Trujillo-Ortiz, R. Hernandez-Walls, K. Barba-Rojo and \n% A. Castro-Perez\n% Facultad de Ciencias Marinas\n% Universidad Autonoma de Baja California\n% Apdo. Postal 453\n% Ensenada, Baja California\n% Mexico.\n% atrujo@uabc.mx\n%\n% Copyright. April 20, 2007.\n%\n% To cite this file, this would be an appropriate format:\n% Trujillo-Ortiz, A., R. Hernandez-Walls, K. Barba-Rojo and A. Castro-Perez. (2007).\n% AnDartest:Anderson-Darling test for assessing normality of a sample data. \n% A MATLAB file. [WWW document]. URL http://www.mathworks.com/matlabcentral/\n% fileexchange/loadFile.do?objectId=14807\n%\n% References:\n% Anderson, T. W. and Darling, D. A. (1952), Asymptotic theory of certain \n% 'goodness-of-fit' criteria based on stochastic processes. Annals of\n% Mathematical Statistics, 23:193-212. \n% Stephens, M. A. (1974), EDF Statistics for goodness of fit and some \n% comparisons. Journal of the American Statistical Association, \n% 69:730-737.\n% Stephens, M. A. (1976), Asymptotic Results for goodness-of-fit statistics\n% with unknown parameters. Annals of Statistics, 4:357-369.\n% Stephens, M. A. (1977a), Goodness of fit for the extreme value distribution.\n% Biometrika, 64:583-588.\n% Stephens, M. A. (1977b), Goodness of fit with special reference to tests\n% for exponentiality. Technical Report No. 262, Department of Statistics,\n% Stanford University, Stanford, CA.\n% Stephens, M. A. (1979), Tests of fit for the logistic distribution based\n% on the empirical distribution function. Biometrika, 66:591-595.\n% Stephens, M. A. (1986), Tests based on EDF statistics. In: D'Agostino,\n% R.B. and Stephens, M.A., eds.: Goodness-of-Fit Techniques. Marcel \n% Dekker, New York. \n%\n\nswitch nargin\n case{2}\n if isempty(x) == false && isempty(alpha) == false\n if (alpha <= 0 || alpha >= 1)\n fprintf('Warning: Significance level error; must be 0 < alpha < 1 \\n');\n return;\n end\n end\n case{1}\n alpha = 0.05;\n otherwise \n error('Requires at least one input argument.');\nend\n\nn = length(x);\n\nif n < 7,\n disp('Sample size must be greater than 7.');\n return,\nelse\n x = x(:);\n x = sort(x);\n fx = normcdf(x,mean(x),std(x));\n i = 1:n;\n \n S = sum((((2*i)-1)/n)*(log(fx)+log(1-fx(n+1-i))));\n AD2 = -n-S;\n \n AD2a = AD2*(1 + 0.75/n + 2.25/n^2); %correction factor for small sample sizes: case normal\n \n if (AD2a >= 0.00 && AD2a < 0.200);\n P = 1 - exp(-13.436 + 101.14*AD2a - 223.73*AD2a^2);\n elseif (AD2a >= 0.200 && AD2a < 0.340);\n P = 1 - exp(-8.318 + 42.796*AD2a - 59.938*AD2a^2);\n elseif (AD2a >= 0.340 && AD2a < 0.600);\n P = exp(0.9177 - 4.279*AD2a - 1.38*AD2a^2);\n else (AD2a >= 0.600 && AD2a <= 13);\n P = exp(1.2937 - 5.709*AD2a + 0.0186*AD2a^2);\n end\nend\n\ndisp(' ')\nfprintf('Sample size: %i\\n', n);\nfprintf('Anderson-Darling statistic: %3.4f\\n', AD2);\nfprintf('Anderson-Darling adjusted statistic: %3.4f\\n', AD2a);\nfprintf('Probability associated to the Anderson-Darling statistic = %3.4f\\n', P);\nfprintf('With a given significance = %3.3f\\n', alpha);\nif P >= alpha;\n disp('The sampled population is normally distributed.');\n s = [mean(x),var(x)];\n fprintf('Thus, this sample have been drawn from a normal population with a mean & variance = %6.4f %8.4f\\n',s);\nelse\n disp('The sampled population is not normally distributed.');\nend\n\nreturn,", "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/14807-andartest/AnDartest.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012732322215, "lm_q2_score": 0.8872045937171068, "lm_q1q2_score": 0.8391192343551154}} {"text": "function variance = i4row_variance ( m, n, a )\n\n%*****************************************************************************80\n%\n%% I4ROW_VARIANCE returns the variances of an I4ROW.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 04 November 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns of data in TABLE.\n%\n% Input, integer A(M,N), the array.\n%\n% Output, real VARIANCE(M), the variance of each row of TABLE.\n%\n for i = 1 : m\n\n mean = sum ( a(i,1:n) ) / n;\n\n variance(i) = 0.0;\n for j = 1 : n\n variance(i) = variance(i) + ( a(i,j) - mean )^2;\n end\n\n if ( 1 < n )\n variance(i) = variance(i) / ( n - 1 );\n else\n variance(i) = 0.0\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/i4lib/i4row_variance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810466522862, "lm_q2_score": 0.8856314632529871, "lm_q1q2_score": 0.8390304626048106}} {"text": "% Compute the link density of a graph, defined as the number of edges divided by \n% number_of_nodes(number_of_nodes-1)/2 where the latter is the maximum possible number of edges.\n%\n% Inputs: adjacency matrix, nxn\n% Outputs: link density, a float between 0 and 1\n%\n% Note 1: The graph has to be non-trivial (more than 1 node).\n% Note 2: Routine works for both directed and undirected graphs.\n%\n% Other routines used: numNodes.m, numEdges.m, isDirected.m\n% GB: last update Sep 19, 2012\n\n\nfunction d=linkDensity(adj)\n\nn = numNodes(adj);\n\ncoeff = 2;\nif isDirected(adj); coeff = 1; end\n\nd = coeff*numEdges(adj)/(n*(n-1));", "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/linkDensity.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9525741295151718, "lm_q2_score": 0.8807970795424088, "lm_q1q2_score": 0.8390245113246156}} {"text": "% Script file: calc_decay.m\n%\n% Purpose: \n% This program calculates the amount of Thorium 227 and\n% Radium 223 left as a function of time, given an inital\n% concentration of 1 gram of Thorium 227 and no grams of\n% Radium 223.\n%\n% Record of revisions:\n% Date Programmer Description of change\n% ==== ========== =====================\n% 03/15/07 S. J. Chapman Original code \n%\n% Define variables:\n% odefun_handle -- Handle to function that defines the derivative\n% tspan -- Duration to solve equation for\n% yo -- Initial condition for equation\n% t -- Array of solution times \n% y -- Array of solution values\n\n% Get a handle to the function that defines the derivative.\nodefun_handle = @decay1;\n\n% Solve the equation over the period 0 to 100 days\ntspan = [0 100];\n\n% Set the initial conditions\ny0(1) = 1000000; % Atoms of Thorium 227\ny0(2) = 0; % Atoms of Radium 223\n\n% Call the differential equation solver.\n[t,y] = ode45(odefun_handle,tspan,y0);\n\n% Plot the result\nfigure(1);\nplot(t,y(:,1),'b-','LineWidth',2);\nhold on;\nplot(t,y(:,2),'k--','LineWidth',2);\ntitle('\\bfAmount of Thorium 227 and Radium 223 vs Time');\nxlabel('\\bfTime (days)');\nylabel('\\bfNumber of Atoms');\nlegend('Thorium 227','Radium 223');\ngrid on;\nhold off;\n\n\n", "meta": {"author": "101Hub", "repo": "Matlab101", "sha": "07273f68f1147a110443aeb121fa10962234f298", "save_path": "github-repos/MATLAB/101Hub-Matlab101", "path": "github-repos/MATLAB/101Hub-Matlab101/Matlab101-07273f68f1147a110443aeb121fa10962234f298/assets/《Matlab编程》源码/chap7/calc_decay.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172659321806, "lm_q2_score": 0.8840392802184581, "lm_q1q2_score": 0.8388801367615522}} {"text": "function [J, grad] = costFunction(theta, X, y)\n%COSTFUNCTION Compute cost and gradient for logistic regression\n% J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the\n% parameter for logistic regression and the gradient of the cost\n% w.r.t. to the parameters.\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n% Note: grad should have the same dimensions as theta\n%\nz=X*theta;\nh=sigmoid(z);\n%logisf=-y*log(h)-(1-y)*log(1-h);\n%logisf=log(h)*(-y)-log(1-h)*(1-y);\nlogisf=(-y)'*log(h)-(1-y)'*log(1-h);\nJ=(1/m)*sum(logisf);\t\t% sum will only work for a column, will not sum over a row\n\ngrad=1/m*((X'*h-X'*y)');\n\n\n\n% =============================================================\n\nend\n", "meta": {"author": "yhyap", "repo": "machine-learning-coursera", "sha": "fb33f0ad54ff2104660c86b0d26456b15029a798", "save_path": "github-repos/MATLAB/yhyap-machine-learning-coursera", "path": "github-repos/MATLAB/yhyap-machine-learning-coursera/machine-learning-coursera-fb33f0ad54ff2104660c86b0d26456b15029a798/mlclass-ex2/costFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172630429474, "lm_q2_score": 0.8840392802184581, "lm_q1q2_score": 0.8388801342073565}} {"text": "function result = fit_ML_normal( x,hAx )\n% fit_ML_normal - Maximum Likelihood fit of the normal distribution of i.i.d. samples!.\n% Given the samples of a normal distribution, the PDF parameter is found\n%\n% fits data to the probability of the form: \n% p(r) = sqrt(1/2/pi/sig^2)*exp(-((r-u)^2)/(2*sig^2))\n% with parameters: u,sig^2\n%\n% format: result = fit_ML_normal( x,hAx )\n%\n% input: x - vector, samples with normal distribution to be parameterized\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% sig^2,u - fitted parameters\n% CRB_sig2,CRB_u - Cram?r-Rao Bound for the estimator value\n% RMS - RMS error of the estimation \n% type - 'ML'\n%\n% example: fit_ML_normal( randn(1,10000)*3 - 1 )\n% or\n% figure; \n% fit_ML_normal( randn(1,10000)*3 - 1,gca );\n%\n\n%\n% Algorithm\n% ===========\n%\n% We use the ML algorithm to estimate the PDF from the samples.\n% The normal destribution is given by:\n%\n% p(x;u,sig^2) = sqrt(1/2/pi/sig^2)*exp(-((x-u).^2)/(2*sig^2))\n%\n% where x are the samples which distribute by the function p(x;u,sig^2)\n% and are assumed to be i.i.d !!!\n%\n% The ML estimator is given by:\n%\n% a = parameters vector = [u,sig^2]\n% f(Xn,a) = sqrt(1/2/pi/sig^2)*exp(-((Xn-u).^2)/(2*sig^2))\n% L(a) = f(X,a) = product_by_n( f(Xn,a) )\n% = (2*pi*sig^2)^(-N/2)*exp(-sum((Xn-u)^2)/(2*sig^2))\n% log(L(a)) = -N/2*log(2*pi) - N/2*log(sig^2) - sum((Xn-u)^2)/(2*sig^2)\n%\n% The maximum likelihood point is found by the derivative of log(L(a)) with respect to \"a\":\n%\n% diff(log(L(a)),u) = -2*sum(Xn-u)/(2*sig^2) = N/sig^2 * ( u - sum(Xn)/N )\n% = J(u) * (u_estimation - u) \n% diff(log(L(a)),sig^2) = -N/(2*sig^2) + sum((Xn-u)^2)/(2*sig^4)\n% = N/(2*sig^4) * ( sum((Xn-u)^2)/N - sig^2 )\n% = J(sig^2) * (sig^2_estimator - sig^2)\n%\n% Therefore, the (efficient) estimators are given by:\n%\n% u = sum(Xn)/N\n% sig^2 = sum((Xn-u)^2)/N\n%\n% The Cram?r-Rao Bounds for these estimator are:\n%\n% VAR( u ) = 1/J(u) = (sig^2) / N\n% VAR( sig^2 ) = 1/J(sig^2) = (2*sig^4) / N\n%\n% NOTE: the ML estimator does not detect a deviation from the model.\n% therefore, check the RMS value !\n%\n\nif (nargin<1)\n error( 'fit_ML_normal - insufficient input arguments' );\nend\n\n% Estimation\n% =============\nx = x(:); % should be column vectors !\nN = length(x);\nu = sum(x)/N;\nsig2 = (x-u)'*(x-u)/N;\nCRB_u = sig2 / N;\nCRB_sig2= (2*sig2^2) / N;\n[n,x_c] = hist( x,100 );\nn = n / sum(n*abs(x_c(2)-x_c(1)));\ny = sqrt(1/2/pi/sig2)*exp(-((x_c-u).^2)/(2*sig2));\nRMS = sqrt( (y-n)*((y-n)')/ (x_c(2)-x_c(1))^2 / (length(x_c)-1) );\n\n% finish summarizing results\n% ============================\nresult = struct( 'u',u,'sig2',sig2,'CRB_u',CRB_u,'CRB_sig2',CRB_sig2,'RMS',RMS,'type','ML' );\n\n% plot distribution if asked for\n% ===============================\nif (nargin>1)\n xspan = linspace(min(x),max(x),100);\n if ishandle( hAx )\n plot_normal( xspan,result,hAx,1 );\n else\n figure;\n plot_normal( xspan,result,gca,1 );\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_ML_normal.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109770159683, "lm_q2_score": 0.8824278540866547, "lm_q1q2_score": 0.8386691189486019}} {"text": "function f = beale ( x )\n\n%*****************************************************************************80\n%\n%% BEALE computes the Beale function.\n%\n% Discussion:\n%\n% This function has a global minimizer:\n%\n% X = ( 3.0, 0.5 )\n%\n% for which\n%\n% F(X) = 0.\n%\n% For a relatively easy computation, start the search at\n%\n% X = ( 1.0, 1.0 )\n%\n% A harder computation starts at\n%\n% X = ( 1.0, 4.0 )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 January 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Evelyn Beale,\n% On an Iterative Method for Finding a Local Minimum of a Function\n% of More than One Variable,\n% Technical Report 25, \n% Statistical Techniques Research Group,\n% Princeton University, 1958.\n%\n% Richard Brent,\n% Algorithms for Minimization with Derivatives,\n% Dover, 2002,\n% ISBN: 0-486-41998-3,\n% LC: QA402.5.B74.\n%\n% Parameters:\n%\n% Input, real X(N,2), the argument of the function.\n%\n% Output, real F, the value of the function at X.\n%\n f1 = 1.5 - x(:,1) .* ( 1.0 - x(:,2) );\n f2 = 2.25 - x(:,1) .* ( 1.0 - x(:,2).^2 );\n f3 = 2.625 - x(:,1) .* ( 1.0 - x(:,2).^3 );\n\n f = f1.^2 + f2.^2 + f3.^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/nelder_mead/beale.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.9032942151647514, "lm_q1q2_score": 0.8386262970605015}} {"text": "disp(\"Question 1\")\nA = [1 2; 3 4; 5 6]\nB = [1 2 3; 4 5 6]\n\nC = B' + A\n#C = A' * B\n#C = B + A\nC = A * B\n\ndisp(\"Question 2\")\n\nA = [16,2,3,13;5,11,10,8;9,7,6,12;4,14,15,1]\n\n#B = A(:, 0:2) \nB = A(:, 1:2)\nB = A(1:4, 1:2)\n#B = A(0:4, 0:2)\n\ndisp(\"Question 3\")\nA = ones(10,10);\nx = ones(10,1);\n\nv = zeros(10, 1);\n\nfor i = 1:10\n\t for j = 1:10 \n\t v(i) = v(i) + A(i, j) * x(j);\n\t end\nend\n\nv\n\n\nv = zeros(10, 1);\nv = A * x\n \nv = zeros(10, 1); \nv = sum (A * x)\n \nv = zeros(10, 1) \nv = A .* x;\n \nv = zeros(10, 1)\n#v = Ax;\n\ndisp(\"Question 4\")\nv = ones(7,1);\nw = ones(7,1);\n\n\nz = 0;\nfor i = 1:7\n z = z + v(i) * w(i);\nend\n\nz\n\nz = v' * w\n \n#z = v * w\n \nz = sum (v .* w)\n \nz = v .* w\n\ndisp(\"Question 4\")\nX = ones(7,7)\n\nfor i = 1:7\n for j = 1:7\n \tA(i, j) = log (X(i, j));\n\t B(i, j) = X(i, j) ^ 2;\n \tC(i, j) = X(i, j) + 1;\n\t D(i, j) = X(i, j) / 4;\n end\nend\n\nA\nB\nC\nD\n\n\nB = X .^ 2\n \nC = X + 1\n \nD = X / 4\n \nB = X ^ 2", "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/quiz/week2_quiz5.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107861416413, "lm_q2_score": 0.8947894562828415, "lm_q1q2_score": 0.8386063297540937}} {"text": "function volume = torus_volume_3d ( r1, r2 )\n\n%*****************************************************************************80\n%\n%% TORUS_VOLUME_3D computes the volume of a torus in 3D.\n%\n% Discussion:\n%\n% A torus with radii R1 and R2 is the set of points (X,Y,Z)\n% satisfying:\n%\n% ( sqrt ( X**2 + Y**2 ) - R1 )**2 + Z**2 <= R2**2\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 February 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R1, R2, the \"inner\" and \"outer\" radii of the\n% torus.\n%\n% Output, real VOLUME, the volume of the torus.\n%\n volume = 2.0 * pi * pi * r1 * r2 * 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/geometry/torus_volume_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951863227517834, "lm_q2_score": 0.8807970904940926, "lm_q1q2_score": 0.8383983613460247}} {"text": "function [J, grad] = costFunction(theta, X, y)\n%COSTFUNCTION Compute cost and gradient for logistic regression\n% J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the\n% parameter for logistic regression and the gradient of the cost\n% w.r.t. to the parameters.\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n% Note: grad should have the same dimensions as theta\n%\n\n\nJ = (1 / m) * sum( -y'*log(sigmoid(X*theta)) - (1-y)'*log( 1 - sigmoid(X*theta)) );\n\ngrad = (1 / m) * sum( X .* repmat((sigmoid(X*theta) - y), 1, size(X,2)) );\n\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 3 Assignments/Logistic Regression and Regularization/mlclass-ex2/costFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542840900507, "lm_q2_score": 0.8740772335247532, "lm_q1q2_score": 0.8383749231608467}} {"text": "function x=realCepstrum(x,N)\n%%REALCEPSTRUM Compute the real cepstrum. The real cepstrum is the inverse\n% Fourier transform of the real logarithm of the magnitude of\n% the Fourier transform of a real sequence. The cepstrum is\n% often used in signal identification. The real cepstrum plays\n% a role in the design of certain filters.\n%\n%INPUTS: x An xDimX1 or 1XxDim real sequence.\n% N The length of the discrete Fourier transforms to use in the\n% computation of the cepstrum. If this parameter is omitted or an\n% empty matrix is passed, then the default of N=length(x) is used.\n%\n%OUTPUTS: x The real cepstrum of the input signal x. This will be length-N.\n%\n%The computation of the real cepstrum is described in [1]. However, the\n%implementation here is more straighforward.\n%\n%REFERENCES:\n%[1] T. F. Quatieri and J. M. Tribolet, \"Computation of the real cepstrum\n% and minimum-phase reconstruction,\" in Programs for Digital Signal\n% Processing, Digital Signal Processing Committee, IEEE Acoustics,\n% Speech, and Signal Processing Society, Ed. New York: IEEE Press, 1979,\n% ch. 7.2.\n%\n%January 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<2||isempty(N))\n N=length(x);\nend\n\nif(~isreal(x))\n error('The input must be real')\nend\n\n%The ifft should be real; this just deals with any possible finite\n%precision issues.\nx=real(ifft(log(abs(fft(x,N))),N));\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/Signal_Processing/realCepstrum.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966747198242, "lm_q2_score": 0.8856314692902447, "lm_q1q2_score": 0.8383358038573778}} {"text": "function phin = phi ( n )\n\n%*****************************************************************************80\n%\n%% PHI computes the number of relatively prime predecessors of an integer.\n%\n% Definition:\n%\n% PHI(N) is the number of integers between 1 and N which are\n% relatively prime to N. I and J are relatively prime if they\n% have no common factors. The function PHI(N) is known as\n% \"Euler's totient function\".\n%\n% By convention, 1 and N are relatively prime.\n%\n% First values:\n%\n% N PHI(N)\n%\n% 1 1\n% 2 1\n% 3 2\n% 4 2\n% 5 4\n% 6 2\n% 7 6\n% 8 4\n% 9 6\n% 10 4\n% 11 10\n% 12 4\n% 13 12\n% 14 6\n% 15 8\n% 16 8\n% 17 16\n% 18 6\n% 19 18\n% 20 8\n%\n% Formula:\n%\n% PHI(U*V) = PHI(U) * PHI(V) if U and V are relatively prime.\n%\n% PHI(P^K) = P^(K-1) * ( P - 1 ) if P is prime.\n%\n% PHI(N) = N * Product ( P divides N ) ( 1 - 1 / P )\n%\n% N = Sum ( D divides N ) PHI(D).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 July 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the value to be analyzed.\n%\n% Output, integer PHIN, the value of PHI(N). If N is less than\n% or equal to 0, PHI will be returned as 0. If there is not enough\n% room for full factoring of N, PHI will be returned as -1.\n%\n if ( n <= 0 )\n phin = 0;\n return\n end\n\n if ( n == 1 )\n phin = 1;\n return\n end\n%\n% Factor N.\n%\n [ nfactor, factor, power, nleft ] = i4_factor ( n );\n\n if ( nleft ~= 1 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PHI - Fatal error!\\n' );\n fprintf ( 1, ' Not enough factorization space.\\n' );\n error ( 'PHI - Fatal error!' );\n end\n\n phin = 1;\n for i = 1 : nfactor\n phin = phin * factor(i)^( power(i) - 1 ) * ( factor(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/polpak/phi.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465134460243, "lm_q2_score": 0.8962513814471134, "lm_q1q2_score": 0.8383056048077402}} {"text": "function diftab = dif_basis_i ( ival, ntab, xtab )\n\n%*****************************************************************************80\n%\n%% DIF_BASIS_I computes the I-th Lagrange basis polynomial in divided difference 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% 05 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Carl deBoor,\n% A Practical Guide to Splines,\n% Springer, 2001,\n% ISBN: 0387953663,\n% LC: QA1.A647.v27.\n%\n% Parameters:\n%\n% Input, integer IVAL, the index of the desired Lagrange basis polynomial.\n% IVAL should be between 1 and NTAB.\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 DIFTAB(NTAB), the divided difference table\n% for the IVAL-th Lagrange basis polynomial.\n%\n\n%\n% Check IVAL.\n%\n if ( ival < 1 | ntab < ival )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'DIF_BASIS_I - Fatal error!\\n' );\n fprintf ( 1, ' IVAL must be between 1 and %d\\n', ntab );\n fprintf ( 1, ' but your value is %d\\n', ival );\n error ( 'DIF_BASIS_I - Fatal error!' );\n end\n%\n% Initialize DIFTAB to Delta(I,J).\n%\n diftab(1:ntab) = 0.0;\n diftab(ival) = 1.0;\n%\n% Compute the IVAL-th Lagrange basis polynomial.\n%\n diftab = data_to_dif ( ntab, xtab, diftab );\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/dif_basis_i.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465098415278, "lm_q2_score": 0.8962513752119936, "lm_q1q2_score": 0.8383055957452078}} {"text": "function y = gauss(mu, covar, x)\n%GAUSS\tEvaluate a Gaussian distribution.\n%\n%\tDescription\n%\n%\tY = GAUSS(MU, COVAR, X) evaluates a multi-variate Gaussian density\n%\tin D-dimensions at a set of points given by the rows of the matrix X.\n%\tThe Gaussian density has mean vector MU and covariance matrix COVAR.\n%\n%\tSee also\n%\tGSAMP, DEMGAUSS\n%\n\n%\tCopyright (c) Ian T Nabney (1996-2001)\n\n[n, d] = size(x);\n\n[j, k] = size(covar);\n\n% Check that the covariance matrix is the correct dimension\nif ((j ~= d) | (k ~=d))\n error('Dimension of the covariance matrix and data should match');\nend\n \ninvcov = inv(covar);\nmu = reshape(mu, 1, d); % Ensure that mu is a row vector\n\nx = x - ones(n, 1)*mu;\nfact = sum(((x*invcov).*x), 2);\n\ny = exp(-0.5*fact);\n\ny = y./sqrt((2*pi)^d*det(covar));\n", "meta": {"author": "bayesnet", "repo": "bnt", "sha": "bebba5f437b4e1e29169f0f3669df59fb5392e62", "save_path": "github-repos/MATLAB/bayesnet-bnt", "path": "github-repos/MATLAB/bayesnet-bnt/bnt-bebba5f437b4e1e29169f0f3669df59fb5392e62/netlab3.3/gauss.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551525886193, "lm_q2_score": 0.868826769445233, "lm_q1q2_score": 0.8382919852061574}} {"text": "function [lat, lon, sphrad] = proj_on_sphere(x)\n% PROJ_ON_SPHERE Project a point configuration onto a sphere\n%\n% [LAT, LON, SPHRAD] = proj_on_sphere(X)\n%\n% X is a 3-row matrix. Each colum has the (x,y,z)-coordinates of a point.\n%\n% LAT, LON are vectors with the latitude and longitude of the points in X\n% projected onto a sphere. The centre of the sphere is the centroid of X.\n%\n% SPHRAD is the median of the distance of the points in X to the\n% centroid. It can be used as the radius of the sphere that best contains\n% the projection of X in terms of distances between the the points.\n\n% Author: Ramon Casero \n% Copyright © 2013 University of Oxford\n% Version: 0.1.1\n%\n% University of Oxford means the Chancellor, Masters and Scholars of\n% the University of Oxford, having an administrative office at\n% Wellington Square, Oxford OX1 2JD, UK. \n%\n% This file is part of Gerardus.\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. The offer of this\n% program under the terms of the License is subject to the License\n% being interpreted in accordance with English Law and subject to any\n% action against the University of Oxford being under the jurisdiction\n% of the English Courts.\n%\n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see\n% .\n\n% check arguments\nnarginchk(1, 1);\nnargoutchk(0, 3);\n\nif (size(x, 2) ~= 3)\n error('X must be a matrix with 3-columns')\nend\n\n% project 3D Cartesian coordinates onto\n% the surface of a sphere lon, lat given in radians, centered around 0\n[lon, lat, r] = cart2sph(...\n x(:, 1) - mean(x(:, 1)), ...\n x(:, 2) - mean(x(:, 2)), ...\n x(:, 3) - mean(x(:, 3)));\n\n% we use the median radius of the points in the configuration as the radius\n% of the sphere that best can contains their projections\nsphrad = median(r);\n", "meta": {"author": "vigente", "repo": "gerardus", "sha": "4d7c5195b826967781f1bb967872410e66b7cd3d", "save_path": "github-repos/MATLAB/vigente-gerardus", "path": "github-repos/MATLAB/vigente-gerardus/gerardus-4d7c5195b826967781f1bb967872410e66b7cd3d/matlab/ManifoldToolbox/proj_on_sphere.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545348152283, "lm_q2_score": 0.8840392924390585, "lm_q1q2_score": 0.8382058640809391}} {"text": "function pdf = angle_pdf ( x, n )\n\n%*****************************************************************************80\n%\n%% ANGLE_PDF evaluates the Angle PDF.\n%\n% Discussion:\n%\n% X is an angle between 0 and PI, corresponding to the angle\n% made in an N-dimensional space, between a fixed line passing\n% through the origin, and an arbitrary line that also passes\n% through the origin, which is specified by a choosing any point\n% on the N-dimensional sphere with uniform probability.\n%\n% Formula:\n%\n% PDF(X) = ( sin ( X ) )**(N-2) * Gamma ( N / 2 )\n% / ( sqrt ( PI ) * Gamma ( ( N - 1 ) / 2 ) )\n%\n% PDF(X) = 1 / PI if N = 2.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Reuven Rubinstein,\n% Monte Carlo Optimization, Simulation and Sensitivity of Queueing Networks,\n% Wiley, 1986.\n%\n% Parameters:\n%\n% Input, real X, the argument of the PDF.\n%\n% Input, integer N, the spatial dimension.\n% N must be at least 2.\n%\n% Output, real PDF, the value of the PDF.\n%\n if ( n < 2 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, '\\ANGLE_PDF - Fatal error!\\n' );\n fprintf ( 1, '\\ N must be at least 2.\\n' );\n fprintf ( 1, '\\ The input value of N = %d\\n', n );\n error ( 'ANGLE_PDF - Fatal error!' );\n end\n\n if ( x < 0.0 | pi < x )\n pdf = 0.0;\n elseif ( n == 2 )\n pdf = 1.0 / pi;\n else\n pdf = ( sin ( x ) )^( n - 2 ) * gamma ( n / 2.0 ) ...\n / ( sqrt ( pi ) * gamma ( ( n - 1 ) / 2.0 ) );\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/prob/angle_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545274901876, "lm_q2_score": 0.8840392817460332, "lm_q1q2_score": 0.8382058474666749}} {"text": "function volume = simplex_unit_volume_nd ( dim_num )\n\n%*****************************************************************************80\n%\n%% SIMPLEX_UNIT_VOLUME_ND computes the volume of the unit simplex in ND.\n%\n% Discussion:\n%\n% The formula is simple: volume = 1/N!.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 February 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the dimension of the space.\n%\n% Output, real VOLUME, the volume of the cone.\n%\n volume = 1.0;\n for i = 1 : dim_num\n volume = volume / 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/quadrature_test/simplex_unit_volume_nd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.93812402119614, "lm_q2_score": 0.8933093996634686, "lm_q1q2_score": 0.8380350061846029}} {"text": "function value = torus_area_3d ( r1, r2 )\n\n%*****************************************************************************80\n%\n%% TORUS_AREA_3D returns the area of a torus in 3D.\n%\n% Integration region:\n%\n% Points (X,Y,Z) such that:\n%\n% ( SQRT ( X*X + Y*Y ) - R1 )**2 + Z*Z = R2*R2.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 20 May 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R1, R2, the two radii that define the torus.\n%\n% Output, real TORUS_AREA_3D, the area of the torus.\n%\n value = 4.0E+00 * pi * pi * r1 * 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/stroud/torus_area_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9546474168650672, "lm_q2_score": 0.8774767826757123, "lm_q1q2_score": 0.8376809439404387}} {"text": "function val=intPowSin(u,n)\n%%INTPOWSIN Evaluate the integral of u^n*sin(u) du. A definite integral\n% can be evaluated, or an indefinite integral (with a particular\n% additive constant).\n%\n%INPUTS: u A 2XN (for definite integral) or a 1XN (for indefinite\n% integrals) set of N points. For definite integrals, u(1,:) are\n% the real lower bounds and u(2,:) are the real upper bounds. For\n% indefinite integrals, the integral is evaluated at the points in\n% u. The values in u should be real.\n% n The positive integer exponent of coefficient multiplying the\n% sine term.\n%\n%OUTPUTS: val The 1XN set of values of the integral of u^n*sin(u).\n%\n%This function simply implements the recursion that arises from integration\n%by parts from basic calculus, as are given in the tables in the back of\n%[1].\n%\n%REFERENCES:\n%[1] J. Stewart, Calculus, 7th ed. Belmont, CA: Brooks/Cole, 2012.\n%\n%October 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nnumDim=size(u,1);\n\nif(isempty(u))\n val=[];\n return;\nend\n\nif(numDim==1)%An indefinite integral\n val=indefIntPowSin(u,n);\nelse%A definite integral\n val=indefIntPowSin(u(2,:),n)-indefIntPowSin(u(1,:),n);\nend\n\nend\n\nfunction val=indefIntPowSin(u,n)\n\nif(n==0)\n val=-cos(u);\n return;\nelseif(n==1)\n val=sin(u)-u*cos(u);\n return;\nend\n\n%If here, n>=1\ncosVal=cos(u);\nsinVal=sin(u);\n\nval=0;\nif(mod(n,2)==0)%If n is even\n endVal=2;\nelse\n endVal=3;\nend\n\ncoeffProd=1;\nfor k=n:-2:endVal\n %Do a sine step and a cosine step together!!!\n val=val-coeffProd*u.^k.*cosVal;\n coeffProd=coeffProd*k;\n val=val+coeffProd*u.^(k-1).*sinVal;\n coeffProd=-coeffProd*(k-1);\nend\n\nif(endVal==2)\n %The final integral is over u^0*sin(u)\n val=val-coeffProd*cosVal;\nelse%The final integral is over u^1*sin(u)\n val=val+coeffProd*(sinVal-u.*cosVal);\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/Specific_Integrals/intPowSin.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.9086179000259899, "lm_q1q2_score": 0.8376746776757137}} {"text": "function pagerankdemo (steps)\n% PAGERANKDEMO draw a 6-node web and compute its pagerank\n%\n% PAGERANKDEMO draws the 6-node \"tiny web\" in Section 2.11 of \"Numerical\n% Computing with MATLAB\", by Cleve Moler, SIAM, 2004. It then simulates the\n% computation of Google's PageRank algorithm, by randomly selecting links to\n% traverse. If a link is traversed, the edge and the target node are displayed\n% in red. If the \"random surfer\" jumps to an arbitrary page, the target node\n% is displayed in blue. The number of hits at each node, and the page rank\n% (in %) are displayed % on each node. Note that after a large number of\n% steps, the PageRanks (in percentages) converge to the values given in Section\n% 2.11 of Moler (alpha: .321, sigma: .2007, beta: .1705, delta: .1368,\n% gamma: .1066, rho: .0643). See http://www.mathworks.com/moler for more\n% details (the pagerank M-file, in particular).\n%\n% Note that this method is NOT how the PageRank is actually computed. Instead\n% the eigenvalue problem A*x=x is solved for x, where A is the Markov\n% transition matrix, A = p*G*D + e*z', where G is the binary matrix used here.\n% The method here is a simplistic random-hopping demonstration of the Markov\n% process, to motivate the A*x=x formulation of the problem. In this example,\n% A does control how the transitions are made, but the matrix A is not formed\n% explicitly.\n%\n% This demo only operates on a single graph. It is meant as a simple demo\n% only, suitable for in-class use. To compute the PageRanks for an arbitrary\n% graph, use pagerank.m, or the power method (repeat x=A*x until convergence,\n% where A is the Markov transition matrix of the web).\n%\n% Example:\n% pagerankdemo\n% pagerankdemo (1000) % run 1000 steps with no user input, then quit\n%\n% See also pagerank\n%\n% I suggest single-stepping a dozen times or so to see the link traversal in\n% process, and then type \"1000\". Hit control-C to quit.\n%\n% Copyright 2007, Tim Davis, University of Florida\n\n% Initial graph\nGraph = graphinit ;\nrand ('state', 0) ;\nn = size (Graph.G, 1) ;\n\nhelp pagerankdemo\n\n% initialize the page counts\nhits = zeros (1,n) ;\noldwhere = 1 ;\nwhere = 1 ;\nhits (where) = 1 ;\nset (Graph.node (where), 'FaceColor', [0 0 1]) ;\n\np = 0.85 ;\t\t% probability a link will be followed\nc = sum (Graph.G) ;\t% outgoing degree\n\nlinks = cell (1,n) ;\nfor k = 1:n\n links {k} = find (Graph.G (:,k)) ;\nend\n\nfollow_link = 0 ;\nif (nargin < 1)\n input ('hit enter to start at node alpha: ') ;\nend\n\n% write the stats to the figure\nset (Graph.nodelabel (where), 'string', ...\n\tsprintf ('%s %d (%3.1f%%)', Graph.nodes {where}, hits (where), ...\n\t100 * hits (where) / sum (hits))) ;\n\nif (nargin < 1)\n input ('hit enter to take one step: ') ;\n steps = 1 ;\nend\n\n% repeat\nwhile (1)\n\n % clear the old color and old arrow\n set (Graph.node (where), 'FaceColor', [0 1 0]) ;\n if (follow_link)\n\tset (Graph.arrows (where,oldwhere), 'LineWidth', 2) ;\n\tset (Graph.arrows (where,oldwhere), 'Color', [0 0 0]) ;\n end\n\n % determine where to go to next\n oldwhere = where ;\n if (c (where) == 0 || rand > p)\n\t% no outgoing links, or ignore the links\n\tfollow_link = 0 ;\n\twhere = floor (n * rand + 1) ;\n\tset (Graph.node (where), 'FaceColor', [0 0 1]) ;\n else\n\t% move along the link\n\tfollow_link = 1 ;\n\twhere = links{where}(floor (c (where) * rand + 1)) ;\n\tset (Graph.node (where), 'FaceColor', [1 0 0]) ;\n\tset (Graph.arrows (where,oldwhere), 'LineWidth', 5) ;\n\tset (Graph.arrows (where,oldwhere), 'Color', [1 0 0]) ;\n end\n\n % increment the hit count\n hits (where) = hits (where) + 1 ;\n\n % write the stats to the figure\n for k = 1:n\n\tset (Graph.nodelabel (k), 'string', ...\n\tsprintf ('%s %d (%3.1f%%)', Graph.nodes {k}, hits (k), ...\n\t100 * hits (k) / sum (hits))) ;\n end\n\n drawnow\n\n % go the next step\n steps = steps - 1 ;\n if (steps <= 0)\n if (nargin > 0)\n break ;\n end\n steps = input ...\n\t ('number of steps to make (default 1, control-C to quit): ') ;\n\tif (steps == 0)\n\t break ;\n\tend\n\tif (isempty (steps))\n\t steps = 1 ;\n\tend\n end\n\nend\n\n%-------------------------------------------------------------------------------\n\nfunction Graph = graphinit\n% GRAPHINIT create the tiny-web example in Moler, section 2.11, and draw it.\n% Example\n% G = graphinit ;\n\nfigure (1)\nclf\n\nnodes = { 'alpha', 'beta', 'gamma', 'delta', 'rho', 'sigma' } ;\n\nxy = [\n0 4\n1 3\n1 2\n2 4\n2 0\n0 0\n] ;\n\nx = xy (:,1) ;\ny = xy (:,2) ;\n\n% scale x and y to be in the range 0.1 to 0.9\nx = 0.8 * x / 2 + .1 ;\ny = 0.8 * y / 4 + .1 ;\nxy = [x y] ;\n\nxy_delta = [\n .08 .04 0\n-.03 -.02 -1\n .04 0 0\n-.05 .04 -1\n-.03 0 -1\n .03 0 0\n] ;\n\nxd = xy_delta (:,1) ;\nyd = xy_delta (:,2) ;\ntjust = xy_delta (:,3) ;\n\nG = [\n0 0 0 1 0 1\n1 0 0 0 0 0\n0 1 0 0 0 0\n0 1 1 0 0 0\n0 0 1 0 0 0\n1 0 1 0 0 0 ] ;\n\nclf\n\nn = size (G,1) ;\n\naxes ('Position', [0 0 1 1], 'Visible', 'off') ;\n\nnode = zeros (n,1) ;\nnodelabel = zeros (n,1) ;\nfor k = 1:n\n node (k) = annotation ('ellipse', [x(k)-.025 y(k)-.025 .05 .05]) ;\n set (node (k), 'LineWidth', 2) ;\n set (node (k), 'FaceColor', [0 1 0]) ;\n nodelabel (k) = text (x (k) + xd (k), y (k) + yd (k), nodes {k}, ...\n\t'Units', 'normalized', 'FontSize', 16) ;\n if (tjust (k) < 0) \n\tset (nodelabel (k), 'HorizontalAlignment', 'right') ;\n end\nend\n\n\naxis off\n\n% Yes, I realize that this is overkill; arrows should be sparse.\n% This example is not meant for large graphs.\narrows = zeros (n,n) ;\n\n[i j] = find (G) ;\nfor k = 1:length (i)\n % get the center of the two nodes\n figx = [x(j(k)) x(i(k))] ;\n figy = [y(j(k)) y(i(k))] ;\n% [figx figy] = dsxy2figxy (gca, axx, axy);\n % shorten the arrows by s units at each end\n s = 0.03 ;\n len = sqrt (diff (figx)^2 + diff (figy)^2) ;\n fy (1) = diff (figy) * (s/len) + figy(1) ;\n fy (2) = diff (figy) * (1-s/len) + figy(1) ;\n fx (1) = diff (figx) * (s/len) + figx(1) ;\n fx (2) = diff (figx) * (1-s/len) + figx(1) ;\n arrows (i(k),j(k)) = annotation ('arrow', fx, fy) ;\n set (arrows (i(k),j(k)), 'LineWidth', 2) ;\n set (arrows (i(k),j(k)), 'HeadLength', 20) ;\n set (arrows (i(k),j(k)), 'HeadWidth', 20) ;\nend\n\nGraph.G = G ;\nGraph.nodes = nodes ;\nGraph.node = node ;\nGraph.xy = xy ;\nGraph.xy_delta = xy_delta ;\nGraph.nodelabel = nodelabel ;\nGraph.arrows = arrows ;\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/dmlt/external/gpstuff/SuiteSparse/MATLAB_Tools/pagerankdemo.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.9086178913651384, "lm_q1q2_score": 0.8376746774878622}} {"text": "% Example 6.2: Robust regression using the Huber penalty\n% Section 6.1.2, Figure 6.5\n% Boyd & Vandenberghe \"Convex Optimization\"\n% Original by Lieven Vandenberghe\n% Adapted for CVX by Joelle Skaf - 09/07/05\n%\n% Compares the solution of regular Least-squares:\n% minimize sum(y_i - alpha - beta*t_i)^2\n% to the solution of the following:\n% minimize sum( phi_h (y_i - alpha - beta*t_i)^2 )\n% where phi_h is the Huber penalty function, (t_i,y_i) are data points in a\n% plane.\n\n% Input data\nrandn('seed',1);\nrand('seed',1);\n\nm=40; n=2;\nxex = [5;1];\npts = -10+20*rand(m,1);\nA = [ones(m,1) pts];\nb = A*xex + .5*randn(m,1);\noutliers = [-9.5; 9]; outvals = [20; -15];\nA = [A; ones(length(outliers),1), outliers];\nb = [b; outvals];\nm = size(A,1);\npts = [pts;outliers];\n\n% Least Squares\nfprintf(1,'Computing the solution of the least-squares problem...');\n\nxls = A\\b;\n\nfprintf(1,'Done! \\n');\n\n% Huber\nfprintf(1,'Computing the solution of the huber-penalized problem...');\n\ncvx_begin quiet\n variable xhub(n)\n minimize(sum(huber(A*xhub-b)))\ncvx_end\n\nfprintf(1,'Done! \\n');\n\n% Plots\nfigure(1); hold off\nplot(pts,b,'o', [-11; 11], [1 -11; 1 11]*xhub, '-', ...\n [-11; 11], [1 -11; 1 11]*xls, '--');\naxis([-11 11 -20 25])\ntitle('Least-square fit vs robust least-squares fit (Huber-penalized)');\nxlabel('x');\nylabel('y');\nlegend('Data points','Huber penalty','Regular LS','Location','Best');\n%print -deps robustls.eps\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/cvxbook/Ch06_approx_fitting/fig6_5.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294588, "lm_q2_score": 0.888758801595206, "lm_q1q2_score": 0.8376611468993489}} {"text": "function rz = vecrotz(angle) \n% \n% Function Name: \n% \n% vecrotz - Transformation matrix for a rotation around the z axis. \n% \n% Calling Sequence: \n% \n% rz = vecrotz(angle); \n% \n% Parameters: \n% \n% angle\t: rotation angle defined in radians \n% \n% rz\t\t: (4x4) Transformation matrix. \n% \n% \n% Description: \n% \n% Return the (4x4) Transformation matrix for a rotation about the z axis \n% by the defined angle. \n% \n% The matrix is: \n% \n% [ cos(angle) -sin(angle) 0 0] \n% [ -sin(angle) cos(angle) 0 0] \n% [ 0 0 1 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 z-axis \n% \n% line = nrbline([0.0 0.0 0.0],[3.0 3.0 3.0]); \n% trans = vecrotz(%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); \nrz = [cn -sn 0 0; sn cn 0 0; 0 0 1 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/vecrotz.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075690244281, "lm_q2_score": 0.8705972801594706, "lm_q1q2_score": 0.8376082328135072}} {"text": "function value = sin_power_int ( a, b, n )\n\n%*****************************************************************************80\n%\n%% SIN_POWER_INT evaluates the sine power integral.\n%\n% Discussion:\n%\n% The function is defined by\n%\n% SIN_POWER_INT(A,B,N) = Integral ( A <= T <= B ) ( sin ( t ))^n dt\n%\n% The algorithm uses the following fact:\n%\n% Integral sin^n ( t ) = (1/n) * (\n% sin^(n-1)(t) * cos(t) + ( n-1 ) * Integral sin^(n-2) ( t ) dt )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 02 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters\n%\n% Input, real A, B, the limits of integration.\n%\n% Input, integer N, the power of the sine function.\n%\n% Output, real SIN_POWER_INT, the value of the integral.\n%\n if ( n < 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'SIN_POWER_INT - Fatal error!\\n' );\n fprintf ( 1, ' Power N < 0.\\n' );\n value = 0.0;\n error ( 'SIN_POWER_INT - Fatal error!' );\n end\n\n sa = sin ( a );\n sb = sin ( b );\n ca = cos ( a );\n cb = cos ( b );\n\n if ( mod ( n, 2 ) == 0 )\n value = b - a;\n mlo = 2;\n else\n value = ca - cb;\n mlo = 3;\n end\n\n for m = mlo : 2 : n\n value = ( ( m - 1 ) * value + sa^(m-1) * ca - sb^(m-1) * cb ) / m;\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/stroud/sin_power_int.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897492587142, "lm_q2_score": 0.8902942297605357, "lm_q1q2_score": 0.8375796851828945}} {"text": "function a = jordan_inverse ( n, alpha )\n\n%*****************************************************************************80\n%\n%% JORDAN_INVERSE returns the inverse of the JORDAN matrix.\n%\n% Formula:\n%\n% if ( I <= J )\n% A(I,J) = -1 * (-1/ALPHA)^(J+1-I)\n% else\n% A(I,J) = 0\n%\n% Example:\n%\n% ALPHA = 2, N = 4\n%\n% 1/2 -1/4 1/8 -1/16\n% 0 1/2 -1/4 1/8\n% 0 0 1/2 -1/4\n% 0 0 0 1/2\n%\n% Properties:\n%\n% A is upper triangular.\n%\n% A is Toeplitz: constant along diagonals.\n%\n% A is generally not symmetric: A' /= A.\n%\n% A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\n%\n% The inverse of A is the Jordan block matrix, whose diagonal\n% entries are ALPHA, whose first superdiagonal entries are 1,\n% with all other entries zero.\n%\n% det ( A ) = (1/ALPHA)^N.\n%\n% LAMBDA(1:N) = 1 / ALPHA.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 13 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Input, real ALPHA, the eigenvalue of the Jordan matrix.\n%\n% Output, real A(N,N), the matrix.\n%\n a = zeros ( n, n );\n\n if ( alpha == 0.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'JORDAN_INVERSE - Fatal error!\\n' );\n fprintf ( 1, ' The input parameter ALPHA was 0.\\n' );\n error ( 'JORDAN_INVERSE - Fatal error!' );\n end\n\n for i = 1 : n\n for j = 1 : n\n\n if ( i <= j )\n a(i,j) = - ( - 1.0 / alpha )^(j+1-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/jordan_inverse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680097, "lm_q2_score": 0.8991213813246445, "lm_q1q2_score": 0.8374978559171932}} {"text": "function g = sigmoid(z)\n%SIGMOID Compute sigmoid function\n% g = SIGMOID(z) computes the sigmoid of z.\n\n% You need to return the following variables correctly \ng = zeros(size(z));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the sigmoid of each value of z (z can be a matrix,\n% vector or scalar).\n\ng = 1 ./ (1 + exp(-z));\n\n\n\n% =============================================================\n\nend\n", "meta": {"author": "JY-112553", "repo": "machine-learning", "sha": "db9c6e5a5175739821acd97787453472b8f46cac", "save_path": "github-repos/MATLAB/JY-112553-machine-learning", "path": "github-repos/MATLAB/JY-112553-machine-learning/machine-learning-db9c6e5a5175739821acd97787453472b8f46cac/machine-learning-ex2/ex2/sigmoid.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.9019206870747658, "lm_q1q2_score": 0.8373511032832284}} {"text": "function [mu sigma2] = estimateGaussian(X)\n%ESTIMATEGAUSSIAN This function estimates the parameters of a \n%Gaussian distribution using the data in X\n% [mu sigma2] = estimateGaussian(X), \n% The input X is the dataset with each n-dimensional data point in one row\n% The output is an n-dimensional vector mu, the mean of the data set\n% and the variances sigma^2, an n x 1 vector\n% \n\n% Useful variables\n[m, n] = size(X);\n\n% You should return these values correctly\nmu = zeros(n, 1);\nsigma2 = zeros(n, 1);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the mean of the data and the variances\n% In particular, mu(i) should contain the mean of\n% the data for the i-th feature and sigma2(i)\n% should contain variance of the i-th feature.\n%\n\n\n\nmu = 1/m * sum(X);\n\nsigma2 = 1/m * sum((X - repmat(mu, m, 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 9 Assignments/Anomaly Detection and Recommender Systems/mlclass-ex8/estimateGaussian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660976007596, "lm_q2_score": 0.877476800298183, "lm_q1q2_score": 0.8370831189156587}} {"text": "function [hyperplane_normal, hyperplane_offset] = linortfitn(data)\n% LINORTFITN Fit a line to data by ORTHOGONAL least-squares.\n% [N,C] = LINORTFITN(DATA) finds the coefficients of a hyperplane (in\n% Hessian normal form) that best fits the data in an ORTHOGONAL\n% least-squares sense. Consider the hyperplane\n% H = {x | dot(N,x) + C == 0},\n% and the minimum (Euclidean) distance between this hyperplane and each\n% datapoint DATA(i,:) -- LINORTFITN finds N and C such that the sum of\n% squared distances is minimized.\n\n[M,N] = size(data);\nif M <= N,\n error('linortfitn:DegenerateProblem',...\n 'There are fewer datapoints than dimensions: the data is perfectly fit by a hyperplane.');\nend\n\n[U,S,V] = svd(data - repmat(mean(data),M,1), 0);\nhyperplane_normal = V(:,end);\nhyperplane_offset = - mean(data * hyperplane_normal);\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/16800-orthogonal-linear-regression/linortfitn.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9780517462851321, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.8370667088514613}} {"text": "function a = lesp ( m, n )\n\n%*****************************************************************************80\n%\n%% LESP returns the LESP matrix.\n%\n% Formula:\n%\n% if ( I - J == 1 )\n% A(I,J) = 1 / I\n% else if ( I - J == 0 )\n% A(I,J) = - ( 2*I+3 )\n% else if ( I - J == 1 )\n% A(I,J) = J\n% else\n% A(I,J) = 0.0\n%\n% Example:\n%\n% M = 5, N = 5\n%\n% -5 2 . . .\n% 1/2 -7 3 . .\n% . 1/3 -9 4 .\n% . . 1/4 -11 5\n% . . . 1/5 -13\n%\n%\n% Properties:\n%\n% The matrix is tridiagonal.\n%\n% Because A is tridiagonal, it has property A (bipartite).\n%\n% A is generally not symmetric: A' /= A.\n%\n% The eigenvalues are real, and smoothly distributed in [-2*N-3.5, -4.5].\n%\n% The eigenvalues are sensitive.\n%\n% The matrix is similar to the symmetric tridiagonal matrix with\n% the same diagonal entries and with off-diagonal entries 1,\n% via a similarity transformation using the diagonal matrix\n% D = diagonal ( 1!, 2!, ..., N! ).\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% 23 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Wim Lenferink, MN Spijker,\n% On the use of stability regions in the numerical analysis of initial\n% value problems,\n% Mathematics of Computation,\n% Volume 57, 1991, pages 221-237.\n%\n% Lloyd Trefethen,\n% Pseudospectra of matrices,\n% in Numerical Analysis 1991,\n% Proceedings of the 14th Dundee Conference,\n% D F Griffiths and G A Watson, editors,\n% Pitman Research Notes in Mathematics, volume 260,\n% Longman Scientific and Technical, Essex, UK, 1992, pages 234-266.\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns 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 == 1 )\n a(i,j) = 1.0 / i;\n elseif ( i - j == 0 )\n a(i,j) = - ( 2 * i + 3 );\n elseif ( i - j == -1 )\n a(i,j) = j;\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/lesp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.897695295528596, "lm_q1q2_score": 0.8370589537191477}} {"text": "function ell = inertiaEllipse(points)\n%INERTIAELLIPSE Inertia ellipse of a set of points\n%\n% ELL = inertiaEllipse(PTS);\n% where PTS is a N*2 array containing coordinates of N points, computes\n% the inertia ellispe of the set of points.\n%\n% The result has the form:\n% ELL = [XC YC A B THETA],\n% with XC and YC being the center of mass of the point set, A and B are\n% the lengths of the inertia ellipse (see below), and THETA is the angle\n% of the main inertia axis with the horizontal (counted in degrees\n% between 0 and 180). \n% A and B are the standard deviations of the point coordinates when\n% ellipse is aligned with the inertia axes.\n%\n% Example\n% pts = randn(100, 2);\n% pts = transformPoint(pts, createScaling(5, 2));\n% pts = transformPoint(pts, createRotation(pi/6));\n% pts = transformPoint(pts, createTranslation(3, 4));\n% ell = inertiaEllipse(pts);\n% figure(1); clf; hold on;\n% drawPoint(pts);\n% drawEllipse(ell, 'linewidth', 2, 'color', 'r');\n%\n% See also\n% ellipses2d, drawEllipse\n%\n% ------\n% Author: David Legland\n% e-mail: david.legland@grignon.inra.fr\n% Created: 2008-02-21, using Matlab 7.4.0.287 (R2007a)\n% Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas.\n\n% HISTORY\n% 2009-07-29 take into account ellipse orientation\n% 2011-03-12 rewrite using inertia moments\n\n% ellipse center\nxc = mean(points(:,1));\nyc = mean(points(:,2));\n\n% recenter points\nx = points(:,1) - xc;\ny = points(:,2) - yc;\n\n% number of points\nn = size(points, 1);\n\n% inertia parameters\nIxx = sum(x.^2) / n;\nIyy = sum(y.^2) / n;\nIxy = sum(x.*y) / n;\n\n% compute ellipse semi-axis lengths\ncommon = sqrt( (Ixx - Iyy)^2 + 4 * Ixy^2);\nra = sqrt(2) * sqrt(Ixx + Iyy + common);\nrb = sqrt(2) * sqrt(Ixx + Iyy - common);\n\n% compute ellipse angle in degrees\ntheta = atan2(2 * Ixy, Ixx - Iyy) / 2;\ntheta = rad2deg(theta);\n\n% create the resulting inertia ellipse\nell = [xc yc ra rb theta];\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/geom2d/inertiaEllipse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465170505204, "lm_q2_score": 0.8947894661025424, "lm_q1q2_score": 0.8369382106125077}} {"text": "function value = i4_gcd ( i, j )\n\n%*****************************************************************************80\n%\n%% I4_GCD finds the greatest common divisor of I and J.\n%\n% Discussion:\n%\n% Only the absolute values of I and J are\n% considered, so that the result is always nonnegative.\n%\n% If I or J is 0, I4_GCD is returned as max ( 1, abs ( I ), abs ( J ) ).\n%\n% If I and J have no common factor, I4_GCD is returned as 1.\n%\n% Otherwise, using the Euclidean algorithm, I4_GCD is the\n% largest common factor of I and J.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 19 July 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer I, J, two numbers whose greatest common divisor\n% is desired.\n%\n% Output, integer VALUE, the greatest common divisor of I and J.\n%\n value = 1;\n%\n% Return immediately if either I or J is zero.\n%\n if ( i == 0 )\n value = max ( 1, abs ( j ) );\n return\n elseif ( j == 0 )\n value = max ( 1, abs ( i ) );\n return\n end\n%\n% Set IP to the larger of I and J, IQ to the smaller.\n% This way, we can alter IP and IQ as we go.\n%\n ip = max ( abs ( i ), abs ( j ) );\n iq = min ( abs ( i ), abs ( j ) );\n%\n% Carry out the Euclidean algorithm.\n%\n while ( 1 )\n\n ir = mod ( ip, iq );\n\n if ( ir == 0 )\n break;\n end\n\n ip = iq;\n iq = ir;\n\n end\n\n value = iq;\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/uniform/i4_gcd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465116437761, "lm_q2_score": 0.8947894682067639, "lm_q1q2_score": 0.8369382077427862}} {"text": "function a = cheby_van2 ( n )\n\n%*****************************************************************************80\n%\n%% CHEBY_VAN2 returns the CHEBY_VAN2 matrix.\n%\n% Discussion:\n%\n% CHEBY_VAN2 is the Chebyshev Vandermonde-like matrix.\n%\n% The formula for this matrix has been slightly modified, by a scaling\n% factor, in order to make it closer to its inverse.\n%\n% Formula:\n%\n% A(I,J) = ( 1 / sqrt ( N - 1 ) ) * cos ( (I-1) * (J-1) * PI / (N-1) )\n%\n% Example:\n%\n% N = 4\n%\n% 1 1 1 1\n% 1/sqrt(3) * 1 COS(PI/3) COS(2*PI/3) COS(3*PI/3)\n% 1 COS(2*PI/3) COS(4*PI/3) COS(6*PI/3)\n% 1 COS(3*PI/3) COS(6*PI/3) COS(9*PI/3)\n%\n% 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% The entries of A are based on the extrema of the Chebyshev\n% polynomial T(n-1).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 September 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Output, real A(N,N), the matrix.\n%\n a = zeros ( n, n );\n\n if ( n == 1 )\n a(1,1) = 1.0;\n return\n end\n \n for i = 1 : n\n for j = 1 : n\n\n angle = ( ( i - 1 ) * ( j - 1 ) ) * pi / ( n - 1 );\n\n a(i,j) = cos ( angle );\n\n end\n end\n\n a(1:n,1:n) = a(1:n,1:n) / sqrt ( 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/test_mat/cheby_van2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465098415278, "lm_q2_score": 0.8947894654011352, "lm_q1q2_score": 0.8369382035059183}} {"text": "function f=dft(f,N,dim);\n%DFT Normalized Discrete Fourier Transform\n% Usage: f=dft(f);\n% f=dft(f,N,dim);\n%\n% `dft` computes a normalized or unitary discrete Fourier transform. The \n% unitary discrete Fourier transform is computed by\n% \n% .. L-1\n% c(k+1) = 1/sqrt(L) * sum f(l+1)*exp(-2*pi*i*k*l/L)\n% l=0\n%\n% .. math:: c\\left(k+1\\right)=\\frac{1}{\\sqrt{L}}\\sum_{l=0}^{L-1}f\\left(l+1\\right)e^{-2\\pi ikl/L}\n%\n% for $k=0,\\ldots,L-1$.\n%\n% The output of `dft` is a scaled version of the output from `fft`. The\n% function takes exactly the same arguments as `fft`. See the help on `fft`\n% for a thorough description.\n%\n% See also: idft\n\n% AUTHOR: Peter L. Søndergaard, Jordy van Velthoven\n% TESTING: TEST_DFT\n% REFERENCE: REF_DFT\n\ncomplainif_argnonotinrange(nargin,1,3,mfilename);\n\nif nargin<3\n dim=[];\nend;\n\nif nargin<2\n N=[];\nend;\n\n[f,N,Ls,W,dim,permutedsize,order]=assert_sigreshape_pre(f,N,dim,'DFT');\n\n% Force FFT along dimension 1, since we have permuted the dimensions\n% manually\nf=fft(f,N,1)/sqrt(N);\n\nf=assert_sigreshape_post(f,dim,permutedsize,order);\n\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/fourier/dft.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632329799585, "lm_q2_score": 0.8791467770088162, "lm_q1q2_score": 0.8368274934275224}} {"text": "function K = knGauss(X, Y, s)\n% Gaussian (RBF) kernel K = exp(-|x-y|/(2s));\n% Input:\n% X: d x nx data matrix\n% Y: d x ny data matrix\n% s: sigma of gaussian\n% Ouput:\n% K: nx x ny kernel matrix\n% Written by Mo Chen (sth4nth@gmail.com).\nif nargin < 3\n s = 0.4;\nend\n\nif nargin < 2 || isempty(Y) \n K = ones(1,size(X,2)); % norm in kernel space\nelse\n D = bsxfun(@plus,dot(X,X,1)',dot(Y,Y,1))-2*(X'*Y);\n K = exp(D/(-2*s^2));\nend\n\n", "meta": {"author": "PRML", "repo": "PRMLT", "sha": "baac49f643db6b39e75307d3b21307b32b29a7a9", "save_path": "github-repos/MATLAB/PRML-PRMLT", "path": "github-repos/MATLAB/PRML-PRMLT/PRMLT-baac49f643db6b39e75307d3b21307b32b29a7a9/chapter06/knGauss.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9518632302488964, "lm_q2_score": 0.8791467580102419, "lm_q1q2_score": 0.8368274729424737}} {"text": "%MAIN_cannon.m\n%\n% This script is used to find the optimal initial state for the cannon\n% example problem, as described below:\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% Cannon Example:\n%\n% Find the optimal initial velocity for a projectile such that the\n% resulting trajectory passes through a desired target. \n%\n% States:\n% x = horizontal position\n% y = vertical position\n% dx = horizontal speed\n% dy = vertical speed\n% ddx = horizontal acceleration\n% ddy = vertical acceleration\n%\n% Parameters:\n% c = quadratic drag coefficient\n% T = final simulation time\n%\n% Boundary Conditions:\n% x(0) = 0;\n% y(0) = 0;\n% x(T) = xf;\n% y(T) = yf;\n%\n% Objective Function:\n% J = dx(0)^2 + dy(0)^2;\n%\n% Dynamics Constraint:\n% ddx = -c*dx*sqrt(dx.*dx + dy.*dy);\n% ddy = -c*dy*sqrt(dx.*dx + dy.*dy) - 1; \n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nclc; clear;\n%%%% Adjust the following parameters and see what happens.\n%\n% 1) The problem becomes trivial if the drag coefficient (c) is small, but\n% numerically stiff if c is large (>0.4). Which methods can handle large\n% values of c the best?\n%\n%\n% 2) What do you think happens if you use more (or fewer) grid points?\n%\n% 3) What happens if you move the target away? \n% Open: TEST_cannonFeasibility.m to see the answer. \n%\n% 4) For either large range or large damping, the problem becomes stiff. As\n% a result, the integration methods (either implicit or explicit) start to\n% fail near the beginning of the trajectory where the speed is very high.\n% If you use a log spaced grid (rather than uniform), then all methods\n% perform better.\n%\n% 5) You can speed up the optimizations by disabling diagnostics or making\n% each animation shorter.\n%\n\n\n%Provide an initial guess for the solver\nguess.initSpeed = 9.0;\nguess.initAngle = (pi/180)*45;\n\n% Set the target (assuming that the trajectory starts at x=0, y=0)\ntarget.x = 6.0; \ntarget.y = 0;\n\n% Set up the parameters for the dynamics function:\nparam.dynamics.c = 0.4; %Quadratic drag coefficient\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%%% Set up the grid discretization for each method:\nparam.singleShooting.nGrid = 100; \nparam.multipleShooting.nSegment = 10;\nparam.multipleShooting.nSubStep = 5;\nparam.collocation.nSegment = 50;\nparam.gpops.nSegment = 10;\n\n%%% Parameters for diagnostics (visualization only)\nparam.diagnostics.enable = true; %Enable plotting and log iterations?\nparam.diagnostics.animationDuration = 5; %(seconds) How long is the animation?\nparam.diagnostics.writeGif = true; %Save animation to a gif?\nparam.diagnostics.gifPixelDim = [800,400]; %How big of a gif to make?\nparam.diagnostics.figNum.singleShooting = 10;\nparam.diagnostics.figNum.multipleShooting = 11;\nparam.diagnostics.figNum.collocation = 12;\nparam.diagnostics.figNum.gpops = 13;\n\n% Use single shooting to find the solution:\nsoln.singleShooting = cannon_singleShooting(guess,target,param);\n\n% Use multiple shooting to find the solution:\nsoln.multipleShooting = cannon_multipleShooting(guess,target,param);\n\n% Use collocation to find the solution:\nsoln.collocation = cannon_collocation(guess,target,param);\n\n% % Use GPOPS to solve the problem (http://www.gpops2.com/)\n% % - adaptive high-order collocation\n% % - not included in Matlab. Must be purchased seperately.\n% soln.gpops = cannon_gpops(guess,target,param);\n\n\n\n\n\n\n\n\n", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/TrajectoryOptimization/Example_1_Cannon/MAIN_cannon.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913356558485, "lm_q2_score": 0.8902942217558213, "lm_q1q2_score": 0.8367994302951381}} {"text": "function [ r, center ] = tetrahedron_circumsphere_3d ( tetra )\n\n%*****************************************************************************80\n%\n%% TETRAHEDRON_CIRCUMSPHERE_3D computes the circumsphere of a tetrahedron in 3D.\n%\n% Discussion:\n%\n% The circumsphere, or circumscribed sphere, of a tetrahedron is the sphere that\n% passes through the four vertices. The circumsphere is not necessarily\n% the smallest sphere that contains the tetrahedron.\n%\n% Surprisingly, the diameter of the sphere can be found by solving\n% a 3 by 3 linear system. This is because the vectors P2 - P1,\n% P3 - P1 and P4 - P1 are secants of the sphere, and each forms a\n% right triangle with the diameter through P1. Hence, the dot product of\n% P2 - P1 with that diameter is equal to the square of the length\n% of P2 - P1, and similarly for P3 - P1 and P4 - P1. This determines\n% the diameter vector originating at P1, and hence the radius and\n% center.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 10 August 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, real TETRA(3,4) the tetrahedron vertices.\n%\n% Output, real R, CENTER(3), the center of the\n% circumscribed sphere, and its radius. If the linear system is\n% singular, then R = -1, CENTER(1:3) = 0.\n%\n dim_num = 3;\n nrhs = 1;\n%\n% Set up the linear system.\n%\n a(1:dim_num,1:3) = ( tetra(1:dim_num,2:4) )';\n\n for j = 1 : dim_num\n a(1:dim_num,j) = a(1:dim_num,j) - tetra(j,1);\n end\n\n for i = 1 : dim_num\n a(i,4) = sum ( a(i,1:3).^2 );\n end\n%\n% Solve the linear system.\n%\n [ a, info ] = r8mat_solve ( dim_num, nrhs, a );\n%\n% If the system was singular, return a consolation prize.\n%\n if ( info ~= 0 )\n r = -1.0;\n center(1:dim_num) = 0.0;\n return\n end\n%\n% Compute R, X, Y, Z.\n%\n r = 0.5 * sqrt ( sum ( a(1:dim_num,dim_num+1).^2 ) );\n\n center(1:dim_num) = tetra(1:dim_num,1) + 0.5 * a(1:dim_num,dim_num+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/tet_mesh/tetrahedron_circumsphere_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8902942253943279, "lm_q1q2_score": 0.8367994277211198}} {"text": "function [J, grad] = lrCostFunction(theta, X, y, lambda)\n%LRCOSTFUNCTION Compute cost and gradient for logistic regression with \n%regularization\n% J = LRCOSTFUNCTION(theta, X, y, lambda) computes the cost of using\n% theta as the parameter for regularized logistic regression and the\n% gradient of the cost w.r.t. to the parameters. \n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n% Hint: The computation of the cost function and gradients can be\n% efficiently vectorized. For example, consider the computation\n%\n% sigmoid(X * theta)\n%\n% Each row of the resulting matrix will contain the value of the\n% prediction for that example. You can make use of this to vectorize\n% the cost function and gradient computations. \n%\n% Hint: When computing the gradient of the regularized cost function, \n% there're many possible vectorized solutions, but one solution\n% looks like:\n% grad = (unregularized gradient for logistic regression)\n% temp = theta; \n% temp(1) = 0; % because we don't add anything for j = 0 \n% grad = grad + YOUR_CODE_HERE (using the temp variable)\n%\n\n\nn = length(theta);\n\n% X.shape = [m, n], y.shape = [m, 1], theta.shape = [n, 1]\n% y_pred = sigmoid(X*theta), y_pred.shape = [m, 1]\ny_pred = sigmoid(X*theta);\nJ = -1.0 / m * sum( y.*log(y_pred) + (1-y).*log(1-y_pred) );\nJ = J + lambda / (2.0*m) * sum( theta(2:n, 1).^2 ); % ignore theta(1)\ngrad = 1.0 / m .* (X' * (y_pred - y));\ngrad(2:n, 1) = grad(2:n, 1) + lambda / m * theta(2:n, 1); % ignore theta(1)\n\n\n\n\n\n% =============================================================\n\ngrad = grad(:);\n\nend\n", "meta": {"author": "imLogM", "repo": "Machine_Learning_AndrewNg", "sha": "1d499e8e2738032dc85e869ba55c32eb24da288d", "save_path": "github-repos/MATLAB/imLogM-Machine_Learning_AndrewNg", "path": "github-repos/MATLAB/imLogM-Machine_Learning_AndrewNg/Machine_Learning_AndrewNg-1d499e8e2738032dc85e869ba55c32eb24da288d/machine-learning-ex3/ex3/lrCostFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133447766225, "lm_q2_score": 0.890294223211224, "lm_q1q2_score": 0.8367994211737665}} {"text": "function [ n_data, m, n, fmn ] = i4_rise_values ( n_data )\n\n%*****************************************************************************80\n%\n%% I4_RISE_VALUES returns values of the integer rising factorial function.\n%\n% Discussion:\n%\n% The integer rising factorial function is sometimes symbolized by (m)_n.\n%\n% The definition is\n%\n% (m)_n = (m-1+n)! / (m-1)!\n% = ( m ) * ( m + 1 ) * ( m + 2 ) ... * ( m - 1 + n )\n% = Gamma ( m + n ) / Gamma ( m )\n%\n% We assume 0 <= N <= M.\n%\n% In Mathematica, the function can be evaluated by:\n%\n% Pochhammer[m,n]\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 December 2014\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 M, N, the arguments of the function.\n%\n% Output, integer FMN, the value of the function.\n%\n n_max = 8;\n\n fmn_vec = [ ...\n 1, 5, 30, 210, 1680, ...\n 15120, 151200, 1, 10, 4000, ...\n 110, 6840, 840, 970200, 5040 ];\n\n m_vec = [ ...\n 5, 5, 5, 5, 5, ...\n 5, 5, 50, 10, 4000, ...\n 10, 18, 4, 98, 1 ];\n\n n_vec = [ ...\n 0, 1, 2, 3, 4, ...\n 5, 6, 0, 1, 1, ...\n 2, 3, 4, 3, 7 ];\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 m = 0;\n n = 0;\n fmn = 0;\n else\n m = m_vec(n_data);\n n = n_vec(n_data);\n fmn = fmn_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/i4_rise_values.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.8991213840277783, "lm_q1q2_score": 0.836594914459992}} {"text": "function Z = projectData(X, U, K)\n%PROJECTDATA Computes the reduced data representation when projecting only \n%on to the top k eigenvectors\n% Z = projectData(X, U, K) computes the projection of \n% the normalized inputs X into the reduced dimensional space spanned by\n% the first K columns of U. It returns the projected examples in Z.\n%\n\n% You need to return the following variables correctly.\nZ = zeros(size(X, 1), K);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the projection of the data using only the top K \n% eigenvectors in U (first K columns). \n% For the i-th example X(i,:), the projection on to the k-th \n% eigenvector is given as follows:\n% x = X(i, :)';\n% projection_k = x' * U(:, k);\n%\n\n\nsubsetU = U(:, 1:K);\nZ = X * subsetU;\n\n\n% =============================================================\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-ex7/projectData.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.905989822921759, "lm_q1q2_score": 0.8362640928537357}} {"text": "%KF_LOOP Performs the prediction and update steps of the Kalman filter\n% for a set of measurements. \n%\n% Syntax:\n% [MM,PP] = KF_LOOP(X,P,H,R,Y,A,Q)\n% \n% In:\n% X - Nx1 initial estimate for the state mean \n% P - NxN initial estimate for the state covariance\n% H - DxN measurement matrix\n% R - DxD measurement noise covariance\n% Y - DxM matrix containing all the measurements.\n% A - Transition matrix of the discrete model (optional, default identity)\n% Q - Process noise of the discrete model (optional, default zero)\n% \n% Out:\n% MM - Filtered state mean sequence\n% PP - Filtered state covariance sequence\n% \n% Description:\n% Calculates state estimates for a set measurements using the\n% Kalman filter. This function is for convience, as it basically consists\n% only of a space reservation for the estimates and of a for-loop which\n% calls the predict and update steps of the KF for each time step in\n% the measurements. \n% \n% See also:\n% KF_PREDICT, KF_UPDATE\n\n% History:\n% \n% 12.2.2007 JH Initial version. \n%\n% Copyright (C) 2007 Jouni Hartikainen\n%\n% This software is distributed under the GNU General Public \n% Licence (version 2 or later); please refer to the file \n% Licence.txt, included with the software, for details.\n\nfunction [MM,PP] = kf_loop(X,P,H,R,Y,A,Q)\n\n % Check the input parameters. \n if nargin < 5\n error('Too few arguments');\n end\n if nargin < 6\n A = [];\n end\n if nargin < 7\n Q = [];\n end\n\n % Apply the defaults\n if isempty(A)\n A = eye(size(X,1));\n end\n if isempty(Q)\n Q = zeros(size(X,1));\n end\n\n % Space for the estimates.\n MM = zeros(size(X,1), size(Y,2));\n PP = zeros(size(X,1), size(X,1), size(Y,2));\n\n % Filtering steps.\n for i = 1:size(Y,2)\n [X,P] = kf_predict(X,P,A,Q);\n [X,P] = kf_update(X,P,Y(:,i),H,R);\n MM(:,i) = X;\n PP(:,:,i) = P;\n end\n", "meta": {"author": "EEA-sensors", "repo": "ekfukf", "sha": "d08550a5b14caac525e51ed4ef5ec0ef1ea3e8f8", "save_path": "github-repos/MATLAB/EEA-sensors-ekfukf", "path": "github-repos/MATLAB/EEA-sensors-ekfukf/ekfukf-d08550a5b14caac525e51ed4ef5ec0ef1ea3e8f8/kf_loop.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422241476943, "lm_q2_score": 0.8791467722591728, "lm_q1q2_score": 0.8361936163188561}} {"text": "function [P_intersect,distances] = lineIntersect3D(PA,PB)\n% Find intersection point of lines in 3D space, in the least squares sense.\n% PA : Nx3-matrix containing starting point of N lines\n% PB : Nx3-matrix containing end point of N lines\n% P_Intersect : Best intersection point of the N lines, in least squares sense.\n% distances : Distances from intersection point to the input lines\n% Anders Eikenes, 2012\n\nSi = PB - PA; %N lines described as vectors\nni = Si ./ (sqrt(sum(Si.^2,2))*ones(1,3)); %Normalize vectors\nnx = ni(:,1); ny = ni(:,2); nz = ni(:,3);\nSXX = sum(nx.^2-1);\nSYY = sum(ny.^2-1);\nSZZ = sum(nz.^2-1);\nSXY = sum(nx.*ny);\nSXZ = sum(nx.*nz);\nSYZ = sum(ny.*nz);\nS = [SXX SXY SXZ;SXY SYY SYZ;SXZ SYZ SZZ];\nCX = sum(PA(:,1).*(nx.^2-1) + PA(:,2).*(nx.*ny) + PA(:,3).*(nx.*nz));\nCY = sum(PA(:,1).*(nx.*ny) + PA(:,2).*(ny.^2-1) + PA(:,3).*(ny.*nz));\nCZ = sum(PA(:,1).*(nx.*nz) + PA(:,2).*(ny.*nz) + PA(:,3).*(nz.^2-1));\nC = [CX;CY;CZ];\nP_intersect = (S\\C)';\n\nif nargout>1\n N = size(PA,1);\n distances=zeros(N,1);\n for i=1:N %This is faster:\n ui=(P_intersect-PA(i,:))*Si(i,:)'/(Si(i,:)*Si(i,:)');\n distances(i)=norm(P_intersect-PA(i,:)-ui*Si(i,:));\n end\n %for i=1:N %http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html:\n % distances(i) = norm(cross(P_intersect-PA(i,:),P_intersect-PB(i,:))) / norm(Si(i,:));\n %end\nend\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/37192-intersection-point-of-lines-in-3d-space/lineIntersect3D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377320263432, "lm_q2_score": 0.8723473813156294, "lm_q1q2_score": 0.836177880425403}} {"text": "function value = gud ( x )\n\n%*****************************************************************************80\n%\n%% GUD evaluates the Gudermannian function.\n%\n% Discussion:\n%\n% The Gudermannian function relates the hyperbolic and trigonometric\n% functions. For any argument X, there is a corresponding value\n% G so that\n%\n% sinh(x) = tan(g).\n%\n% The value G is called the Gudermannian of X.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 20 July 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the Gudermannian.\n%\n% Output, real VALUE, the value of the Gudermannian.\n%\n value = 2.0 * atan ( tanh ( 0.5 * x ) );\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/polpak/gud.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897542390751, "lm_q2_score": 0.8887587957022977, "lm_q1q2_score": 0.8361351689865809}} {"text": "function acv= autocov(x,maxlag)\n%\n% autocov computes the sample autocovariance of a time series x for lags\n% from 0 to maxlag, returning a column vector of length maxlag+1. x must\n% be a column vector having length m not less than maxlag+1. If no value\n% is supplied for maxlag, the default is the minimum of m-1 and 100.\n%\n% Dr. Phillip M. Feldman\n% Last update 21 June 2008\n%\n% Based on equations on p. 19 of \"Introduction to Time Series and\n% Forecasting\" 2nd Edition by Brockwell and Davis.\n\n\n% Section 1: Check input arguments and supply default value for maxlag\n% if needed.\n\nif nargin < 1, error('Missing input vector.'); end\n\n[m n]= size(x);\nif (n ~= 1)\n error('x must be a column vector.')\nend\nif (m <= maxlag)\n error('The length of the input vector x must be at least maxlag+1.');\nend\n\nif nargin < 2, maxlag= min(m-1,100); end\n\n\n% Section 2: Compute autocovariance.\n\n% Remove mean from x:\nx= x - mean(x);\n\n% For faster running time, we pre-allocate the output array:\nacv= zeros(maxlag+1,1);\n\n% Compute autocovariance:\nfor h= 0 : maxlag\n % Take matrix product of row vector and column vector to obtain a\n % scalar. The row vector contains the first n-h elements of x; the\n % column vector contains the last n-h elements of x.\n acv(h+1)= x(1:m-h)' * x(1+h:m);\nend\n\nacv= acv / 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/24066-autocov-m/autocov.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.8887587949656841, "lm_q1q2_score": 0.8361351668181359}} {"text": "function optimal = fibonacci(f,a,b,n)\n\n% Program : fibonacci.m\n%\n% Purpose : find the optimal point of a given single \n% variable function within the given interval\n%\n% Author : Aamir Alaud Din\n% Date : 26.09.2013\n%\n% Inputs : Four input arguments are required viz., function, initial and\n% final points of the interval, and function evaluation number n\n%\n% Syntax : optimal = fibonacci(f,a,b)\n% where f is an inline function \n% e.g., f = inline('sin(x)','x');\n% a and b are initial and final points of the interval\n%\n% Example: optimal = fibonacci(f,-3,5)\n%\n% Fourth input argument is fibonacci number decided by the user.\n% Default fibonacci number is 11 which gives 10 iterations.\n% Number of iterations is one less then fibonacci number, i.e.,\n% number of iterations = fibonacci number - 1\n%\n% Syntax: optimal = fibonacci(f,a,b,n)\n% f, a, and b are described above\n% n is the number of iterations decided by the user\n% Example: optimal = fibonacci(f,0,1,20)\n%\n\nif (nargin < 3)\n error('Too few input arguments');\n optimal = 'Fibonacci search is not possible with too few inputs';\n return;\n \nelseif (nargin == 3)\n n = 11;\n fss = [1,1];\n for ii = 1:(n-1)\n fs = fss(end) + fss(end-1);\n fss = [fss,fs];\n end\n \n disp('Iteration N x1 x2 f(x1) f(x2)');\n disp('========= === ======== ======== ========= =========');\n Iter = 0;\n for jj = n:-1:2\n Iter = Iter + 1;\n L = b - a;\n x1 = a + ((fss(jj-1)/fss(jj+1))*L);\n x2 = b - ((fss(jj-1)/fss(jj+1))*L);\n if (f(x1) < f(x2))\n b = x2;\n elseif (f(x1) > f(x2))\n a = x1;\n elseif (f(x1) == f(x2))\n a = x1;\n b = x2 + 0.0001;\n end\n fprintf('%3d', Iter);\n fprintf('\\t\\t\\t\\t');\n fprintf('%4d', jj-1);\n fprintf('\\t');\n fprintf('%11.4f', x1);\n fprintf('\\t\\t');\n fprintf('%11.4f', x2);\n fprintf('\\t\\t');\n fprintf('%12.4f', f(x1));\n fprintf('\\t\\t');\n fprintf('%12.4f', f(x2));\n fprintf('\\n');\n end\n optimal = min(x1,x2);\n \nelseif (nargin == 4)\n fss = [1,1];\n for ii = 1:(n-1)\n fs = fss(end) + fss(end-1);\n fss = [fss,fs];\n end\n \n disp('Iteration N x1 x2 f(x1) f(x2)');\n disp('========= === ======== ======== ========= =========');\n Iter = 0;\n for jj = n:-1:2\n Iter = Iter + 1;\n L = b - a;\n x1 = a + ((fss(jj-1)/fss(jj+1))*L);\n x2 = b - ((fss(jj-1)/fss(jj+1))*L);\n if (f(x1) < f(x2))\n b = x2;\n elseif (f(x1) > f(x2))\n a = x1;\n elseif (f(x1) == f(x2))\n a = x1;\n b = x2 + 0.0001;\n end\n fprintf('%3d', Iter);\n fprintf('\\t\\t\\t\\t');\n fprintf('%4d', jj-1);\n fprintf('\\t');\n fprintf('%11.4f', x1);\n fprintf('\\t\\t');\n fprintf('%11.4f', x2);\n fprintf('\\t\\t');\n fprintf('%12.4f', f(x1));\n fprintf('\\t\\t');\n fprintf('%12.4f', f(x2));\n fprintf('\\n');\n end\n optimal = min(x1,x2);\n \nelseif (nargin > 4)\n error('Too many input arguments');\n optimal = 'Fibonacci search is not possible with too many inputs';\n return\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/43650-fibonacci-m/fibonacci.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012717045181, "lm_q2_score": 0.8840392878563336, "lm_q1q2_score": 0.8361254826912768}} {"text": "function [U, S] = pca(X)\n%PCA Run principal component analysis on the dataset X\n% [U, S, X] = pca(X) computes eigenvectors of the covariance matrix of X\n% Returns the eigenvectors U, the eigenvalues (on diagonal) in S\n%\n\n% Useful values\n[m, n] = size(X);\n\n% You need to return the following variables correctly.\nU = zeros(n);\nS = zeros(n);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: You should first compute the covariance matrix. Then, you\n% should use the \"svd\" function to compute the eigenvectors\n% and eigenvalues of the covariance matrix. \n%\n% Note: When computing the covariance matrix, remember to divide by m (the\n% number of examples).\n%\n\nSigma = (X' * X) / m; %'\n[U, S, V] = svd(Sigma);\n\n\n% =========================================================================\n\nend\n", "meta": {"author": "gopaczewski", "repo": "coursera-ml", "sha": "9f68b71ac6b65bfd7cea32c7c22b4abd40401579", "save_path": "github-repos/MATLAB/gopaczewski-coursera-ml", "path": "github-repos/MATLAB/gopaczewski-coursera-ml/coursera-ml-9f68b71ac6b65bfd7cea32c7c22b4abd40401579/mlclass-ex7-005/mlclass-ex7/pca.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.8947894520743981, "lm_q1q2_score": 0.8360869322415724}} {"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n% \n% \n% \n% time invariant or time variant\n\n\n\n%time variant\nt=-5:.001:10;\np=heaviside(t)-heaviside(t-5);\ny=t.*exp(-t).*p;\nplot(t,y)\nylim([-.05 .4]);\nlegend('y(t)') \n\nfigure\nplot(t+3,y)\nylim([-.05 .4]);\nlegend('y(t-3)')\n\nfigure\nt=-5:.001:10;\np=heaviside(t-3)-heaviside(t-8);\ny2=t.*exp(-t).*p;\nplot(t,y2)\nylim([-.01 .2]);\nlegend('S[x(t-3)]')\n\n\n%time invariant\nfigure\nt=-5:.01:20;\np=heaviside(t-1)-heaviside(t-11);\ny=1-2*cos(t-1).*p;\nplot(t,y)\nlegend('y(t)')\n\nfigure\np=heaviside(t)-heaviside(t-10);\nx=cos(t).*p;\nplot(t+1,1-2*x)\nlegend('y(t)')\n\nfigure\nplot(t+4,y)\nlegend('y(t-4)')\n\nfigure\np=heaviside(t-4)-heaviside(t-14);\nx=cos(t-4).*p;\nplot(t,x)\n\nfigure\np=heaviside(t-4)-heaviside(t-14);\nx=cos(t-4).*p;\nplot(t+1,1-2*x)\n\nfigure\nt=-5:.01:20;\np=heaviside(t-5)-heaviside(t-15);\ny2=1-2*cos(t-5).*p ;\nplot(t,y2) ;\nlegend('S[x(t-4)]')\n\n\n\n%time variant\nfigure\nt=-5:.1:10;\nx=heaviside(t+2)-heaviside(t-2);\nplot(t,x);\nylim([-.1 1.1]);\n\nfigure\nplot((1/2)*t,x);\nylim([-.1 1.1]);\n\nfigure\nplot((1/2)*t+2,x);\nylim([-.1 1.1]);\nlegend('y_1(t)')\n\nfigure\nplot(t+2,x);\nylim([-.1 1.1]);\nlegend('x(t-2)')\n\nfigure\nt=-5:.1:10;\nx2=heaviside(t)-heaviside(t-4);\nplot(t,x2);\nylim([-.1 1.1]);\n\nfigure\nplot((1/2)*t,x2);\nylim([-.1 1.1]);\nlegend('y_2(t)')\n\n\n\n\n%shift invariant\nfigure\nn=0:5;\nx=0.8.^n; \ny=x.^2;\nstem(n,y);\nxlim([-.1 5.1])\nlegend('y[n]')\n\nfigure\nstem(n+2,y)\nlegend('y[n-2]')\nxlim([1.9 7.1])\n\nfigure\nn=2:7;\ny2=(0.8.^(n-2)).^2;\nstem(n,y2);\nxlim([1.9 7.1])\nlegend('S[x[n-2]]')\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/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/3/c324.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.904650536386234, "lm_q1q2_score": 0.8360253950307769}} {"text": "function K=commutationMatrix(m,n)\n%%COMMUTATIONMATRIX Return a commutation matrix K for an mXn matrix. This\n% means that given an mXn matrix A that K*A(:)=B(:) where\n% B=transpose(A). As shown below, this matrix can also be used for\n% reversing the order of Kronecker products. As in [2], this\n% matrix is also known as a vec-permutation matrix.\n%\n%INPUTS: m,n The number of rows and the number of columns of the matrix\n% that is to be commutated by this commutation matrix.\n%\n%OUTPUTS: K An (m*n)X(m*n) commutation matrix.\n%\n%The matrix K is just a type of permutation matrix with 1's in the correct\n%places.\n%\n%Properties of the commutation matrix are given in [1] and in [2]. For\n%example, commutationMatrix(m,n)=commutationMatrix(n,m)' and also there is\n%an inverse relation that\n%commutationMatrix(m,n)*commutationMatrix(n,m)==eye(n*m) and\n%Note that the Vec permutation matrix I_{m,n} as in [2] is actually\n%commutationMatrix(n,m).\n%\n%EXAMPLE 1:\n%Here, we demonstrate the property that the vec-permutation matrix\n%(commutation matrix) allows one to get vec(A') from vec(A):\n% m=12;\n% n=17;\n% A=randn(m,n);\n% Imn=commutationMatrix(n,m);%The vec-permutation matrix as in [2].\n% all(vec(A)==Imn*vec(A'))\n%The result will be true, showing that\n%vec(A)==commutationMatrix(n,m)*vec(A')\n%which agrees with the identity given in the abstract to [2]. \n%\n%EXAMPLE 2:\n%Here, we give a demonstration of how to reverse the ordering of a\n%Kronecker product of two matrices:\n% m=12;\n% n=17;\n% A=randn(m,n);\n% p=4;\n% q=6;\n% B=randn(p,q);\n% Imp=commutationMatrix(p,m);\n% Iqn=commutationMatrix(n,q);\n% %Reversing the order of the matrix Kronecker product as in Equation 25 in\n% %[2].\n% all(vec(kron(B,A)==Imp*kron(A,B)*Iqn))\n%The result will be true, showing that one can use two commutation matrices\n%to reverse the ordering of Kronecker products of matrices.\n%\n%EXAMPLE 3:\n%Now, we demonstrate that one can use a single commutation matrix (vec-\n%permutation matrix) to reverse the order of the Kronecker product of two\n%vectors.\n% m=13;\n% n=7;\n% a=randn(m,1);\n% b=randn(n,1);\n% Imat=commutationMatrix(m,n);\n% all(vec(kron(a,b)==Imat*kron(b,a)))\n%The result will be true.\n%\n%REFERENCES:\n%[1] J. R. Magnus and H. Neudecker, \"The elimination matrix: Some lemmas\n% and applications,\" SIAM Journal on Algebraic Discrete Methods, vol. 1,\n% no. 4, pp. 422-449, 1980.\n%[2] H. V. Henderson and S. R. Searle, \"The vec-permutation matrix, the vec\n% operator and Kronecker products: A review,\" Linear and Multilinear\n% Algebra, vol. 9, no. 4, pp. 271-288, 1981.\n%\n%December 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nK=zeros(m*n,m*n);\n\nidx=0;\ncol=0;\n\nfor i=1:n\n idx=idx+1;\n row=idx;\n \n for j=1:m\n col=col+1;\n K(row,col)=1;\n row=row+n;\n end\nend\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/commutationMatrix.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.9046505318875316, "lm_q1q2_score": 0.8360253946534263}} {"text": "function pcof = r8poly_lagrange_coef ( npol, ipol, xpol )\n\n%*****************************************************************************80\n%\n%% R8POLY_LAGRANGE_COEF returns the coefficients of a Lagrange polynomial.\n%\n% Discussion:\n%\n% Given distinct abscissas XPOL(1:NPOL), the IPOL-th Lagrange\n% polynomial L(IPOL)(X) is defined as the polynomial of degree\n% NPOL - 1 which is 1 at XPOL(IPOL) and 0 at the NPOL - 1 other\n% abscissas.\n%\n% A formal representation is:\n%\n% L(IPOL)(X) = Product ( 1 <= I <= NPOL, I /= IPOL )\n% ( X - X(I) ) / ( X(IPOL) - X(I) )\n%\n% However sometimes it is desirable to be able to write down\n% the standard polynomial coefficients of L(IPOL)(X).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 29 October 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, integer IPOL, the index of the polynomial to evaluate.\n% IPOL must be between 1 and NPOL.\n%\n% Input, real XPOL(NPOL), the abscissas of the\n% Lagrange polynomials. The entries in XPOL must be distinct.\n%\n% Output, real PCOF(1:NPOL), the standard polynomial\n% coefficients of the IPOL-th Lagrange polynomial:\n% L(IPOL)(X) = SUM ( 0 <= I <= NPOL-1 ) PCOF(I+1) * X**I\n%\n\n%\n% Make sure IPOL is legal.\n%\n if ( ipol < 1 || npol < ipol )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'R8POLY_LAGRANGE_COEF - Fatal error!\\n' );\n fprintf ( 1, ' 1 <= IPOL <= NPOL is required.\\n' );\n error ( 'R8POLY_LAGRANGE_COEF - Fatal error!' );\n end\n%\n% Check that the abscissas are distinct.\n%\n if ( ~r8vec_distinct ( npol, xpol ) )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'R8POLY_LAGRANGE_COEF - Fatal error!\\n' );\n fprintf ( 1, ' Two or more entries of XPOL are equal:\\n' );\n error ( 'R8POLY_LAGRANGE_COEF - Fatal error!' );\n end\n\n pcof(1) = 1.0;\n pcof(2:npol) = 0.0;\n\n indx = 0;\n\n for i = 1 : npol\n\n if ( i ~= ipol )\n\n indx = indx + 1;\n\n for j = indx : -1 : 0\n\n pcof(j+1) = -xpol(i) * pcof(j+1) / ( xpol(ipol) - xpol(i) );\n\n if ( 0 < j )\n pcof(j+1) = pcof(j+1) + pcof(j) / ( xpol(ipol) - xpol(i) );\n end\n\n end\n\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/r8lib/r8poly_lagrange_coef.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009457116781, "lm_q2_score": 0.9136765263519308, "lm_q1q2_score": 0.8359235180339425}} {"text": "function Z = projectData(X, U, K)\n%PROJECTDATA Computes the reduced data representation when projecting only \n%on to the top k eigenvectors\n% Z = projectData(X, U, K) computes the projection of \n% the normalized inputs X into the reduced dimensional space spanned by\n% the first K columns of U. It returns the projected examples in Z.\n%\n\n% You need to return the following variables correctly.\nZ = zeros(size(X, 1), K);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the projection of the data using only the top K \n% eigenvectors in U (first K columns). \n% For the i-th example X(i,:), the projection on to the k-th \n% eigenvector is given as follows:\n% x = X(i, :)';\n% projection_k = x' * U(:, k);\n%\n\nsubsetU = U(:, 1:K);\nZ = X * subsetU;\n\n\n% =============================================================\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-8/exercises/machine-learning-ex7/ex7/projectData.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.9032941988938414, "lm_q1q2_score": 0.8357548528840364}} {"text": "function matrixData=ivech(stackedData)\n% Transform a vector in to a symmetric matrix for use in covariance applications\n% \n% USAGE:\n% MATRIXDATA = ivech(STACKEDDATA)\n% \n% INPUTS:\n% STACKEDDATA: A K(K+1)/2 vector of data to be transformed \n%\n% OUTPUTS:\n% MATRIXDATA - a K by K symmetric matrix of the form \n% [ data(1) data(2) data(3) ... data(K)\n% data(2) data(K+1) data(K+2) ... ...\n% data(3) data(K+2) data(2K) ... ...\n% ... .... ... ... data(K(K+1)/2-1)\n% data(K) data(2K-1) ... data(K(K+1)/2-1) data(K(K+1)/2) ]\n%\n% COMMENTS:\n%\n% See also VECH\n\n% Author: Kevin Sheppard\n% kevin.sheppard@economics.ox.ac.uk\n% Revision: 3 Date: 2/1/2008\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Input Checking\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nif size(stackedData,2)>size(stackedData,1)\n stackedData=stackedData';\nend\n\nif size(stackedData,2)~=1\n error('STACKED_DATA must be a column vector.')\nend\n\nK2=size(stackedData,1);\nK=(-1+sqrt(1+8*K2))/2;\n\nif floor(K)~=K\n error(['The number of elemeents in STACKED_DATA must be conformable to' ...\n 'the inverse vech operation.'])\nend\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Input Checking\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% Initialize the output data\nmatrixData=zeros(K);\n\n% Use a logical trick to inverse the vech\npl=tril(true(K));\nmatrixData(pl)=stackedData;\ndiag_matrixData=diag(diag(matrixData));\nmatrixData=matrixData+matrixData'-diag_matrixData;\n\n", "meta": {"author": "bashtage", "repo": "mfe-toolbox", "sha": "9622b6c546bc6d649fd9bf0a36a7fcd53872e04a", "save_path": "github-repos/MATLAB/bashtage-mfe-toolbox", "path": "github-repos/MATLAB/bashtage-mfe-toolbox/mfe-toolbox-9622b6c546bc6d649fd9bf0a36a7fcd53872e04a/utility/ivech.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.9099070005411124, "lm_q1q2_score": 0.8357316038973125}} {"text": "function [a, tri] = trifacet_signed_area(tri, x)\n% TRIFACET_SIGNED_AREA Signed area of the facets in a 2D triangulation.\n%\n% A = trifacet_signed_area(TRI, X)\n%\n% TRI is a 3-column matrix. Each row contains the 3 nodes that form one\n% triangular facet in the mesh.\n%\n% X is a 2-column matrix. X(i, :) contains the xy-coordinates of the\n% i-th node in the mesh.\n%\n% A is a vector where A(i) is the signed area of the i-th triangle.\n% Positive areas correspond to counter-clockwise triangles, and negative\n% areas, to clockwise triangles.\n%\n% [..., TRI2] = trifacet_signed_area(...)\n%\n% TRI2 returns TRI reoriented when necessary so that all triangles have\n% a positive signed area.\n\n% Author: Ramon Casero \n% Copyright © 2013 University of Oxford\n% Version: 0.2.0\n%\n% University of Oxford means the Chancellor, Masters and Scholars of\n% the University of Oxford, having an administrative office at\n% Wellington Square, Oxford OX1 2JD, UK. \n%\n% This file is part of Gerardus.\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. The offer of this\n% program under the terms of the License is subject to the License\n% being interpreted in accordance with English Law and subject to any\n% action against the University of Oxford being under the jurisdiction\n% of the English Courts.\n%\n% You should have received a copy of the GNU General Public License\n% along with this program. If not, see\n% .\n\n% check arguments\nnarginchk(2, 2);\nnargoutchk(0, 2);\n\nif (size(tri, 2) ~= 3)\n error('TRI must have 3 columns')\nend\nif (size(x, 2) ~= 2)\n error('X must have 2 columns')\nend\n\n% signed area of a triangle with vertices V1, V2, V3 in counter-clockwise\n% orientation\n%\n% a = 1/2*((x2-x1)(y3-y1) - (x3-x1)(y2-y1))\n\nx2x1 = x(tri(:, 2), 1) - x(tri(:, 1), 1);\ny3y1 = x(tri(:, 3), 2) - x(tri(:, 1), 2);\nx3x1 = x(tri(:, 3), 1) - x(tri(:, 1), 1);\ny2y1 = x(tri(:, 2), 2) - x(tri(:, 1), 2);\n\na = 0.5 * (x2x1 .* y3y1 - x3x1 .* y2y1);\n\n% reorient negative area triangles\nif (nargout > 1)\n \n % triangles with negative area\n idx = a < 0;\n \n % reorient triangles with negative area so that they become positive\n tri(idx, 1:2) = tri(idx, [2 1]);\n \nend\n", "meta": {"author": "vigente", "repo": "gerardus", "sha": "4d7c5195b826967781f1bb967872410e66b7cd3d", "save_path": "github-repos/MATLAB/vigente-gerardus", "path": "github-repos/MATLAB/vigente-gerardus/gerardus-4d7c5195b826967781f1bb967872410e66b7cd3d/matlab/ManifoldToolbox/trifacet_signed_area.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291501, "lm_q2_score": 0.8962513752119936, "lm_q1q2_score": 0.8357125553400918}} {"text": "function c = cardinal_cos ( j, m, t )\n\n%*****************************************************************************80\n%\n%% CARDINAL_COS evaluates the J-th cardinal cosine basis function.\n%\n% Discussion:\n%\n% The base points are T(I) = pi * I / ( M + 1 ), 0 <= I <= M + 1.\n% Basis function J is 1 at T(J), and 0 at T(I) for I /= J\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 12 May 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% John Boyd,\n% Exponentially convergent Fourier-Chebyshev quadrature schemes on\n% bounded and infinite intervals,\n% Journal of Scientific Computing,\n% Volume 2, Number 2, 1987, pages 99-109.\n%\n% Parameters:\n%\n% Input, integer J, the index of the basis function.\n% 0 <= J <= M + 1.\n%\n% Input, integer M, indicates the size of the basis set.\n%\n% Input, real T(*), one or more points in [0,pi] where the\n% basis function is to be evaluated.\n%\n% Output, real C, the value of the function at T.\n%\n if ( j == 0 || j == m + 1 )\n cj = 2.0;\n else\n cj = 1.0;\n end\n\n tj = pi * j / ( m + 1 );\n\n c = ( -1.0 ) ^ mod ( j + 1, 2 ) ...\n * sin ( t ) ...\n .* sin ( ( m + 1 ) * t ) ...\n / cj ...\n / ( m + 1 ) ...\n ./ ( cos ( t ) - cos ( tj ) );\n\n i = find ( abs ( t - tj ) < eps );\n c(i) = 1.0;\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/cc_project/cardinal_cos.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482725, "lm_q2_score": 0.8933094088947399, "lm_q1q2_score": 0.8355538426481891}} {"text": "function [x,y] = km_kde(data,sigma,nsteps,range_x)\n% KM_KDE performs kernel density estimation (KDE) on one-dimensional data\n% http://en.wikipedia.org/wiki/Kernel_density_estimation\n% \n% Input:\t- data: input data, one-dimensional\n% - sigma: bandwidth (sometimes called \"h\")\n% - nsteps: optional number of abscis points. If nsteps is an\n% array, the abscis points will be taken directly from it.\n% - range_x: optional factor for abscis expansion beyond extrema\n% Output:\t- x: equispaced abscis points\n%\t\t\t- y: estimates of p(x)\n% USAGE: [xx,pp] = km_kde(data,sigma,nsteps,range_x)\n%\n% Author: Steven Van Vaerenbergh (steven *at* gtas.dicom.unican.es), 2010.\n%\n% This file is part of the Kernel Methods Toolbox for MATLAB.\n% https://github.com/steven2358/kmbox\n\nN = length(data);\t% number of data points\n\nif (nargin<4), range_x = 1; end % default abscis expansion\nif (nargin<3), nsteps = 100; end % default number of abscis points\n\n% obtain full data range + extra bit\nmm(1) = min(data);\nmm(2) = max(data);\nif length(nsteps) > 1\n x = nsteps;\nelse\n xm = range_x*mm;\n if (mm(1)>0), xm(1)=mm(1)/range_x; end\n if (mm(2)<0), xm(2)=mm(2)/range_x; end\n x = linspace(xm(1),xm(2),nsteps);\nend\ny = zeros(size(x));\n\n% kernel density estimation\nc = 1/sqrt(2*pi*sigma^2);\nfor i=1:N,\n\ty = y + 1/N*c*exp(-(data(i)-x).^2/(2*sigma^2));\nend\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/lib/km_kde.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.8933094060543488, "lm_q1q2_score": 0.8355538399914392}} {"text": "function value = hermite_integral ( n )\n\n%*****************************************************************************80\n%\n%% HERMITE_INTEGRAL returns the value of a Hermite polynomial integral.\n%\n% Discussion:\n%\n% H(n) = Integral ( -oo < x < +oo ) x^n exp(-x^2) dx\n%\n% H(n) is 0 for n odd.\n%\n% H(n) = (n-1)!! * sqrt(pi) / 2^(n/2) for n even.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 July 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the integral.\n% 0 <= N.\n%\n% Output, real VALUE, the value of the integral.\n%\n if ( n < 0 )\n\n value = - r8_huge ( );\n\n elseif ( mod ( n, 2 ) == 1 )\n\n value = 0.0;\n\n else\n\n value = i4_factorial2 ( n - 1 ) * sqrt ( pi ) / 2.0^( n / 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/hermite_test_int/hermite_integral.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9504109798251322, "lm_q2_score": 0.8791467754256018, "lm_q1q2_score": 0.8355507482423518}} {"text": "function pdf = hypergeometric_pdf ( x, n, m, l )\n\n%*****************************************************************************80\n%\n%% HYPERGEOMETRIC_PDF evaluates the Hypergeometric PDF.\n%\n% Discussion:\n%\n% PDF(X)(N,M,L) = C(M,X) * C(L-M,N-X) / C(L,N).\n%\n% PDF(X)(N,M,L) is the probability of drawing X white balls in a\n% single random sample of size N from a population containing\n% M white balls and a total of L balls.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer X, the desired number of white balls.\n% 0 <= X <= N, usually, although any value of X can be given.\n%\n% Input, integer N, the number of balls selected.\n% 0 <= N <= L.\n%\n% Input, integer M, the number of white balls in the population.\n% 0 <= M <= L.\n%\n% Input, integer L, the number of balls to select from.\n% 0 <= L.\n%\n% Output, real PDF, the probability of exactly K white balls.\n%\n\n%\n% Special cases.\n%\n if ( x < 0 )\n\n pdf = 1.0;\n\n elseif ( n < x )\n\n pdf = 0.0;\n\n elseif ( m < x )\n\n pdf = 0.0;\n\n elseif ( l < x )\n\n pdf = 0.0;\n\n elseif ( n == 0 )\n\n if ( x == 0 )\n pdf = 1.0;\n else\n pdf = 0.0;\n end\n\n else\n\n c1 = binomial_coef_log ( m, x );\n c2 = binomial_coef_log ( l-m, n-x );\n c3 = binomial_coef_log ( l, n );\n\n pdf_log = c1 + c2 - c3;\n\n pdf = exp ( pdf_log );\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/prob/hypergeometric_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.953966101527047, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.835471102190492}} {"text": "function d = dcircle ( p, xc, yc, r )\n\n%*****************************************************************************80\n%\n%% DCIRCLE returns the signed distance of one or more points to a circle.\n%\n% Discussion:\n%\n% The corresponding routine in 3D is DSPHERE.\n%\n% Licensing:\n%\n% (C) 2004 Per-Olof Persson. \n% See COPYRIGHT.TXT for details.\n%\n% Reference:\n%\n% Per-Olof Persson and Gilbert Strang,\n% A Simple Mesh Generator in MATLAB,\n% SIAM Review,\n% Volume 46, Number 2, June 2004, pages 329-345.\n%\n% Parameters:\n%\n% Input, real P(NP,2), the point coordinates.\n%\n% Input, real XC, YC, the coordinates of the center of the circle.\n%\n% Input, real R, the radius of the circle.\n%\n% Output, real D(NP), the signed distance of each point to the\n% circle. The point is inside, on, or outside the circle depending\n% on whether D is negative, zero, or positive.\n%\n d = sqrt ( ( p(:,1) - xc ).^2 + ( p(:,2) - yc ).^2 ) - r;\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/distmesh/dcircle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.953966098909522, "lm_q2_score": 0.8757869786798663, "lm_q1q2_score": 0.8354710875269888}} {"text": "function [A,d]=affineTransBetweenTriangles(v1,v2)\n%%AFFINETRANSBETWEENTRIANGLES Given the vertices of one triangle in 2D and\n% the vertices of a second triangle in 2D, obtain a matrix M and a\n% vector d such that p2=M*p1+d transforms a point p1 in the first\n% triangle into a point p2 in the second triangle.\n%\n%INPUTS: v1 The 2X3 set of vertices in the first triangle.\n% v2 The 2X3 set of vertices in the second triangle (into which we\n% wish to transform the first triangle).\n%\n%OUTPUTS: A A 2X2 scale/rotation matrix.\n% d A 2X1 origin shift vector.\n%\n%Equations for the transformation are given in Chapter 5 of [1].\n%\n%EXAMPLE:\n%This just find the transformation between two sets of vertices and\n%transforms the first set of vertices into the second set. The error is on\n%the order of typical finite precision limitations.\n% v1=[ 5, -22, 3;\n% 18, 8, -13];\n% v2=[-4, 35, -13;\n% 3, 27, 30];\n% [A,d]=affineTransBetweenTriangles(v1,v2);\n% v2Trans=bsxfun(@plus,A*v1,d);\n% RelErr=max(abs((v2Trans-v2)./v2))\n%\n%REFERENCES:\n%[1] K. Anjyo and H. Ochiai, Mathematical Basics of Motion and Deformation\n% in Computer Graphics, 2nd ed. Morgan and Claypool Publishers, 2017.\n%\n%October 2022 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nA1=[v1;\n 1,1,1];\nA2=[v2;\n 1,1,1];\n\nM=A2/A1;\n\nA=M(1:2,1:2);\nd=M(1:2,3);\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/Geometry/affineTransBetweenTriangles.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475778774728, "lm_q2_score": 0.885631476836816, "lm_q1q2_score": 0.8354583085660595}} {"text": "function [mu sigma2] = estimateGaussian(X)\n%ESTIMATEGAUSSIAN This function estimates the parameters of a \n%Gaussian distribution using the data in X\n% [mu sigma2] = estimateGaussian(X), \n% The input X is the dataset with each n-dimensional data point in one row\n% The output is an n-dimensional vector mu, the mean of the data set\n% and the variances sigma^2, an n x 1 vector\n% \n\n% Useful variables\n[m, n] = size(X);\n\n% You should return these values correctly\nmu = zeros(n, 1);\nsigma2 = zeros(n, 1);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the mean of the data and the variances\n% In particular, mu(i) should contain the mean of\n% the data for the i-th feature and sigma2(i)\n% should contain variance of the i-th feature.\n%\n\n\n\nmu = sum(X)./size(X,1);\nmurep = repmat(mu, [size(X,1) 1]);\nsigma2 = sum((X-murep).^2)/size(X,1);\n\n\n\n\n\n% =============================================================\n\n\nend\n", "meta": {"author": "1094401996", "repo": "machine-learning-coursera", "sha": "e53d1021a08b0f2ab7e0840d9807ab14e24ea9bb", "save_path": "github-repos/MATLAB/1094401996-machine-learning-coursera", "path": "github-repos/MATLAB/1094401996-machine-learning-coursera/machine-learning-coursera-e53d1021a08b0f2ab7e0840d9807ab14e24ea9bb/problem_sets/ex8/estimateGaussian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475762847495, "lm_q2_score": 0.8856314723088732, "lm_q1q2_score": 0.8354583028840697}} {"text": "%% Principal Component Analysis and Partial Least Squares\n% Principal Component Analysis (PCA) and Partial Least Squares (PLS) are\n% widely used tools. This code is to show their relationship through the\n% Nonlinear Iterative PArtial Least Squares (NIPALS) algorithm.\n\n%% The Eigenvalue and Power Method\n% The NIPALS algorithm can be derived from the Power method to solve the\n% eigenvalue problem. Let x be the eigenvector of a square matrix, A,\n% corresponding to the eignvalue s:\n%\n% $$Ax=sx$$\n%\n% Modifying both sides by A iteratively leads to\n%\n% $$A^kx=s^kx$$\n%\n% Now, consider another vectro y, which can be represented as a linear\n% combination of all eigenvectors:\n%\n% $$y=\\sum_i^n b_ix_i=Xb$$\n%\n% where\n%\n% $$X=\\left[x_1\\,\\,\\, \\cdots\\,\\,\\, x_n \\right]$$\n%\n% and\n%\n% $$b = \\left[b_1\\,\\,\\, \\cdots\\,\\,\\, b_n \\right]^T$$\n%\n% Modifying y by A gives\n%\n% $$Ay=AXb=XSb$$\n%\n% Where S is a diagnal matrix consisting all eigenvalues. Therefore, for\n% a large enough k,\n%\n% $$A^ky=XS^kb\\approx \\alpha x_1$$\n%\n% That is the iteration will converge to the direction of x_1, which is the\n% eigenvector corresponding to the eigenvalue with the maximum module.\n% This leads to the following Power method to solve the eigenvalue problem.\n\nA=randn(10,5);\n% sysmetric matrix to ensure real eigenvalues\nB=A'*A;\n%find the column which has the maximum norm\n[dum,idx]=max(sum(A.*A));\nx=A(:,idx);\n%storage to judge convergence\nx0=x-x;\n%convergence tolerant\ntol=1e-6;\n%iteration if not converged\nwhile norm(x-x0)>tol\n %iteration to approach the eigenvector direction\n y=A'*x;\n %normalize the vector\n y=y/norm(y);\n %save previous x\n x0=x;\n %x is a product of eigenvalue and eigenvector\n x=A*y;\nend\n% the largest eigen value corresponding eigenvector is y\ns=x'*x;\n% compare it with those obtained with eig\n[V,D]=eig(B);\n[d,idx]=max(diag(D));\nv=V(:,idx);\ndisp(d-s)\n% v and y may be different in signs\ndisp(min(norm(v-y),norm(v+y)))\n\n%% The NIPALS Algorithm for PCA\n% The PCA is a dimension reduction technique, which is based on the\n% following decomposition:\n%\n% $$X=TP^T+E$$\n%\n% Where X is the data matrix (m x n) to be analysed, T is the so called\n% score matrix (m x a), P the loading matrix (n x a) and E the residual.\n% For a given tolerance of residual, the number of principal components, a,\n% can be much smaller than the orginal variable dimension, n. \n% The above power algorithm can be extended to get T and P by iteratively\n% subtracting A (in this case, X) by x*y' (in this case, t*p') until the\n% given tolerance satisfied. This is the so called NIPALS algorithm.\n\n% The data matrix with normalization\nA=randn(10,5);\nmeanx=mean(A);\nstdx=std(A);\nX=(A-meanx(ones(10,1),:))./stdx(ones(10,1),:);\nB=X'*X;\n% allocate T and P\nT=zeros(10,5);\nP=zeros(5);\n% tol for convergence\ntol=1e-6;\n% tol for PC of 95 percent\ntol2=(1-0.95)*5*(10-1);\nfor k=1:5\n %find the column which has the maximum norm\n [dum,idx]=max(sum(X.*X));\n t=A(:,idx);\n %storage to judge convergence\n t0=t-t;\n %iteration if not converged\n while norm(t-t0)>tol\n %iteration to approach the eigenvector direction\n p=X'*t;\n %normalize the vector\n p=p/norm(p);\n %save previous t\n t0=t;\n %t is a product of eigenvalue and eigenvector\n t=X*p;\n end\n %subtracing PC identified\n X=X-t*p';\n T(:,k)=t;\n P(:,k)=p;\n if norm(X) 2;\n objfunvals = [];\n xkk = [];\n \n if(isempty(alpha))\n alpha = .5*norm(Atb,'inf');\n end\n \n if(isempty(opts.tau))\n %Use iterative method to find the Lipschitz constant\n opts.tau = svds(A,1).^2;\n end \n \n %Setup reporting functions if quiet mode is disabled\n if(opts.verbose)\n fprintf('\\n*******************************************\\n');\n fprintf('* FISTA: SPARSE VECTOR RECONSTRUCTION \\n');\n if(is_complex)\n \tfprintf('* CMPLX : %s\\n','true');\n else\n fprintf('* CMPLX : %s\\n','false');\n end\n fprintf('* MAXITER : %d\\n',opts.maxiter);\n fprintf('* TOL : %e\\n',opts.tol);\n if(opts.restart)\n fprintf('* RESTART : %s\\n','true');\n else\n fprintf('* RESTART : %s\\n','false');\n end\n fprintf('* STOPCRIT : %s\\n',opts.stopcrit);\n fprintf('*******************************************\\n');\n msgstr = ['Current Precision: ',num2str(inf)];\n h = waitbar(0,msgstr); \n precision = zeros(opts.maxiter,1);\n objfun = @(x) ObjFunc(x,A,b,alpha);\n objfunvals = zeros(opts.maxiter,1);\n end\n if(keep_history)\n xkk = zeros(length(xk),opts.maxiter);\n end\n \n %% MAINLOOP\n \n while(nn < opts.maxiter)\n if opts.verbose\n objfunvals(nn+1) = objfun(xk); %#ok<*AGROW>\n end\n if(keep_history)\n xkk(:,nn+1) = xk;\n end\n \n yk = xk + ((tp-1)/tk)*(xk - xp);\n grd = At*(A*yk) - Atb;\n xp = xk;\n if(opts.backtracking)\n % solve the local regularization problem with an appropriate\n % step size\n [xk,opts.tau] = LineSearch(A,b,grd,alpha,yk,opts.tau);\n else\n xk = sparse(shrink(yk - (1/opts.tau)*grd,alpha/opts.tau));\n end\n\n % check stopping criterion\n switch(lower(opts.stopcrit))\n case 'cauchy'\n prec = norm(xk(:) - yk(:))/max(norm(xk),1);\n case 'subgradient'\n % we need to estimate the subgradient at current pt\n % optimality occurs at zero\n prec = ComputeOptimalityResidue(A,At,xk,Atb,alpha);\n end\n if(prec < opts.tol)\n has_converged = true;\n break;\n end\n \n % keep going\n nn = nn + 1;\n tp = tk;\n tk = 0.5*(1+sqrt(1+4*tk*tk));\n \n % check if a restart is necessary\n if(opts.restart && ((yk - xk)'*(xk - xp) > 0))\n % forget all previous iterations\n % and reset momentum back to zero\n tp = 1;\n tk = 1;\n end \n if(opts.verbose)\n precision(nn) = prec;\n waitbar(nn/opts.maxiter,h,['Current precision: ',num2str(prec)]);\n end\n end\n if(~has_converged)\n warning('MATLAB:no_convergence','method failed to converge within given time steps');\n end\n \n %% Post-processing\n if(opts.verbose)\n waitbar(1,h);\n objfunvals = objfunvals(1:nn);\n precision = precision(1:nn);\n iter = 0:nn-1;\n figure;\n semilogy(iter,objfunvals,'--r','linewidth',1.2);\n grid on;\n title(['Objective Function for \\alpha = ',num2str(alpha)]);\n xlabel('ITERATION');\n ylabel('FOBJ VAL');\n \n figure;\n semilogy(iter,precision,'--g','linewidth',1.2);\n grid on;\n title(['Precision for \\alpha = ',num2str(alpha)]);\n xlabel('ITERATION');\n ylabel('PREC LVL');\n close(h);\n end\n if(opts.return_as_dense)\n xk = full(xk);\n if keep_history\n xkk = full(xkk(:,1:nn));\n end\n end\n if(is_complex)\n xk = complex(xk(1:n),xk(n+1:end));\n if(keep_history)\n xkk = complex(xkk(1:n,:),xkk(n+1:end,:));\n end\n end\n\nend\n%% UTILITY\n% defines the standard shrinkage operator. \nfunction z = shrink(x,mu)\n z = sign(x).*max(abs(x)-mu,0);\nend\n\n% Experimental stopping criteria particlarly for proximal gradient methods.\n% It is not clear if this can help issues do non-strict convexivity of the\n% data fidelity term\nfunction prec = ComputeOptimalityResidue(A,At,xk,Atb,alpha)\n % first compute the gradient at the current point\n gradF = At*(A*xk) - Atb;\n \n % compute the unique portion of the sub-gradient\n subGrad = alpha*sign(xk);\n \n % now for the points that are zero minimize the\n % optimality residue\n inds = find(subGrad == 0);\n \n % compute solution to the constrained\n % sub optimization problem\n g = gradF(inds);\n y = zeros(size(g));\n \n for i=1:50\n yp = y;\n lambda = abs(y+g)/alpha;\n y = (y - .5*(y+g))./(1 - .5*lambda);\n if(norm(y-yp)/max([norm(y),1]) < 1e-5)\n break;\n end\n end\n subGrad(inds) = y;\n \n % evaluate the maximum sub-gradient component\n prec = norm(gradF + subGrad,'inf');\nend\n\n% returns the objective function value of the unconstrained l2-l1 problem\nfunction val = ObjFunc(x,A,b,alpha)\n val = .5*norm(A*x - b).^2 + alpha*norm(x,1);\nend\n\n% A straight-forward line search method for first order methods\nfunction [xk,fxk,L] = LineSearch(A,b,grd,alpha,yk,L)\n beta = 1.2;\n stopBacktrack = false;\n fyk = .5*norm(A*yk - b).^2 + alpha*norm(yk,1); \n while(~stopBacktrack)\n % predict the next value\n xk = sparse(shrink(yk - (1/L)*grd,alpha/L));\n fxk = .5*norm(A*xk - b).^2 + alpha*norm(xk,1); \n\n % find the Lipschitz constant that ensures the Taylor\n % expansion is valid\n q = fyk + (xk-yk)'*grd + 0.5*L*norm(xk-yk).^2 + alpha*norm(xk,1);\n if(fxk <= q)\n stopBacktrack = true;\n else\n % increase the Lipschitz constant estimate \n L = L*beta;\n end\n end\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/Continuous_Optimization/solveLASSOProblem.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582477806522, "lm_q2_score": 0.8976952832120991, "lm_q1q2_score": 0.8352679802584861}} {"text": "function [f, df, ddf] = rosenbrock(x);\n\n% rosenbrock.m This function returns the function value, partial derivatives\n% and Hessian of the (general dimension) rosenbrock function, given by:\n%\n% f(x) = sum_{i=1:D-1} 100*(x(i+1) - x(i)^2)^2 + (1-x(i))^2 \n%\n% where D is the dimension of x. The true minimum is 0 at x = (1 1 ... 1).\n%\n% Carl Edward Rasmussen, 2001-07-21.\n\nD = length(x);\nf = sum(100*(x(2:D)-x(1:D-1).^2).^2 + (1-x(1:D-1)).^2);\n\nif nargout > 1\n df = zeros(D, 1);\n df(1:D-1) = - 400*x(1:D-1).*(x(2:D)-x(1:D-1).^2) - 2*(1-x(1:D-1));\n df(2:D) = df(2:D) + 200*(x(2:D)-x(1:D-1).^2);\nend\n\nif nargout > 2\n ddf = zeros(D,D);\n ddf(1:D-1,1:D-1) = diag(-400*x(2:D) + 1200*x(1:D-1).^2 + 2);\n ddf(2:D,2:D) = ddf(2:D,2:D) + 200*eye(D-1);\n ddf = ddf - diag(400*x(1:D-1),1) - diag(400*x(1:D-1),-1);\nend\n", "meta": {"author": "visva89", "repo": "pTVreg", "sha": "c359620e3c8435392db02354274d6c74d682d437", "save_path": "github-repos/MATLAB/visva89-pTVreg", "path": "github-repos/MATLAB/visva89-pTVreg/pTVreg-c359620e3c8435392db02354274d6c74d682d437/mutils/My/minFunc_2012_mod/rosenbrock.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951863227517834, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.835237879379817}} {"text": "function table = hn_exponential_product ( p, b )\n\n%*****************************************************************************80\n%\n%% HN_EXPONENTIAL_PRODUCT: exponential products exp(b*x)*Hn(i,x)*Hn(j,x).\n%\n% Discussion:\n%\n% Hn(i,x) is the normalized physicist's Hermite 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 exp(B*X) with every possible pair\n% of basis functions. That is, we'd like to form\n%\n% Tij = Integral ( -oo < X < +oo ) exp(B*X) * Hn(I,X) * Hn(J,X) exp(-X*X) dx\n%\n% We will estimate these integrals using Gauss-Hermite quadrature.\n% Because of the exponential factor exp(B*X), the quadrature will not \n% be exact.\n%\n% However, when B = 0, the quadrature is exact, and moreoever, the\n% table will be the identity matrix.\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% Parameters:\n%\n% Input, integer P, the maximum degree of the polyonomial factors.\n% 0 <= P.\n%\n% Input, real B, the coefficient of X in the exponential factor.\n%\n% Output, real TABLE(P+1,P+1), the table of integrals. TABLE(I,J)\n% represents the weighted integral of exp(B*X) * Hn(I+1,X) * Hn(J+1,X).\n%\n table(1:p+1,1:p+1) = 0.0;\n\n order = floor ( ( 3 * p + 4 ) / 2 );\n\n [ x_table, w_table ] = h_quadrature_rule ( order );\n r8vec2_print ( order, x_table, w_table, ' Quadrature rule:' );\n\n for k = 1 : order\n\n x = x_table(k);\n h_table = hn_polynomial_value ( 1, p, x );\n%\n% The following formula is an outer product in H_TABLE.\n%\n table(1:p+1,1:p+1) = table(1:p+1,1:p+1) ...\n + w_table(k) * exp ( b * x ) * h_table(1:p+1)' * h_table(1:p+1);\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/hermite_polynomial/hn_exponential_product.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.8902942203004186, "lm_q1q2_score": 0.8352063832147859}} {"text": "function er3OC_sym\n%EG3OC_sym Example 3 of optimal control tutorial.\n% This example is from D.S.Naidu, \"Optimal contorl systems\"\n% page 77-80, Example 2.14\n% Symbolic toolbox is used to get the analytical solution\n\nsol = dsolve('Dx1 = x2, Dx2 = -p2, Dp1 = 0, Dp2 = -p1',...\n 'x1(0) = 1, x2(0) = 2, x1(tf) = 3, p2(tf) = 0');\neq1 = subs(sol.x1) - 'x1tf';\neq2 = subs(sol.x2) - 'x2tf';\neq3 = subs(sol.p1) - 'p1tf';\neq4 = subs(sol.p2) - 'p2tf';\neq5 = sym('p1tf*x2tf - 0.5*p2tf^2');\n%%\nsol_2 = solve(eq1, eq2, eq3, eq4, eq5);\ntf = sol_2.tf;\nx1tf = sol_2.x1tf;\nx2tf = sol_2.x2tf;\n\nx1 = subs(sol.x1);\nx2 = subs(sol.x2);\np1 = subs(sol.p1);\np2 = subs(sol.p2);\n\n%%\nsol_book = {@(t)((4/54).*t.^3-(2/3)*t.^2+2.*t+1),...\n @(t)((4/18).*t.^2-(4/3).*t+2)};\nu = @(t)((4/9).*t-(4/3));\nt = double(tf);\ntime = linspace(0,t,20);\ns_book = [sol_book{1}(time);sol_book{2}(time)];\nut = u(time);\n\nfigure(1);\nezplot(x1,[0 t]); hold on;\nezplot(x2,[0 t]);\nplot(time, s_book,'*');\nplot(time, ut, 'k:');\naxis([0 t -1.5 3]);\ntext(1.3,2.5,'x_1(t)');\ntext(1.3,1,'x_2(t)');\ntext(1.3,-.5,'u(t)');\nxlabel('time');\nylabel('states');\ntitle('Analytical solution');\nhold off;\n% print -djpeg90 -r300 eg3a.jpg\n\n%% ------------------------------------------------------------------------\n% % The same procedure applied on example problem 1 with tf unknown.\n% % no explicit solution could be found\n% sol = dsolve('Dx1 = x2, Dx2 = -x2 - p2, Dp1 = 0, Dp2 = p1 - p2',...\n% 'x1(0) = 1, x2(0) = 2, x1(tf) = 5, x2(tf) = 2');\n% eq1 = subs(sol.x1) - 'x1tf';\n% eq2 = subs(sol.x2) - 'x2tf';\n% eq3 = subs(sol.p1) - 'p1tf';\n% eq4 = subs(sol.p2) - 'p2tf';\n% eq5 = sym('p1tf*x2tf-p2tf*x2tf-0.5*p2tf^2');\n% \n% sol_2 = solve(eq1, eq2, eq3, eq4, eq5);\n% tf = sol_2.tf;\n% x1tf = sol_2.x1tf;\n% x2tf = sol_2.x2tf;\n% clear t;\n% x1 = subs(sol.x1);\n% x2 = subs(sol.x2);\n% p1 = subs(sol.p1);\n% p2 = subs(sol.p2);", "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/25889-an-optimal-control-tutorial-for-beginners/er3OC_sym.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692238, "lm_q2_score": 0.90052978812007, "lm_q1q2_score": 0.8351182775625147}} {"text": "function [intT,T]=ChebyshevPolyInt(tau,n,tauStart,tauEnd)\n%%CHEBYSHEVPOLYDERIV Compute the indefinite integral (with zero additive\n% constant) of Chebyshev polynomials of the first kind\n% from order 0 to order n evaluated at the points given\n% in tau.\n%\n%INPUTS: tau An NX1 or 1XN vector of values from tauStart to tauEnd, or\n% from -1 to 1 if tauStart and tauEnd are omitted, where one\n% wishes to evaluate the indefinite integrals (antiderivatives)\n% of the Chebyshev polynomials.\n% n The non-negative integer maximum order of the Chebyshev\n% polynomials evaluated.\n% tauStart,tauEnd The possible range of the inputs. If omitted, a range of\n% -1 to 1 is assumed --the normal range for Chebyshev\n% polynomials. The option for mapping to a wider range is useful\n% when using Chebyshev polynomials for interpolation. Note that\n% such polynomials are generally not useful for interpolating\n% far outside of the valid range.\n%\n%OUTPUTS: dT An (n+1)XN matrix of the antiderivatives of the Chebyshev\n% polynomials from order 0 to n evaluated at each of the values\n% of tau. T(i,j) is the antiderivative of the (i-1)th order\n% Chebyshev polynomial evaluated at tau(j), taking into account\n% that the function has been mapped to the range\n% (tauStart,tauEnd), if necessary.\n% T Since the Chebyshev functions have to be computed to find the\n% indefinite integrals, an (n+2)XN matrix of the Chebyshev\n% functions can also be returned, if desired\n%\n%The recursion for finding the indefinite integral values can be obtained\n%by examining how the function ChebyshevPolyIntCoeffs modifies the\n%coefficients of a weighted series of Chebyshev polynomials when only a\n%single 1 is present for each given order.\n%\n%September 2014 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nN=length(tau);\ntau=tau(:)';%Make tau into a column vector.\n%Map the tau values to the -1 to 1 range, if necessary.\nif(nargin>2)\n tau=(tau-0.5*(tauStart+tauEnd))/(0.5*(tauEnd-tauStart));\nend\n\n%Get the Chebyshev polynomial function values.\nT=ChebyshevPoly(tau,n+1);\nintT=zeros(n+1,N);\n\n%Deal with the n=0 case.\ncurN=0;\nintT(curN+1,:)=T(curN+1+1,:);\n\nif(n>0)\n %Deal with the n=1 case.\n curN=1;\n intT(curN+1,:)=0.5*(T(curN+1+1,:)/(curN+1)+0.5);\nend\n\n%Perform recusion for the rest of the values.\nfor curN=2:n\n intT(curN+1,:)=0.5*(T(curN+1+1,:)/(curN+1)-T(curN-1+1,:)/(curN-1));\nend\n\n%The constant to handle a mapping from -1->1 to some other range of\n%parameters.\nif(nargin>2)\n intT=intT*((tauEnd-tauStart)/2);\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/Polynomials/ChebyshevPolyInt.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632916317102, "lm_q2_score": 0.9005297927918167, "lm_q1q2_score": 0.835118272855841}} {"text": "function theta = lineAngle(varargin)\n%LINEANGLE Computes angle between two straight lines.\n%\n% A = lineAngle(LINE);\n% Returns the angle between horizontal, right-axis and the given line.\n% Angle is fiven in radians, between 0 and 2*pi, in counter-clockwise\n% direction.\n%\n% A = lineAngle(LINE1, LINE2);\n% Returns the directed angle between the two lines. Angle is given in\n% radians between 0 and 2*pi, in counter-clockwise direction.\n%\n% See also\n% lines2d, angles2d, createLine, normalizeAngle\n%\n% ---------\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 31/10/2003.\n%\n\n% HISTORY\n% 2004-02-19 added support for multiple lines.\n% 2011-01-20 use bsxfun\n\nnargs = length(varargin);\nif nargs == 1\n % angle of one line with horizontal\n line = varargin{1};\n theta = mod(atan2(line(:,4), line(:,3)) + 2*pi, 2*pi);\n \nelseif nargs==2\n % angle between two lines\n theta1 = lineAngle(varargin{1});\n theta2 = lineAngle(varargin{2});\n theta = mod(bsxfun(@minus, theta2, theta1)+2*pi, 2*pi);\nend\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/private/lineAngle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9591542805873231, "lm_q2_score": 0.8705972549785201, "lm_q1q2_score": 0.8350370837802208}} {"text": "function intVal=monomialIntCubicalShell(alpha,K1,K2)\n%%MONOMIALINTCUBALSHELL Evaluate the integral of prod_{i=1}^N x(i)^alpha(i)\n% taken over the region K1<=x(i)<=K2 with 0=0.\n% K1, K2 Two positive, finite, real values such that 0sqrt(flintmax))\n error('The algorithm will not work with n>sqrt(flintmax).') \nend\n\nif(nargin<2||isempty(numRuns))\n numRuns=25;\nend\n\n%If divisible by 2.\nif(mod(n,2)==0)\n boolVal=false;\n return\nend\n\n%We now want to find an odd q such that n-1=2^k*q\nq=n-1;\nk=0;\npow2Val=1;\nwhile(mod(q,2)==0)\n pow2Val=pow2Val*2;\n q=q/2;\n k=k+1;\nend\n\nfor curRun=1:numRuns\n %Step P1\n x=randi(n-2)+1;%10)\n boolVal=false;\n return\n end\n\n j=j+1;\n if(j1\n error('Invalid time series.');\n end\n x=x(:);\nend\n\nif nargin<2 | isempty(c)==1\n c=1;\nelse\n % c must be scalar\n if sum(size(c))>2\n error('c must be scalar.');\n end\n % c must be greater or equal than 1\n if c<1\n error('c must be greater or equal than 1.');\n end\nend\n\nif nargin<3 | isempty(maxiter)==1\n maxiter=1000;\nelse\n % maxiter must be scalar\n if sum(size(maxiter))>2\n error('maxiter must be scalar.');\n end\n % maxiter must be greater or equal than 1\n if maxiter<1\n error('maxiter must be greater or equal than 1.');\n end\nend\n\n% The magnitudes of x\namp=abs(fft(x));\n\n% Shuffle x\ns=shuffle(x,c);\n\n% Sort x\n[x,r]=sort(x);\n\n\nfor j=1:c\n \n % Calculate the phases of the shuffled series\n phase=angle(fft(s(:,j)));\n \n % Initialize the loop\n k=1;\n indold=r;\n converge = 0;\n while k<=maxiter & converge == 0 \n % Make phase-randomized surrogates ...\n s(:,j)=amp.*exp(phase.*i); \n s(:,j)=real(ifft(s(:,j)));\n % ... and give them the distribution of x\n [s(:,j),T]=sort(s(:,j));\n [s(:,j),indnew]=sort(T);\n s(:,j)=x(indnew);\n % Check the convergence\n if indnew==indold\n converge=1;\n else\n indold=indnew;\n k=k+1;\n end\n % Loop again if needed, calculating the phases once more\n phase=angle(fft(s(:,j)));\n end\n \n % Get the iterations of each surrogate series\n iter(j)=k;\n \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/1597-chaotic-systems-toolbox/IAAFT.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362855, "lm_q2_score": 0.8991213705121082, "lm_q1q2_score": 0.8347521949319303}} {"text": "function lebesgue_test04 ( )\n\n%*****************************************************************************80\n%\n%% LEBESGUE_TEST04 looks at Chebyshev4 points.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 17 January 2015\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LEBESGUE_TEST04:\\n' );\n fprintf ( 1, ' Analyze Chebyshev4 points.\\n' );\n\n n_max = 11;\n l = zeros ( n_max, 1 );\n xfun = linspace ( -1.0, +1.0, 501 );\n xfun = xfun';\n\n for n = 1 : n_max\n x = chebyshev4 ( n );\n l(n) = lebesgue_constant ( n, x, xfun );\n end\n\n r8vec_print ( n_max, l, ' Chebyshev4 Lebesgue constants for N = 1 to 11:' )\n%\n% Examine one case more closely.\n%\n n = 11;\n x = chebyshev4 ( n );\n r8vec_print ( n, x, ' Chebyshev4 points for N = 11' );\n\n label = 'Chebyshev4 points for N = 11';\n filename = 'chebyshev4.png';\n lebesgue_plot ( n, x, xfun, label, filename );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Plot file saved as \"s\"\\n', filename );\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/lebesgue/lebesgue_test04.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.9161096158798117, "lm_q1q2_score": 0.8347404963460083}} {"text": "function cU = chebTcoeffs2chebUcoeffs(cT)\n%CHEBTCOEFFS2CHEBUCOEFFS Convert Chebyshev-T coeffs. to Chebyshev-U coeffs.\n% CU = CHEBTCOEFFS2CHEBUCOEFFS(CT) takes a column vector of coefficients of a\n% polynomial represented as an expansion in the Chebyshev polynomials of the\n% first kind T_k(x) (ordered starting with the coefficient of T_0(x)) and\n% returns the column vector of coefficients of the same polynomial expanded\n% in Chebyshev polynomials of the second kind U_k(x) (ordered starting with\n% the coefficient of U_0(x)).\n%\n% If CT is a matrix, the conversion is performed column-wise.\n\n% Copyright 2017 by The University of Oxford and The Chebfun Developers.\n% See http://www.chebfun.org/ for Chebfun information.\n\nif ( isempty(cT) )\n cU = [];\n return;\nend\n\n% We compute 2nd-kind coefficients from the 1st-kind coefficients\n% using the recurrence T_n(x) = (1/2)*(U_n(x) - U_{n-2}(x)). The\n% coefficient of U_n requires the coefficients of T_n and T_{n + 2}, so we\n% pad with two zero-coefficients initially.\nnCols = size(cT, 2);\ncU = [cT ; zeros(2,nCols)];\n\n% Run the recurrence.\ncU(1,:) = 2*cT(1,:);\ncU = 0.5*[cU(1:end-2,:) - cU(3:end,:) ; cU(end-1:end,:)];\ncU = cU(1:end-2,:);\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/@chebtech/chebTcoeffs2chebUcoeffs.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996141, "lm_q2_score": 0.8856314783461303, "lm_q1q2_score": 0.8347136208471783}} {"text": "function [U, S] = pca(X)\n%PCA Run principal component analysis on the dataset X\n% [U, S, X] = pca(X) computes eigenvectors of the covariance matrix of X\n% Returns the eigenvectors U, the eigenvalues (on diagonal) in S\n%\n\n% Useful values\n[m, n] = size(X);\n\n% You need to return the following variables correctly.\nU = zeros(n);\nS = zeros(n);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: You should first compute the covariance matrix. Then, you\n% should use the \"svd\" function to compute the eigenvectors\n% and eigenvalues of the covariance matrix. \n%\n% Note: When computing the covariance matrix, remember to divide by m (the\n% number of examples).\n%\n\nSigma = ((1.0/m) .* (X' * X));\n[U, S, V] = svd(Sigma);\n\n% =========================================================================\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-ex7/ex7/pca.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067211996141, "lm_q2_score": 0.8856314783461303, "lm_q1q2_score": 0.8347136208471783}} {"text": "function [J, grad] = costFunctionReg(theta, X, y, lambda)\n%COSTFUNCTIONREG Compute cost and gradient for logistic regression with regularization\n% J = COSTFUNCTIONREG(theta, X, y, lambda) computes the cost of using\n% theta as the parameter for regularized logistic regression and the\n% gradient of the cost w.r.t. to the parameters. \n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n\nJ = ((-1/m)*((y'*log(sigmoid(X*theta))) + ((1-y)'*log(1 - sigmoid(X*theta))))) + ((lambda/(2*m))*((theta' * theta)-(theta(1)^2)));\n\ngrad = ((1/m)*(X' * (sigmoid(X*theta) - y)))+((lambda/m)*(theta));\n\ngrad(1) = grad(1) - ((lambda/m)*(theta(1)));\n\n% =============================================================\n\nend\n", "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-ex2/ex2/costFunctionReg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9688561676667173, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.8347066113322014}} {"text": "function a = c8vec_unity ( n )\n\n%*****************************************************************************80\n%\n%% C8VEC_UNITY returns the N roots of unity.\n%\n% Discussion:\n%\n% A(1:N) = exp ( 2 * PI * (0:N-1) / N )\n%\n% A(1:N)^N = ( (1,0), (1,0), ..., (1,0) ).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 13 September 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of elements of A.\n%\n% Output, complex A(N,1), the N roots of unity.\n%\n x = 0 : 2 : 2 * n - 2;\n theta = pi * ( x' ) / n;\n a(1:n,1) = cos ( theta ) + i * sin ( theta );\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/c8vec_unity.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.8840392817460333, "lm_q1q2_score": 0.8346894321525813}} {"text": "function area = sphere_unit_area_nd ( dim_num )\n\n%*****************************************************************************80\n%\n%% SPHERE_UNIT_AREA_ND computes the surface area of a unit sphere in ND.\n%\n% Discussion:\n%\n% The unit sphere in ND satisfies:\n%\n% sum ( 1 <= I <= DIM_NUM ) X(I) * X(I) = 1\n%\n% Results for the first few values of N are:\n%\n% DIM_NUM Area\n%\n% 2 2 * PI\n% 3 4 * PI\n% 4 ( 2 / 1) * PI**2\n% 5 ( 8 / 3) * PI**2\n% 6 ( 1 / 1) * PI**3\n% 7 (16 / 15) * PI**3\n% 8 ( 1 / 3) * PI**4\n% 9 (32 / 105) * PI**4\n% 10 ( 1 / 12) * PI**5\n%\n% For the unit sphere, Area(DIM_NUM) = DIM_NUM * Volume(DIM_NUM)\n%\n% Sphere_Unit_Area ( DIM_NUM ) = 2 * PI**(DIM_NUM/2) / Gamma ( DIM_NUM / 2 )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 February 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the dimension of the space.\n%\n% Output, real SPHERE_UNIT_AREA_ND, the area of the sphere.\n%\n if ( mod ( dim_num, 2 ) == 0 )\n m = floor ( dim_num / 2 );\n area = 2.0 * pi^m;\n for i = 1 : m-1\n area = area / i;\n end\n else\n m = floor ( ( dim_num - 1 ) / 2 );\n area = pi^m * 2.0^dim_num;\n for i = m+1 : 2*m\n area = area / i;\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/quadrature_test/sphere_unit_area_nd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.8872045952083047, "lm_q1q2_score": 0.8346729916129327}} {"text": "% ECEF2LLA - convert earth-centered earth-fixed (ECEF)\n% cartesian coordinates to latitude, longitude,\n% and altitude\n%\n% USAGE:\n% [lat,lon,alt] = ecef2lla(x,y,z)\n%\n% lat = geodetic latitude (radians)\n% lon = longitude (radians)\n% alt = height above WGS84 ellipsoid (m)\n% x = ECEF X-coordinate (m)\n% y = ECEF Y-coordinate (m)\n% z = ECEF Z-coordinate (m)\n%\n% Notes: (1) This function assumes the WGS84 model.\n% (2) Latitude is customary geodetic (not geocentric).\n% (3) Inputs may be scalars, vectors, or matrices of the same\n% size and shape. Outputs will have that same size and shape.\n% (4) Tested but no warranty; use at your own risk.\n% (5) Michael Kleder, April 2006\n\nfunction [lat,lon,alt] = ecef2lla(x,y,z)\n\n% WGS84 ellipsoid constants:\na = 6378137;\ne = 8.1819190842622e-2;\n\n% calculations:\nb = sqrt(a^2*(1-e^2));\nep = sqrt((a^2-b^2)/b^2);\np = sqrt(x.^2+y.^2);\nth = atan2(a*z,b*p);\nlon = atan2(y,x);\nlat = atan2((z+ep^2.*b.*sin(th).^3),(p-e^2.*a.*cos(th).^3));\nN = a./sqrt(1-e^2.*sin(lat).^2);\nalt = p./cos(lat)-N;\n\n% return lon in range [0,2*pi)\nlon = mod(lon,2*pi);\n\n% correct for numerical instability in altitude near exact poles:\n% (after this correction, error is about 2 millimeters, which is about\n% the same as the numerical precision of the overall function)\n\nk=abs(x)<1 & abs(y)<1;\nalt(k) = abs(z(k))-b;\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/7941-convert-cartesian-ecef-coordinates-to-lat-lon-alt/ecef2lla.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731115849662, "lm_q2_score": 0.8670357477770337, "lm_q1q2_score": 0.834672001167915}} {"text": "function area = hypersphere_01_area ( dim_num )\n\n%*****************************************************************************80\n%\n%% HYPERSPHERE_01_AREA computes the surface area of a unit sphere in ND.\n%\n% Discussion:\n%\n% The unit sphere in ND satisfies:\n%\n% sum ( 1 <= I <= DIM_NUM ) X(I) * X(I) = 1\n%\n% Results for the first few values of N are:\n%\n% DIM_NUM Area\n%\n% 2 2 * PI\n% 3 4 * PI\n% 4 ( 2 / 1) * PI^2\n% 5 ( 8 / 3) * PI^2\n% 6 ( 1 / 1) * PI^3\n% 7 (16 / 15) * PI^3\n% 8 ( 1 / 3) * PI^4\n% 9 (32 / 105) * PI^4\n% 10 ( 1 / 12) * PI^5\n%\n% For the unit sphere, Area(DIM_NUM) = DIM_NUM * Volume(DIM_NUM)\n%\n% Sphere_Unit_Area ( DIM_NUM ) = 2 * PI^(DIM_NUM/2) / Gamma ( DIM_NUM / 2 )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 February 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the dimension of the space.\n%\n% Output, real SPHERE_UNIT_AREA_ND, the area of the sphere.\n%\n if ( mod ( dim_num, 2 ) == 0 )\n m = floor ( dim_num / 2 );\n area = 2.0 * pi^m;\n for i = 1 : m-1\n area = area / i;\n end\n else\n m = floor ( ( dim_num - 1 ) / 2 );\n area = pi^m * 2.0^dim_num;\n for i = m+1 : 2*m\n area = area / i;\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/hypersphere_properties/hypersphere_01_area.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012762876286, "lm_q2_score": 0.8824278649085117, "lm_q1q2_score": 0.8346014008622374}} {"text": "function [maxSum,startIdx,endIdx]=maxSubsequenceSum(a)\n%%MAXSUBSEQUENCESUM Given a vector of numbers that might be positive or\n% find the maximum value that can be obtained by summing\n% a subsequence of the set a.\n%\n%INPUTS: a A 1XN or NX1 vector of real numbers.\n%\n%OUTPUTS: maxSum The maximum value of sums possible by summing consecutive\n% values in a. If a only contains negative values, then this\n% will be zero as the minimum value is obtained by summing\n% nothing in a.\n%startIdx,endIdx The beginning and ending indices of the maximum\n% subsequence of a. If a is all negative, these will both be\n% zero.\n%\n%The solution to the maximum subsequence sum is described in Chapter 2.4\n%of [1]. Multiple approaches to the problem are described in [2]. The\n%algorithm has O(N) complexity as noted in its presentation in [3].\n%\n%The algorithm has been slightly modified to handle arrays that contain all\n%negative or zero elements.\n%\n%REFERENCES:\n%[1] M.A.Weiss, Data Structures and Algorithm Analysis in C++, 2nd ed.\n% Reading, MA: Addison-Wesley, 1999.\n%[2] J. Bentley, \"Algorithm design techniques,\" Communications of the ACM,\n% vol. 27, no. 9, pp. 865-871, Sep. 1984.\n%[3] D. Gries, \"A note on the standard strategy for developing loop\n% invariants and loops,\" Department of Computer Science, Cornell\n% University, Ithaca, NY, Tech. Rep. TR 82-531, Oct. 1982.\n%\n%July 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nnumElA=length(a);\n\nmaxSum=0;\nthisSum=0;\nthisStartIdx=1;\n\nstartIdx=0;\nendIdx=0;\n\nmaxVal=-Inf;\nmaxIdx=0;\n\nfor j=1:numElA\n %Finding the maximum value is needed so that something can be returned if\n %an array of only zero or negative numbers is passed.\n if(a(j)>maxVal)\n maxVal=a(j);\n maxIdx=j;\n end\n \n thisSum=thisSum+a(j);\n \n if(thisSum>maxSum)\n maxSum=thisSum;\n startIdx=thisStartIdx;\n endIdx=j;\n elseif(thisSum<0)\n thisSum=0;\n thisStartIdx=j+1;\n end\nend\n\nif(maxVal<=0)\n %If all of the entries are negative or zero, then return the index of\n %the maximum element.\n maxSum=maxVal;\n startIdx=maxIdx;\n endIdx=maxIdx;\nend\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/Operations_on_Sequences/maxSubsequenceSum.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.918480237888855, "lm_q1q2_score": 0.8345475889433532}} {"text": "function g = sigmoid(z)\n%SIGMOID Compute sigmoid functoon\n% J = SIGMOID(z) computes the sigmoid of z.\n\n% You need to return the following variables correctly \ng = zeros(size(z));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the sigmoid of each value of z (z can be a matrix,\n% vector or scalar)\n\ng = 1./(1 + exp(-z));\n\n% =============================================================\n\nend\n", "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-ex2/ex2/sigmoid.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802440252812, "lm_q2_score": 0.9086178950769319, "lm_q1q2_score": 0.8345475859959978}} {"text": "function [J, grad] = costFunction(theta, X, y)\n%COSTFUNCTION Compute cost and gradient for logistic regression\n% J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the\n% parameter for logistic regression and the gradient of the cost\n% w.r.t. to the parameters.\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly\nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n% Note: grad should have the same dimensions as theta\n%\n\n\nsigmo = sigmoid(X * theta);\n\nJ = 1 / m * (-y' * log(sigmo) - (1 - y') * log(1 - sigmo));\ngrad = 1 / m * ((sigmo - y)' * X)';\n\n\n% =============================================================\n\nend\n", "meta": {"author": "benoitvallon", "repo": "coursera-machine-learning", "sha": "74ec09a5072eb5f3fec942fee45076e4f05b35af", "save_path": "github-repos/MATLAB/benoitvallon-coursera-machine-learning", "path": "github-repos/MATLAB/benoitvallon-coursera-machine-learning/coursera-machine-learning-74ec09a5072eb5f3fec942fee45076e4f05b35af/machine-learning-ex2/ex2/costFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474246069457, "lm_q2_score": 0.874077230244524, "lm_q1q2_score": 0.8344355767605072}} {"text": "function cdf = pareto_cdf ( x, a, b )\n\n%*****************************************************************************80\n%\n%% PARETO_CDF evaluates the Pareto CDF.\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% Parameters:\n%\n% Input, real X, the argument of the CDF.\n%\n% Input, real A, B, the parameters of the PDF.\n% 0.0 < A,\n% 0.0 < B.\n%\n% Output, real CDF, the value of the CDF.\n%\n if ( x < a )\n cdf = 0.0;\n else\n cdf = 1.0 - ( a / x )^b;\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/prob/pareto_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107984180246, "lm_q2_score": 0.8902942297605357, "lm_q1q2_score": 0.8343933659008319}} {"text": "function [p,S] = polyfit(x,y,n)\n %POLYFIT Polynomial curve fitting.\n %\tPOLYFIT(x,y,n) finds the coefficients of a polynomial p(x) of\n %\tdegree n that fits the data, p(x(i)) ~= y(i), in a least-squares sense.\n %\n %\t[p,S] = POLYFIT(x,y,n) returns the polynomial coefficients p and a\n %\tmatrix S for use with POLYVAL to produce error estimates on predictions.\n %\tIf the errors in the data, y, are independent normal with constant\n %\tvariance, POLYVAL will produce error bounds which contain at least 50%\n %\tof the predictions.\n %\n %\tSee also POLY, POLYVAL, ROOTS.\n\n %\tJ.N. Little 4-21-85, 8-23-86; CBM, 12-27-91 BAJ, 5-7-93.\n %\tCopyright (c) 1984-94 by The MathWorks, Inc.\n\n % The regression problem is formulated in matrix format as:\n %\n % y = V*p or\n %\n % 3 2\n % y = [x x x 1] [p3\n % p2\n % p1\n % p0]\n %\n % where the vector p contains the coefficients to be found. For a\n % 7th order polynomial, matrix V would be:\n %\n % V = [x.^7 x.^6 x.^5 x.^4 x.^3 x.^2 x ones(size(x))];\n\n %report_this_filefun(mfilename('fullpath'));\n\n if any(size(x) ~= size(y))\n error('X and Y vectors must be the same size.')\n end\n\n x = x(:);\n y = y(:);\n\n % Construct Vandermonde matrix.\n V(:,n+1) = ones(length(x),1);\n for j = n:-1:1\n V(:,j) = x.*V(:,j+1);\n end\n\n % Solve least squares problem.\n [Q,R] = eval('qr(V,0)','qr(V)');\n\n % The current PC version does not have the two-argument form of qr\n [rows, cols] = size(R);\n if rows ~= cols\n R = R(1:cols,:);\n Q = Q(:,1:cols);\n end\n\n p = R\\(Q'*y); % Same as p = V\\y;\n r = y - V*p;\n p = p'; % Polynomial coefficients are row vectors by convention.\n\n % S is a structure containing three elements: the Cholesky factor of the\n % Vandermonde matrix, the degrees of freedom and the norm of the residuals.\n\n df = length(y) - (n+1);\n S = [R; [df zeros(1,n)]; [norm(r) zeros(1,n)]];\n", "meta": {"author": "CelsoReyes", "repo": "zmap7", "sha": "3895fcb3ca3073608abe22ca71960eb082fd0d9a", "save_path": "github-repos/MATLAB/CelsoReyes-zmap7", "path": "github-repos/MATLAB/CelsoReyes-zmap7/zmap7-3895fcb3ca3073608abe22ca71960eb082fd0d9a/zmap_deprecated/orphaned/src/QUARENTINE_polyfit.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.8902942319436397, "lm_q1q2_score": 0.8343933648241197}} {"text": "function a = r8sd_dif2 ( m, n, ndiag, offset )\n\n%*****************************************************************************80\n%\n%% R8SD_DIF2 returns the DIF2 matrix in R8SD format.\n%\n% Example:\n%\n% N = 5\n%\n% 2 -1 . . .\n% -1 2 -1 . .\n% . -1 2 -1 .\n% . . -1 2 -1\n% . . . -1 2\n%\n% Properties:\n%\n% A is banded, with bandwidth 3.\n%\n% A is tridiagonal.\n%\n% Because A is tridiagonal, it has property A (bipartite).\n%\n% A is a special case of the TRIS or tridiagonal scalar matrix.\n%\n% A is integral, therefore det ( A ) is integral, and \n% det ( A ) * inverse ( A ) is integral.\n%\n% A is Toeplitz: constant along diagonals.\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% A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\n%\n% A is positive definite.\n%\n% A is an M matrix.\n%\n% A is weakly diagonally dominant, but not strictly diagonally dominant.\n%\n% A has an LU factorization A = L * U, without pivoting.\n%\n% The matrix L is lower bidiagonal with subdiagonal elements:\n%\n% L(I+1,I) = -I/(I+1)\n%\n% The matrix U is upper bidiagonal, with diagonal elements\n%\n% U(I,I) = (I+1)/I\n%\n% and superdiagonal elements which are all -1.\n%\n% A has a Cholesky factorization A = L * L', with L lower bidiagonal.\n%\n% L(I,I) = sqrt ( (I+1) / I )\n% L(I,I-1) = -sqrt ( (I-1) / I )\n%\n% The eigenvalues are\n%\n% LAMBDA(I) = 2 + 2 * COS(I*PI/(N+1))\n% = 4 SIN^2(I*PI/(2*N+2))\n%\n% The corresponding eigenvector X(I) has entries\n%\n% X(I)(J) = sqrt(2/(N+1)) * sin ( I*J*PI/(N+1) ).\n%\n% Simple linear systems:\n%\n% x = (1,1,1,...,1,1), A*x=(1,0,0,...,0,1)\n%\n% x = (1,2,3,...,n-1,n), A*x=(0,0,0,...,0,n+1)\n%\n% det ( A ) = N + 1.\n%\n% The value of the determinant can be seen by induction,\n% and expanding the determinant across the first row:\n%\n% det ( A(N) ) = 2 * det ( A(N-1) ) - (-1) * (-1) * det ( A(N-2) )\n% = 2 * N - (N-1)\n% = N + 1\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 July 2000\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Robert Gregory, David Karney,\n% A Collection of Matrices for Testing Computational Algorithms,\n% Wiley, 1969,\n% ISBN: 0882756494,\n% LC: QA263.68\n%\n% Morris Newman, John Todd,\n% Example A8,\n% The evaluation of matrix inversion programs,\n% Journal of the Society for Industrial and Applied Mathematics,\n% Volume 6, Number 4, pages 466-476, 1958.\n%\n% John Todd,\n% Basic Numerical Mathematics,\n% Volume 2: Numerical Algebra,\n% Birkhauser, 1980,\n% ISBN: 0817608117,\n% LC: QA297.T58.\n%\n% Joan Westlake,\n% A Handbook of Numerical Matrix Inversion and Solution of \n% Linear Equations,\n% John Wiley, 1968,\n% ISBN13: 978-0471936756,\n% LC: QA263.W47.\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns.\n%\n% Input, integer NDIAG, the number of diagonals that are stored.\n% NDIAG must be at least 2.\n%\n% Input, integer OFFSET(NDIAG), the offsets for the diagonal\n% storage. It is simply assumed that OFFSET(1) = 0 and OFFSET(2) = 1.\n%\n% Output, real A(N,NDIAG), the matrix.\n%\n a = zeros(n,ndiag);\n\n a(1:n, 1) = 2.0;\n a(1:n-1,2) = -1.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/cg/r8sd_dif2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603709, "lm_q2_score": 0.8947894632969137, "lm_q1q2_score": 0.8343493957846025}} {"text": "function [f] = binomial(n,d)\n%BINOMIAL calculate the binomial coefficient\n% n and d may be complex and any equal size\n%\n% n!\n% f = -------- \n% d!(n-d)!\n%\n%usage: b = binomial(n,d)\n%\n%tested on version 5.3.1\n%\n%see also: Gamma, Prod\n%see also: mhelp binomial\n%\n%not correct for negative integer arguments!\n\n%Paul Godfrey\n%pgodfrey@conexant.com\n%8-12-00\n\nnsize=size(n); n=n(:);\ndsize=size(d); d=d(:);\n\nif min(nsize==dsize)==0\n error('Input argument size mismatch!')\nend\n\nif (0=d & max(size(n))==1 & max(size(d))==1)\n f = prod((d+1):n)/prod(1:(n-d));\nelse\n z=gamma([n d n-d]+1);\n f=z(:,1)./(z(:,2).*z(:,3));\nend\n\nf=reshape(f,nsize);\n\nreturn\n\n%a demo of this routine is\ndx=1/16;\ndy=dx;\nx=-4:dx:4;\ny=-4:dy:4;\n[X,Y]=meshgrid(x,y);\nf=binomial(X,Y);\np=find(abs(f)>4);\n%f(p)=sign(real(f(p)))*4;\nf(p)=NaN;\nmesh(x,y,real(f))\nview([23 54]);\nrotate3d\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/978-special-functions-math-library/binomial.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109742068042, "lm_q2_score": 0.8774767842777551, "lm_q1q2_score": 0.833963565389275}} {"text": "function [C,dt] = VBA_getNtuples(k,n,verbose)\n% gets all n-draws (with replacement) from a k-urn.\n% [C] = VBA_getNtuples(k,n,verbose)\n% This function construct all the n-tuples that can be obtained (with\n% replacement) from an urn containing k marbles.\n% A couple of examples is worth a long description:\n%\n% VBA_getNtuples(2,3)\n%\n% ans =\n%\n% 1 1 1 1 2 2 2 2\n% 1 1 2 2 1 1 2 2\n% 1 2 1 2 1 2 1 2\n%\n% VBA_getNtuples(3,2)\n%\n% ans =\n%\n% 1 1 1 2 2 2 3 3 3\n% 1 2 3 1 2 3 1 2 3\n%\n% IN:\n% - k: the cardinality of the set, whose permutations are replicated over\n% n dimensions\n% - n: the dimension of the tuple, whose entries are elements of the set\n% {1,2,...,k}.\n% OUT:\n% - C: a nXn^p matrix, whose columns are the n-draws\n% Thanks to Antonin \"magic\" Ancelle!\n\ntry; verbose;catch;verbose=0;end\ntic;\nnp = k^n;\nif verbose\n fprintf(1,['Getting the ',num2str(np),' ',num2str(n),'-draws from ',num2str(k),'-urn...'])\nend\nC = zeros(n,np); % pre-allocate k-permutations\nfor ind = 1:n\n for j = 1:k^(ind-1)\n nbch = np/(k^(ind-1));\n C(ind,(1+(j-1)*nbch):j*nbch) = ceil((1:nbch)/(nbch/k));\n end\nend\ndt = toc;\nif verbose\n fprintf(1,[' OK. (took ',num2str(dt),' seconds)'] )\n fprintf(1,'\\n')\nend\n\nreturn\n", "meta": {"author": "MBB-team", "repo": "VBA-toolbox", "sha": "01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414", "save_path": "github-repos/MATLAB/MBB-team-VBA-toolbox", "path": "github-repos/MATLAB/MBB-team-VBA-toolbox/VBA-toolbox-01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414/utils/VBA_getNtuples.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.8962513752119936, "lm_q1q2_score": 0.8339244945206302}} {"text": "function area = polygon_area_2d ( n, v )\n\n%*****************************************************************************80\n%\n%% POLYGON_AREA_2D computes the area of a polygon in 2D.\n%\n% Discussion:\n%\n% AREA = 1/2 * abs ( sum ( 1 <= I <= N ) X(I) * ( Y(I+1) - Y(I-1) ) )\n% where Y(0) should be replaced by Y(N), and Y(N+1) by Y(1).\n%\n% If the vertices are given in counterclockwise order, the area\n% will be positive. If the vertices are given in clockwise order,\n% the area will be negative.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 January 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of vertices of the polygon.\n%\n% Input, real V(2,N), the vertices.\n%\n% Output, real AREA, the area of the polygon.\n%\n area = 0.0;\n\n for i = 1 : n\n\n im1 = i4_wrap ( i-1, 1, n );\n ip1 = i4_wrap ( i+1, 1, n );\n\n area = area + v(1,i) * ( v(2,ip1) - v(2,im1) );\n\n end\n\n area = 0.5 * area;\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_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259923, "lm_q2_score": 0.8872045817875224, "lm_q1q2_score": 0.8338954304488787}} {"text": "function [ xmin, ymin ] = minquad ( x1, y1, x2, y2, x3, y3 )\n\n%*****************************************************************************80\n%\n%% MINQUAD finds a local minimum of F(X) = A * X * X + B * X + C.\n%\n% Discussion:\n%\n% MINQUAD is primarily intended as a utility routine.\n% The square of the distance function between a point\n% and a line segment has the form of F(X). Hence, we can seek\n% the line on the second segment which minimizes the square of\n% the distance to the other line segment.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 08 March 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X1, Y1, X2, Y2, X3, Y3, three sets of data\n% of the form ( X, F(X) ). The three X values must be distinct.\n%\n% Output, real XMIN, YMIN. XMIN is a point within the interval\n% spanned by X1, X2 and X3, at which F takes its local minimum value YMIN.\n%\n\n%\n% Refuse to deal with coincident data.\n%\n if ( x1 == x2 | x2 == x3 | x3 == x1 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'MINQUAD - Fatal error!\\n' );\n fprintf ( 1, ' X values are equal.\\n' );\n error ( 'MINQUAD - Fatal error!' );\n end\n%\n% Find the interval endpoints.\n%\n xleft = min ( x1, min ( x2, x3 ) );\n xrite = max ( x1, max ( x2, x3 ) );\n%\n% Find the minimizer and its function value, over the three input points.\n%\n if ( y1 <= y2 & y1 <= y3 )\n xmin = x1;\n ymin = y1;\n elseif ( y2 <= y1 & y2 <= y3 )\n xmin = x2;\n ymin = y2;\n else\n xmin = x3;\n ymin = y3;\n end\n%\n% Find the minimizer and its function value over the real line.\n%\n [ x, y, ierror ] = parabola_ex ( x1, y1, x2, y2, x3, y3 );\n%\n% If F is linear, then take the already computed min.\n%\n if ( ierror == 2 )\n%\n% If F has a maximum, then take the already computed min.\n%\n elseif ( ymin < y )\n%\n% If the minimizer is to the left, take the already computed min.\n%\n elseif ( x < xleft )\n%\n% If the minimizer is to the right, take the already computed min.\n%\n elseif ( xrite < x )\n\n else\n\n xmin = x;\n ymin = y;\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/geometry/minquad.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660989095221, "lm_q2_score": 0.8740772351648677, "lm_q1q2_score": 0.8338400501758498}} {"text": "%% Homework 11\n% We wish to solve the following PDE using the approximate factorization\n% method:\n%\n% $\\frac{\\partial \\phi }{\\partial t}+U(x,y)\\frac{\\partial \\phi }{\\partial\n% x}+V(x,y)\\frac{\\partial \\phi }{\\partial y}=\\alpha \\left (\n% \\frac{\\partial^2 \\alpha }{\\partial x^2}-\\frac{\\partial^2 \\phi }{\\partial\n% y^2} \\right)$\n% \n% This is 2D convection-diffusion equation\n\nclose all\nclear all\n\n%% Grid\n\nly = [-1,1]; lx =[0,10];\ndy = 0.2; dx = 0.5;\ny = ly(1):dy:ly(2); x = lx(1):dx:lx(2); % Physical grid\nq = length(y); p = length(x); \nphi = zeros(q,p); % Numerical grid\n\nt_end = 1; dt = 0.1; n = (t_end-0)/dt;\n\n%% Boundary Conditions\n\nphi(:,1) = 1;\nphi(1,:) = 1;\n\n\n%% Constants & coheficients\n% assume: $\\alpha = const$.\n\nalpha = 1;\n\n% 1. assume: $u(x,y)=x*y% and $v(x,y)=x/(y+0.1)$,\n% 2. assume: $u(x,y)=1$ and $v(x,y)=1$.\n\nu = zeros(q,p); \nfor j = 1:q\n for i = 1:p\n u(j,i) = x(i)*y(j);\n % u(j,i) = 1 \n end\nend\n\nv = zeros(q,p);\nfor j = 1:q\n for i = 1:p\n v(j,i) = (1/(y(j)+0.1))*x(i);\n % v(j,i) = 1 \n end\nend\n\n%% Formulate Base matrices\n% Dy\n% Constants\na = dt/2*(alpha/dy^2 - v/(2*dy));\nb = (1 - dt/dy^2);\nc = dt/2*(alpha/dy^2 + v/(2*dy));\n\nQy = zeros(q-2,q-2,p);\nfor i = 2:p-1\n e = zeros(q-2,3);\n e(:,3) = a(1:q-2,i);\n e(:,2) = b*ones(q-2,1); % But the last No. in de Diag must be modif.:\n e(q-2,2) = a(q-1,i)-b(q-1,i);\n e(:,1) = c(3:q,i);\n Qy(:,:,i) = spdiags(e,-1:1,q-2,q-2);\nend\n\n\n% Dx\n% Constants\n% f = dt/2*(alpha/dx^2 - u/(2*dx));\n% g = (1 - dt/dx^2);\n% h = dt/2*(alpha/dx^2 - u/(2*dx));\n% \n% e1 = a(1,3:p-1);\n% e2 = b*ones(1,p-2);\n% e3 = c(1,2:p-2);\n% Qx = spdiags([e3 e2 e1],[-1 0 1],p-2,p-2);\n\n\n\n%% Compute $f$ for time n step\n\n\n\n%% Boundary Conditions\n\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/NumericalMethods/ADI.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692236, "lm_q2_score": 0.8991213820004278, "lm_q1q2_score": 0.833812173413312}} {"text": "function [ res, jac ] = opt05_rj ( x, flag, a ) \n\n%*****************************************************************************80\n%\n%% OPT05_RJ evaluates RES and JAC for test case #5.\n%\n% Discussion:\n%\n% This example is known as the Rosenbrock \"banana\" function.\n%\n% This example is discussed in Dennis and Schnabel, page 157.\n% (There is a misprint in Dennis and Schabel. When they print the\n% rescaled function, they include an incorrect sign on the second term.)\n%\n% This example tests the scaling matrices.\n%\n% Suggested starting points are\n%\n% X(init) = ( -1.2/A, A)\n% or\n% X(init) = ( 6.39/A, -0.221*A )\n%\n% The optimizing value is\n%\n% X* = (1/A, A)\n%\n% for which\n%\n% RES(X*) = (0,0).\n%\n% A typical value of A is 1. For values of A that are greater or lesser\n% than 1, the optimization can take significantly longer.\n%\n% Modified:\n%\n% 02 January 2008\n%\n% Author:\n%\n% Jeff Borggaard,\n% Gene Cliff,\n% Virginia Tech.\n%\n% Reference:\n%\n% John Dennis, Robert Schnabel,\n% Numerical Methods for Unconstrained Optimization \n% and Nonlinear Equations,\n% SIAM, 1996,\n% ISBN13: 978-0-898713-64-0,\n% LC: QA402.5.D44.\n%\n% Parameters:\n%\n% Input, real X(2), the evaluation point.\n%\n% Input, string FLAG, indicates what must be computed.\n% 'f' means only the value of RES is needed,\n% 'g' means only the value of JAC is needed,\n% 'all' means RES and JAC are needed.\n% It is acceptable to behave as though FLAG was 'all'\n% on every call.\n%\n% Input, real A, the scale factor. A typical value is 1.\n% A should not be 0.\n%\n% Output, real RES(2,1), the residual column vector.\n%\n% Output, real J(2,2), the Jacobian matrix.\n%\n n = length ( x );\n\n if ( n ~= 2 )\n fprintf ( '\\n' );\n fprintf ( 'OPT05_RJ - Fatal error!\\n' );\n fprintf ( ' The input vector X should have length 2.\\n'), \n fprintf ( ' Instead, it has length = %d.\\n', n );\n keyboard\n end\n\n if ( a == 0 )\n fprintf ( '\\n' );\n fprintf ( 'OPT05_RJ - Fatal error!\\n' );\n fprintf ( ' The scale factor A should be nonzero.\\n'), \n keyboard\n end\n\n res(1,1) = 10 * ( ( a * x(1) )^2 - x(2) / a );\n res(2,1) = 1 - a * x(1);\n\n jac(1,1) = 20 * a * a * x(1);\n jac(1,2) = - 10 / a;\n\n jac(2,1) = - a;\n jac(2,2) = 0.0;\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/entrust/opt05_rj.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.9230391563648734, "lm_q1q2_score": 0.8337759225052256}} {"text": "function r = assortativity(CIJ,flag)\n%ASSORTATIVITY Assortativity coefficient\n%\n% r = assortativity(CIJ,flag);\n%\n% The assortativity coefficient is a correlation coefficient between the \n% degrees of all nodes on two opposite ends of a link. A positive \n% assortativity coefficient indicates that nodes tend to link to other \n% nodes with the same or similar degree.\n%\n% Inputs: CIJ, binary directed/undirected connection matrix\n% flag, 1 = directed graph; 0 = non-directed graph\n%\n% Outputs: r, assortativity\n%\n% Notes: The function accepts weighted networks, but all connection\n% weights are ignored. The main diagonal should be empty.\n%\n% Reference: Newman (2002) Phys Rev Lett 89:208701.\n%\n%\n% Olaf Sporns, Indiana University, 2007/2008\n% Vassilis Tsiaras, University of Crete, 2009\n\nif (flag==0)\n [deg] = degrees_und(CIJ);\n [i,j] = find(triu(CIJ,1)>0);\n K = length(i);\n for k=1:K\n degi(k) = deg(i(k));\n degj(k) = deg(j(k));\n end;\nend;\nif (flag==1)\n [id,od,deg] = degrees_dir(CIJ);\n [i,j] = find(CIJ>0);\n K = length(i);\n for k=1:K\n degi(k) = deg(i(k));\n degj(k) = deg(j(k));\n end;\nend;\n\n% compute assortativity\nr = (sum(degi.*degj)/K - (sum(0.5*(degi+degj))/K)^2)/(sum(0.5*(degi.^2+degj.^2))/K - (sum(0.5*(degi+degj))/K)^2);\n\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/assortativity.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850128595114, "lm_q2_score": 0.8902942239389253, "lm_q1q2_score": 0.8335691389094054}} {"text": "% Sparse covariance estimation for Gaussian variables\n% Joëlle Skaf - 04/24/08 \n% (a figure is generated)\n% \n% Suppose y \\in\\reals^n is a Gaussian random variable with zero mean and \n% covariance matrix R = \\Expect(yy^T), with sparse inverse S = R^{-1} \n% (S_ij = 0 means that y_i and y_j are conditionally independent).\n% We want to estimate the covariance matrix R based on N independent \n% samples y1,...,yN drawn from the distribution, and using prior knowledge \n% that S is sparse\n% A good heuristic for estimating R is to solve the problem \n% maximize logdet(S) - tr(SY) - lambda*sum(sum(abs(S)))\n% subject to S >= 0\n% where Y is the sample covariance of y1,...,yN, and lambda is a sparsity\n% parameter to be chosen or tuned. \n% A figure showing the sparsity (number of nonzeros) of S versus lambda \n% is generated.\n\n% Input data \nrand('state',0); %#ok\nrandn('state',0); %#ok\nn = 10; \nN = 100; \nStrue = sprandsym(n,0.5,0.01,1);\nStrue(abs(Strue(:))<=1e-4) = 0;\nnnz_true = nnz(Strue);\nR = inv(full(Strue));\ny_sample = sqrtm(R)*randn(n,N); \nY = cov(y_sample'); \nNlambda = 20;\nlambda = logspace(-2, 3, Nlambda);\nnnz_i = zeros(1,Nlambda);\n\nfor i=1:Nlambda\n disp(['i = ' num2str(i) ', lambda(i) = ' num2str(lambda(i))]); \n % Maximum likelihood estimate of R^{-1}\n cvx_begin sdp quiet\n variable S(n,n) symmetric\n maximize log_det(S) - trace(S*Y) - lambda(i)*sum(sum(abs(S)))\n S >= 0; %#ok\n cvx_end\n nnz_i(i) = sum(abs(S(:))>1e-4);\nend\n\nfigure; \nsemilogx(lambda, nnz_i); \nhold on; \nsemilogx(lambda, nnz_true*ones(1,Nlambda),'r');\nxlabel('\\lambda');\nlegend('nonzeros in S', 'nonzeros in R^{-1}'); \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/log_exp/sparse_covariance_est_tradeoff.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545377452443, "lm_q2_score": 0.8791467785920306, "lm_q1q2_score": 0.8335670074661474}} {"text": "function [x,y] = intline(x1, x2, y1, y2)\n%INTLINE Integer-coordinate line drawing algorithm.\n% [X, Y] = INTLINE(X1, X2, Y1, Y2) computes an\n% approximation to the line segment joining (X1, Y1) and\n% (X2, Y2) with integer coordinates. X1, X2, Y1, and Y2\n% should be integers. INTLINE is reversible; that is,\n% INTLINE(X1, X2, Y1, Y2) produces the same results as\n% FLIPUD(INTLINE(X2, X1, Y2, Y1)).\n%\n% Function adapted from the 'strel' function of matlab.\n%\n\ndx = abs(x2 - x1);\ndy = abs(y2 - y1);\n\n% Check for degenerate case\nif dx == 0 && dy == 0\n x = x1;\n y = y1;\n return;\nend\n\nflip = 0;\nif dx >= dy\n if x1 > x2\n % swap coordinates to draw from left to right.\n t = x1; x1 = x2; x2 = t;\n t = y1; y1 = y2; y2 = t;\n flip = 1;\n end\n \n % compute line slope, and y from x\n m = (y2 - y1) / (x2 - x1);\n x = (x1:x2).';\n y = round(y1 + m * (x - x1));\n \nelse\n if y1 > y2\n % swap coordinates to draw from bottom to top.\n t = x1; x1 = x2; x2 = t;\n t = y1; y1 = y2; y2 = t;\n flip = 1;\n end\n \n % compute line slope, and x from y\n m = (x2 - x1) / (y2 - y1);\n y = (y1:y2).';\n x = round(x1 + m * (y - y1));\nend\n\nif flip\n x = flipud(x);\n y = flipud(y);\nend\n\n", "meta": {"author": "mattools", "repo": "matImage", "sha": "94d892c7beac0db32daadf2646ce37f58e894caf", "save_path": "github-repos/MATLAB/mattools-matImage", "path": "github-repos/MATLAB/mattools-matImage/matImage-94d892c7beac0db32daadf2646ce37f58e894caf/matImage/imFilters/intline.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.9019206824612296, "lm_q1q2_score": 0.8335026247348847}} {"text": "function s = collatz ( seed )\n\n%*****************************************************************************80\n%\n%% COLLATZ computes the Collatz sequence for a given starting point.\n%\n% Discussion:\n%\n% The Collatz sequence is defined recursively as follows:\n%\n% Let T be the current entry of the sequence, and U the next:\n%\n% If T = 1, the sequence terminates (or U = 1, your choice);\n% Else if T is even, U = T / 2;\n% Else (if T is odd, and greater than 1) U = 3 * T + 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 27 February 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer SEED, the starting point for the sequence.\n% SEED must be positive.\n%\n% Output, integer S[*], the Collatz sequence, starting with SEED.\n% Once the sequence reaches the value 1, no more entries are computed.\n%\n if ( seed <= 0 )\n s = [];\n return\n end\n\n n = 1;\n t = seed;\n s(n) = t;\n\n while ( t ~= 1 )\n\n if ( 2 * round ( t / 2 ) == t )\n t = t / 2;\n else\n t = 3 * t + 1;\n end\n\n n = n + 1;\n s(n) = t;\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/collatz/collatz.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.9019206870747658, "lm_q1q2_score": 0.8335026195767413}} {"text": "function Z = projectData(X, U, K)\n%PROJECTDATA Computes the reduced data representation when projecting only \n%on to the top k eigenvectors\n% Z = projectData(X, U, K) computes the projection of \n% the normalized inputs X into the reduced dimensional space spanned by\n% the first K columns of U. It returns the projected examples in Z.\n%\n\n% You need to return the following variables correctly.\nZ = zeros(size(X, 1), K);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the projection of the data using only the top K \n% eigenvectors in U (first K columns). \n% For the i-th example X(i,:), the projection on to the k-th \n% eigenvector is given as follows:\n% x = X(i, :)';\n% projection_k = x' * U(:, k);\n%\n\nU_reduced = U(:, 1:K);\nZ = X * U_reduced;\n\n% =============================================================\n\nend\n", "meta": {"author": "rieder91", "repo": "MachineLearning", "sha": "f6708f216326cb5c9e9e5c3afc912060bfa10486", "save_path": "github-repos/MATLAB/rieder91-MachineLearning", "path": "github-repos/MATLAB/rieder91-MachineLearning/MachineLearning-f6708f216326cb5c9e9e5c3afc912060bfa10486/Exercise 7/ex7/projectData.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680097, "lm_q2_score": 0.8947894618940992, "lm_q1q2_score": 0.8334628353844341}} {"text": "function value = r8_exponential_sample ( lambda )\n\n%*****************************************************************************80\n%\n%% R8_EXPONENTIAL_SAMPLE samples the exponential PDF.\n%\n% Discussion:\n%\n% Note that the parameter LAMBDA is a multiplier. In some formulations,\n% it is used as a divisor instead.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 June 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real LAMBDA, the parameter of the PDF.\n%\n% Output, real VALUE, a sample of the PDF.\n%\n r = r8_uniform_01_sample ( );\n\n value = - log ( r ) * lambda;\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/pdflib/r8_exponential_sample.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.897695295528596, "lm_q1q2_score": 0.8334282125859718}} {"text": "function [xi,w]=thirdOrder2DCubPoints()\n%%THIRDORDER2DCUBPOINTS Generate third-order cubature points\n% for integration over a 2-dimensional cube with bounds of \n% (-1,-1), (-1,1), (1,1), and (1,-1).\n%\n%INPUTS: None\n%\n%OUTPUTS: xi This is a 2XnumCubPoints set of points for the standard\n% square.\n% w A 1XnumCubPoints set of cubature weights. This sums to the\n% volume of the standard square (4).\n%\n%This function implements the points given in [1] (4 points).\n%\n%EXAMPLE:\n%We compare a 2nd-order moment computed using these cubature points\n%to one computed using monomialIntCube (a 3rd order moment would have just\n%been 0). The results are the same within typical finite precision limits.\n% [xi,w]=thirdOrder2DCubPoints();\n% alpha=[2;0];\n% theMoment=findMomentFromSamp(alpha,xi,w);\n% intVal=monomialIntCube(alpha);\n% RelErr=(theMoment-intVal)/intVal\n%\n%REFERENCES:\n%[1] F. D. Witherden and P. E. Vincent, \"On the identification of symmetric\n% quadrature rules for finite element methods,\" Computer and Mathematics\n% with Applications, vol. 69, no. 10, pp. 1232-1241, May 2015.\n%\n%October 2022 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nM=[0.57735026918962576450914878050195745565, 0.57735026918962576450914878050195745565, 1;\n 0.57735026918962576450914878050195745565, -0.57735026918962576450914878050195745565, 1;\n -0.57735026918962576450914878050195745565, 0.57735026918962576450914878050195745565, 1;\n -0.57735026918962576450914878050195745565, -0.57735026918962576450914878050195745565, 1];\nw=M(:,3);\nxi=M(:,1:2)';\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/Numerical_Integration/Cubature_Points/Cube_Space/Square/thirdOrder2DCubPoints.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.8976952873175983, "lm_q1q2_score": 0.8334282085191873}} {"text": "%ANGDIFF Difference of two angles\n%\n% ANGDIFF(TH1, TH2) is the difference between angles TH1 and TH2, ie. TH1-TH2\n% on the circle. The result is in the interval [-pi pi). Either or both\n% arguments can be a vector:\n% - If TH1 is a vector, and TH2 a scalar then return a vector where TH2 is modulo \n% subtracted from the corresponding elements of TH1.\n% - If TH1 is a scalar, and TH2 a vector then return a vector where the\n% corresponding elements of TH2 are modulo subtracted from TH1.\n% - If TH1 and TH2 are vectors then return a vector whose elements are the modulo \n% difference of the corresponding elements of TH1 and TH2, which must be the \n% same length.\n%\n% ANGDIFF(TH) as above but TH=[TH1 TH2].\n%\n% ANGDIFF(TH) is the equivalent angle to the scalar TH in the interval [-pi pi).\n%\n% Notes::\n% - The MathWorks Robotics Systems Toolbox defines a function with the same name\n% which computes TH2-TH1 rather than TH1-TH2.\n% - If TH1 and TH2 are both vectors they should have the same\n% orientation, which the output will assume.\n%\n\n% Copyright (C) 1993-2019 Peter I. Corke\n%\n% This file is part of The Spatial Math Toolbox for MATLAB (SMTB).\n% \n% Permission is hereby granted, free of charge, to any person obtaining a copy\n% of this software and associated documentation files (the \"Software\"), to deal\n% in the Software without restriction, including without limitation the rights\n% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\n% of the Software, and to permit persons to whom the Software is furnished to do\n% so, subject to the following conditions:\n%\n% The above copyright notice and this permission notice shall be included in all\n% copies or substantial portions of the Software.\n%\n% THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR \n% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n% FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n% COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n% IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n%\n% https://github.com/petercorke/spatial-math\n\nfunction d = angdiff(th1, th2)\n \n switch nargin\n case 1\n if length(th1) == 2\n d = th1(1) - th1(2);\n else\n d = th1;\n end\n case 2\n if length(th1) > 1 && length(th2) > 1\n % if both arguments are vectors, they must be the same\n assert(all(size(th1) == size(th2)), 'SMTB:angdiff:badarg', 'vectors must be same shape');\n end\n % th1 or th2 could be scalar\n d = th1 - th2;\n end\n \n % wrap the result into the interval [-pi pi)\n d = mod(d+pi, 2*pi) - pi;\nend\n\n% Simplistic version of the code, easy to see what it does, but slow...\n%\n% for very negative angles keep adding 2pi\n% while true\n% k = find(d < -pi);\n% if isempty(k)\n% break;\n% end\n% d(k) = d(k) + 2*pi;\n% end\n% \n% % for very positive angles keep subtracting 2pi\n% while true\n% k = find(d > pi);\n% if isempty(k)\n% break;\n% end\n% d(k) = d(k) - 2*pi;\n% end\n", "meta": {"author": "petercorke", "repo": "spatialmath-matlab", "sha": "6eeff4a79f14286705560b84f1fe72e0b7e0e7f7", "save_path": "github-repos/MATLAB/petercorke-spatialmath-matlab", "path": "github-repos/MATLAB/petercorke-spatialmath-matlab/spatialmath-matlab-6eeff4a79f14286705560b84f1fe72e0b7e0e7f7/angdiff.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.907312215721497, "lm_q1q2_score": 0.8333483392291943}} {"text": "function [new_mu, new_Sigma, new_Sigma2] = collapse_mog(mu, Sigma, coefs)\n% COLLAPSE_MOG Collapse a mixture of Gaussians to a single Gaussian by moment matching\n% [new_mu, new_Sigma] = collapse_mog(mu, Sigma, coefs)\n%\n% coefs(i) - weight of i'th mixture component\n% mu(:,i), Sigma(:,:,i) - params of i'th mixture component\n\n% S = sum_c w_c (S_c + m_c m_c' + m m' - 2 m_c m') \n% = sum_c w_c (S_c + m_c m_c') + m m' - 2 (sum_c m_c) m'\n% = sum_c w_c (S_c + m_c m_c') - m m'\n\nnew_mu = sum(mu * diag(coefs), 2); % weighted sum of columns\n\nn = length(new_mu);\nnew_Sigma = zeros(n,n);\nnew_Sigma2 = zeros(n,n);\nfor j=1:length(coefs)\n m = mu(:,j) - new_mu;\n new_Sigma = new_Sigma + coefs(j) * (Sigma(:,:,j) + m*m');\n new_Sigma2 = new_Sigma2 + coefs(j) * (Sigma(:,:,j) + mu(:,j)*mu(:,j)');\nend\n%assert(approxeq(new_Sigma, new_Sigma2 - new_mu*new_mu'))\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/dmlt/external/murphy/KPMtools/collapse_mog.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750400464604, "lm_q2_score": 0.87407724336544, "lm_q1q2_score": 0.8332360191728895}} {"text": "function rad = deg2rad(deg)\n%DEG2RAD Convert angle from degrees to radians\n%\n% Usage:\n% R = deg2rad(D)\n% convert an angle in degrees to an angle in radians.\n%\n% Example\n% deg2rad(180) % gives pi\n% ans = \n% 3.1416\n% deg2rad(60) % gives pi/3\n% ans =\n% 1.0472\n%\n% See Also\n% angles2d, rad2deg\n% \n% ---------\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 09/12/2004.\n%\n\nrad = deg*pi/180;\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/geom2d/deg2rad.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.9005297967961707, "lm_q1q2_score": 0.833197141536562}} {"text": "function a = schur_block ( n, x, y )\n\n%*****************************************************************************80\n%\n%% SCHUR_BLOCK returns the SCHUR_BLOCK matrix.\n%\n% Formula:\n%\n% if ( i == j )\n% a(i,j) = x( (i+1)/2 )\n% else ( mod ( i, 2 ) == 1 & j == i + 1 )\n% a(i,j) = y( (i+1)/2 )\n% else ( mod ( i, 2 ) == 0 & j == i - 1 )\n% a(i,j) = -y( (i+1)/2 )\n% else\n% a(i,j) = 0.0\n%\n% Example:\n%\n% N = 5, X = ( 1, 2, 3 ), Y = ( 4, 5 )\n%\n% 1 4 0 0 0\n% -4 1 0 0 0\n% 0 0 2 5 0\n% 0 0 -5 2 0\n% 0 0 0 0 3\n%\n% Properties:\n%\n% A is generally not symmetric: A' /= A.\n%\n% A is block diagonal, with the blocks being 2 by 2 or 1 by 1 in size.\n%\n% A is in real Schur form.\n%\n% The eigenvalues of A are X(I) +/- sqrt ( - 1 ) * Y(I)\n%\n% A is tridiagonal.\n%\n% A is banded, with bandwidth 3.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 20 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Francoise Chatelin,\n% Section 4.2.7,\n% Eigenvalues of Matrices,\n% John Wiley, 1993.\n%\n% Francoise Chatelin, Valerie Fraysse,\n% Qualitative computing: Elements of a theory for finite precision\n% computation, Lecture notes,\n% CERFACS, Toulouse, France and THOMSON-CSF, Orsay, France, June 1993.\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Input, real X( (N+1)/2 ), specifies the diagonal elements\n% of A.\n%\n% Input, real Y( N/2 ), specifies the off-diagonal elements \n% of the Schur blocks.\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 )\n a(i,j) = x( floor ( (i+1)/2 ) );\n elseif ( mod ( i, 2 ) == 1 & j == i + 1 )\n a(i,j) = y( floor ( (i+1)/2 ) );\n elseif ( mod ( i, 2 ) == 0 & j == i - 1 )\n a(i,j) = - y( floor ( (i+1)/2 ) );\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/schur_block.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897459384732, "lm_q2_score": 0.8856314828740729, "lm_q1q2_score": 0.8331930177682123}} {"text": "function result = polygon_xy_2d ( n, x, y )\n\n%*****************************************************************************80\n%\n%% POLYGON_XY_2D integrates the function X*Y over a polygon in 2D.\n%\n% Integration region:\n%\n% The polygon bounded by the points (X(1:N), Y(1:N)).\n%\n% Formula:\n%\n% INTEGRAL = (1/24) * SUM ( 1 <= I <= N )\n% ( Y(I) * ( 3 * X(I)**2 + 2 * X(I) * X(I-1) + X(I-1)**2 )\n% + Y(I-1) * ( X(I)**2 + 2 * X(I) * X(I-1) + 3 * X(I-1)**2 ) )\n% * ( 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% 22 May 2004\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 X(N), Y(N), the coordinates of the vertices\n% of the polygon. These vertices should be given in\n% counter-clockwise order.\n%\n% Output, real RESULT, the value of the integral.\n%\n result = 0.0E+00;\n\n if ( n < 3 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'POLYGON_XY_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 error ( 'POLYGON_XY_2D - Fatal error!' );\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 + ( ...\n y(i) * ( 3.0E+00 * x(i)^2 + 2.0E+00 * x(i) * x(im1) + x(im1)^2 ) ...\n + y(im1) * ( x(i)^2 + 2.0E+00 * x(i) * x(im1) + 3.0E+00 * x(im1)^2 ) ...\n ) * ( y(i) - y(im1) );\n\n end\n\n result = result / 24.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/stroud/polygon_xy_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897509188345, "lm_q2_score": 0.8856314692902446, "lm_q1q2_score": 0.8331930093994507}} {"text": "function variance = log_series_variance ( a )\n\n%*****************************************************************************80\n%\n%% LOG_SERIES_VARIANCE returns the variance of the Logarithmic Series PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 20 February 1999\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A, the parameter of the PDF.\n% 0.0 < A < 1.0.\n%\n% Output, real VARIANCE, the variance of the PDF.\n%\n alpha = - 1.0 / log ( 1.0 - a );\n\n variance = a * alpha * ( 1.0 - alpha * a ) / ( 1.0 - a )^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/prob/log_series_variance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248225478307, "lm_q2_score": 0.8872045996818986, "lm_q1q2_score": 0.833107141779914}} {"text": "function [f] = psi(z)\n%Psi Psi (or Digamma) function valid in the entire complex plane.\n%\n% d\n% Psi(z) = --log(Gamma(z))\n% dz\n%\n%usage: [f] = psi(z)\n%\n%tested under versions 6.0 and 5.3.1\n%\n% Z may be complex and of any size.\n%\n% This program uses the analytical derivative of the\n% Log of an excellent Lanczos series approximation\n% for the Gamma function.\n% \n%References: C. Lanczos, SIAM JNA 1, 1964. pp. 86-96\n% Y. Luke, \"The Special ... approximations\", 1969 pp. 29-31\n% Y. Luke, \"Algorithms ... functions\", 1977\n% J. Spouge, SIAM JNA 31, 1994. pp. 931\n% W. Press, \"Numerical Recipes\"\n% S. Chang, \"Computation of special functions\", 1996\n%\n%\n%see also: GAMMA GAMMALN GAMMAINC PSIN\n%see also: mhelp psi\n%see also: mhelp GAMMA\n\n%Paul Godfrey\n%pgodfrey@conexant.com\n%July 13, 2001\n%see gamma for calculation details...\n\nsiz = size(z);\nz=z(:);\nzz=z;\n\nf = 0.*z; % reserve space in advance\n\n%reflection point\np=find(real(z)<0.5);\nif ~isempty(p)\n z(p)=1-z(p);\nend\n\n%Lanczos approximation for the complex plane\n \ng=607/128; % best results when 4<=g<=5\n \nc = [ 0.99999999999999709182;\n 57.156235665862923517;\n -59.597960355475491248;\n 14.136097974741747174;\n -0.49191381609762019978;\n .33994649984811888699e-4;\n .46523628927048575665e-4;\n -.98374475304879564677e-4;\n .15808870322491248884e-3;\n -.21026444172410488319e-3;\n .21743961811521264320e-3;\n -.16431810653676389022e-3;\n .84418223983852743293e-4;\n -.26190838401581408670e-4;\n .36899182659531622704e-5];\n\n\nn=0;\nd=0;\nfor k=size(c,1):-1:2\n dz=1./(z+k-2);\n dd=c(k).*dz;\n d=d+dd;\n n=n-dd.*dz;\nend\nd=d+c(1);\ngg=z+g-0.5;\n%log is accurate to about 13 digits...\n\nf = log(gg) + (n./d - g./gg) ;\n\nif ~isempty(p)\n f(p) = f(p)-pi*cot(pi*zz(p));\nend\n\np=find(round(zz)==zz & real(zz)<=0 & imag(zz)==0);\nif ~isempty(p)\n f(p) = Inf;\nend\n\nf=reshape(f,siz);\n\nreturn\n\n%A demo of this routine is:\nclc\nclear all\nclose all\nx=-4:1/16:4.5;\ny=-4:1/16:4;\n[X,Y]=meshgrid(x,y);\nz=X+i*Y;\nf=psi(z);\np=find(abs(f)>10);\nf(p)=10;\n\nmesh(x,y,abs(f),phase(f));\nview([45 10]);\nrotate3d;\n\nfigure(2);\nezplot psi;\ngrid on;\n\nOne=psi(2)-psi(1)\nEulerGamma=-psi(1)\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/978-special-functions-math-library/psi.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.8962513814471134, "lm_q1q2_score": 0.8330122493932841}} {"text": "function J = computeCostMulti(X, y, theta)\n%COMPUTECOSTMULTI Compute cost for linear regression with multiple variables\n% J = COMPUTECOSTMULTI(X, y, theta) computes the cost of using theta as the\n% parameter for linear regression to fit the data points in X and y\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta\n% You should set J to the cost.\n\n\npredictions = X*theta;\nsqerrors = (predictions - y).^2;\nJ = 1/(2*m)* sum(sqerrors);\n\n\n% =========================================================================\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/computeCostMulti.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.8887587839164801, "lm_q1q2_score": 0.8329543263580418}} {"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n\n\n\n% DTFT of a discrete time signal x[n]\n\n\n%x[n]=0.8^n , 0<=n<=20\nsyms w\nn= 0:20;\nx=0.8.^n;\nX=sum(x.*exp(-j*w*n));\nezplot(abs(X),[-pi pi])\ntitle(' Magnitude of DTFT')\nylim([0 5.4])\n\nfigure\nw1=-pi:.01:pi;\nXX=subs(X,w,w1)\nplot(w1,angle(XX));\nxlim([-pi pi])\ntitle('Phase of DTFT')\n\nfigure\nezplot(abs(X),[-5*pi 5*pi]);\ntitle('Magnitude of DTFT in 5 periods')\nylim([0 5.8])\n\nfigure\nw1=-5*pi:.01:5*pi;\nXX=subs(X,w,w1);\nplot(w1,angle(XX));\nxlim([-5*pi 5*pi])\ntitle(' Phase of DTFT in 5 periods')\n\n\n\n%x[n]=0.8^n u[n]\nfigure\nsyms n w\nx=0.6^n\nX=symsum(x*exp(-j*w*n),n,0,inf)\nw1=-pi:.01:pi;\nX_=subs(X,w,w1);\nplot(w1,abs(X_));\nlegend('|X(\\omega)|')\nxlim([-pi pi])\n\nfigure\nplot(w1,angle(X_));\nxlim([-pi pi])\nlegend('\\angle X(\\omega)')\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/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/7/c71.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731105140616, "lm_q2_score": 0.8652240686758841, "lm_q1q2_score": 0.8329279454838454}} {"text": "function cartPoints=ellips2Cart(points,a,f)\n%%ELLIPS2CART Convert ellipsoidal coordinates to ECEF Cartesian\n% coordinates.\n%\n%INPUTS: points One or more points given in geodetic latitude and\n% longitude, in radians, and height, in meters that are to be\n% converted to Cartesian coordinates. To convert N points,\n% points is a 3XN matrix with each column having the format\n% [latitude;longitude; height].\n% a The semi-major axis of the reference ellipsoid. If this\n% argument is omitted or an empty matrix is passed, the value\n% in Constants.WGS84SemiMajorAxis is used.\n% f The flattening factor of the reference ellipsoid. If this\n% argument is omitted or an empty matrix is passed, the value\n% in Constants.WGS84Flattening is used.\n%\n%OUTPUTS: cartPoints For N points, cartPoints is a 3XN matrix of the\n% converted points with each column having the format\n% [x;y;z].\n%\n%The conversions are mentioned in [1].\n%\n%REFERENCES:\n%[1] D. F. Crouse, \"Simulating aerial targets in 3D accounting for the\n% Earth's curvature,\" Journal of Advances in Information Fusion, vol.\n% 10, no. 1, Jun. 2015.\n%\n%September 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<3||isempty(f))\n f=Constants.WGS84Flattening;\nend\n\nif(nargin<2||isempty(a))\n a=Constants.WGS84SemiMajorAxis;\nend\n\n%The geodetic latitudes\nphi=points(1,:);\n%The longitudes\nlambda=points(2,:);\n\nif(size(points,1)==3)\n %The altitudes\n h=points(3,:);\nelse\n h=0;\nend\n\nsinP=sin(phi);\ncosP=cos(phi);\nsinL=sin(lambda);\ncosL=cos(lambda);\n\n%The square of the first numerical eccentricity\ne2=2*f-f^2;\n%The normal radii of curvature.\nNe=a./sqrt(1-e2*sinP.^2);\n\nx=(Ne+h).*cosP.*cosL;\ny=(Ne+h).*cosP.*sinL;\nz=(Ne*(1-e2)+h).*sinP;\n\ncartPoints=[x;y;z];\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/ellips2Cart.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810525948927, "lm_q2_score": 0.879146761176671, "lm_q1q2_score": 0.8328869839889453}} {"text": "function fibonacci_spiral ( n )\n\n%*****************************************************************************80\n%\n%% FIBONACCI_SPIRAL draws points on a Fibonacci spiral.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 April 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of points to plot.\n% Default is 101.\n%\n if ( nargin < 1 )\n n = 101;\n end\n%\n% PHI is the golden ratio, the limit of the ratio of\n% successive Fibonacci numbers: \n%\n% PHI = limit ( N->oo ) F(N+1)/F(N)\n%\n phi = ( 1.0 + sqrt ( 5.0 ) ) / 2.0;\n%\n% Allocate storage for the data.\n%\n x = zeros ( n, 1 );\n y = zeros ( n, 1 );\n%\n% Set the angle and radius of the first point.\n%\n a = 0.0;\n r = 0.0;\n%\n% Set the increments.\n%\n da = 2.0 * pi * ( phi - 1.0 ) / phi;\n dr = 1.0;\n%\n% Create a spiral in which the radius R and angle A both\n% increase by a constant increment,\n%\n for i = 1 : n\n x(i) = r * cos ( a );\n y(i) = r * sin ( a );\n a = mod ( a + da, 2 * pi );\n r = r + dr;\n end\n%\n% Display the data in a scatter plot.\n%\n scatter ( x, y, 'b.' )\n axis equal\n title ( sprintf ( 'Fibonacci spiral, N = %d', n ) )\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/fibonacci_spiral/fibonacci_spiral.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474142844408, "lm_q2_score": 0.8723473746782093, "lm_q1q2_score": 0.8327841655943727}} {"text": "function l = l1dn ( n, h )\n\n%*****************************************************************************80\n%\n%% L1DN stores the 1D DN Laplacian as a full matrix.\n%\n% Discussion:\n%\n% The N grid points are assumed to be evenly spaced by H.\n%\n% For N = 5, the discrete Laplacian with left Dirichlet and right\n% Neumann condition on [0,6] has the matrix form L:\n%\n% 2 -1 0 0 0\n% -1 2 -1 0 0\n% 0 -1 2 -1 0\n% 0 0 -1 2 -1\n% 0 0 0 -1 1\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 29 October 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of points.\n% N must be at least 3.\n%\n% Input, real H, the spacing between points.\n%\n% Output, real L(N,N), the Laplacian matrix.\n%\n if ( n < 3 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'L1DN - Fatal error!\\n' );\n fprintf ( 1, ' N < 3.\\n' );\n error ( 'L1DN - Fatal error!' );\n end\n\n l = zeros ( n, n );\n\n i = 1;\n l(1,1) = 2.0 / h / h;\n l(1,2) = -1.0 / h / h;\n\n for i = 2 : n - 1\n l(i,i-1) = -1.0 / h / h;\n l(i,i) = 2.0 / h / h;\n l(i,i+1) = -1.0 / h / h;\n end\n\n i = n;\n l(n,n-1) = -1.0 / h / h;\n l(n,n) = 1.0 / h / h;\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/laplacian/l1dn.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392797, "lm_q2_score": 0.8902942173896131, "lm_q1q2_score": 0.832733587362938}} {"text": "function [ xval, yval ] = bc_val ( n, t, xcon, ycon )\n\n%*****************************************************************************80\n%\n%% BC_VAL evaluates a parameterized Bezier curve.\n%\n% Discussion:\n%\n% BC_VAL(T) is the value of a vector function of the form\n%\n% BC_VAL(T) = ( X(T), Y(T) )\n%\n% where\n%\n% X(T) = Sum ( 0 <= I <= N ) XCON(I) * BERN(I,N)(T)\n% Y(T) = Sum ( 0 <= I <= N ) YCON(I) * BERN(I,N)(T)\n%\n% BERN(I,N)(T) is the I-th Bernstein polynomial of order N\n% defined on the interval [0,1],\n%\n% XCON(0:N) and YCON(0:N) are the coordinates of N+1 \"control points\".\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 February 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Kahaner, Moler, and Nash,\n% Numerical Methods and Software,\n% Prentice Hall, 1989.\n%\n% Parameters:\n%\n% Input, integer N, the order of the Bezier curve, which\n% must be at least 0.\n%\n% Input, real T, the point at which the Bezier curve should\n% be evaluated. The best results are obtained within the interval\n% [0,1] but T may be anywhere.\n%\n% Input, real XCON(0:N), YCON(0:N), the X and Y coordinates\n% of the control points. The Bezier curve will pass through\n% the points ( XCON(0), YCON(0) ) and ( XCON(N), YCON(N) ), but\n% generally NOT through the other control points.\n%\n% Output, real XVAL, YVAL, the X and Y coordinates of the point\n% on the Bezier curve corresponding to the given T value.\n%\n bval = bp01 ( n, t );\n\n xval = xcon(1:n+1) * bval(1:n+1)';\n yval = ycon(1:n+1) * bval(1: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/spline/bc_val.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172644875641, "lm_q2_score": 0.8774767954920548, "lm_q1q2_score": 0.8326528804296344}} {"text": "function [w,rho] = mh(A)\n% Computes the Metropolis-Hastings heuristic edge weights\n%\n% [W,RHO] = MH(A) gives a vector of the Metropolis-Hastings edge weights\n% for a graphb described by the incidence matrix A (NxM). N is the number\n% of nodes, and M is the number of edges. Each column of A has exactly one\n% +1 and one -1. RHO is computed from the weights W as follows:\n% RHO = max(abs(eig( eye(n,n) - (1/n)*ones(n,n) - A*W*A' ))).\n%\n% The M.-H. weight on an edge is one over the maximum of the degrees of the\n% adjacent nodes.\n%\n% For more details, see the references:\n% \"Fast linear iterations for distributed averaging\" by L. Xiao and S. Boyd\n% \"Fastest mixing Markov chain on a graph\" by S. Boyd, P. Diaconis, and L. Xiao\n% \"Convex Optimization of Graph Laplacian Eigenvalues\" by S. Boyd\n%\n% Almir Mutapcic 08/29/06\n\n% degrees of the nodes\nn = size(A,1);\nLunw = A*A'; % unweighted Laplacian matrix\ndegs = diag(Lunw);\n\n% Metropolis-Hastings weights\nmh_degs = abs(A)'*diag(degs);\nw = 1./max(mh_degs,[],2);\n\n% compute the norm\nif nargout > 1,\n rho = norm( eye(n) - A*diag(w)*A' - (1/n)*ones(n) );\nend\n\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/mh.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104914476338, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.8325995626593076}} {"text": "function u=randDirVec(numDim,N)\n%%RANDDIRVEC Generate a uniformly distributed random direction vector\n% (unit vector) in an arbitrary number of dimensions.\n%\n%INPUTS: numDim The number of dimensions of the random unit vector. This\n% is >=1.\n% N The number of random direction vectors to generate. If\n% this parameter is omitted, then N=1 is used.\n%\n%OUTPUTS: u A numDimXN matrix of N numDim-dimensional unit vectors that\n% are uniformly distributed on the unit-sphere (or hypersphere).\n%\n%One cannot simply generate a uniformly-distributed direction vector by\n%setting each dimensions to a Uniform(-1,1) random variable and then\n%normalizing the result. Rather, following the algorithm in Chapter 3.4.1,\n%E6 of [1], the elements of the vector must be generated as normal 0-1\n%random variables and then the vector normalized.\n%\n%REFERENCES:\n%[1] D. Knuth, The Art of Computer Programming: Seminumerical Algorithms,\n% 3rd ed. Reading, MA: Addison-Wesley, 1998, vol. 2.\n%\n%September 2014 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<2)\n N=1;\nend\n\nu=zeros(numDim,N);\n\nfor curN=1:N\n %Knuth, Chapter 3.4.1, E6 (Random point on an n-dimensional sphere with\n %radius one. \n u(:,curN)=randn(numDim,1);\n u(:,curN)=u(:,curN)/norm(u(:,curN));\n\n %Deal with the instance that norm(u)=0, which will occur with an extremely\n %small probability due to the limited precision of the random number\n %generation.\n if(~isfinite(u(:,curN)))\n u(:,curN)=zeros(numDim,1);\n u(1,curN)=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/Statistics/randDirVec.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.9019206804839998, "lm_q1q2_score": 0.832508115001323}} {"text": "function Z = projectData(X, U, K)\n%PROJECTDATA Computes the reduced data representation when projecting only \n%on to the top k eigenvectors\n% Z = projectData(X, U, K) computes the projection of \n% the normalized inputs X into the reduced dimensional space spanned by\n% the first K columns of U. It returns the projected examples in Z.\n%\n\n% You need to return the following variables correctly.\nZ = zeros(size(X, 1), K);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the projection of the data using only the top K \n% eigenvectors in U (first K columns). \n% For the i-th example X(i,:), the projection on to the k-th \n% eigenvector is given as follows:\n% x = X(i, :)';\n% projection_k = x' * U(:, k);\n%\n\nsubsetU = U(:, 1:K);\nZ = X * subsetU;\n\n% =============================================================\n\nend\n", "meta": {"author": "khanhnamle1994", "repo": "machine-learning", "sha": "fa391eb9429187a295c15a14ba24f4416667e5c1", "save_path": "github-repos/MATLAB/khanhnamle1994-machine-learning", "path": "github-repos/MATLAB/khanhnamle1994-machine-learning/machine-learning-fa391eb9429187a295c15a14ba24f4416667e5c1/machine-learning-ex7/ex7/projectData.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.9019206857566127, "lm_q1q2_score": 0.8325081084114492}} {"text": "% Script file: lsqfit.m\n%\n% Purpose: \n% To perform a least-squares fit of an input data set\n% to a straight line, and print out the resulting slope\n% and intercept values. The input data for this fit\n% comes from a user-specified input data file.\n%\n% Record of revisions:\n% Date Programmer Description of change\n% ==== ========== =====================\n% 03/24/07 S. J. Chapman Original code \n%\n% Define variables:\n% count -- number of values read\n% filename -- Input file name\n% fid -- File id\n% msg -- Open error message\n% n -- Number of input data pairs (x,y)\n% slope -- Slope of the line\n% sum_x -- Sum of all input X values\n% sum_x2 -- Sum of all input X values squared\n% sum_xy -- Sum of all input X*Y values\n% sum_y -- Sum of all input Y values\n% x -- An input X value\n% x_bar -- Average X value\n% y -- An input Y value\n% y_bar -- Average Y value\n% y_int -- Y-axis intercept of the line\n\n% Initialize sums\nn = 0; sum_x = 0; sum_y = 0; sum_x2 = 0; sum_xy = 0;\nx1 = []; y1 = [];\n\n% Prompt user and get the name of the input file.\ndisp('This program performs a least-squares fit of an');\ndisp('input data set to a straight line. Enter the name');\ndisp('of the file containing the input (x,y) pairs: ' );\nfilename = input(' ','s');\n\n% Open the input file\n[fid,msg] = fopen(filename,'rt');\n\n% Check to see if the open failed.\nif fid < 0 \n\n % There was an error--tell user.\n disp(msg);\n\nelse\n \n % File opened successfully. Read the (x,y) pairs from \n % the input file. Get first (x,y) pair before the\n % loop starts.\n [in,count] = fscanf(fid,'%g %g',2);\n \n while ~feof(fid)\n x = in(1);\n y = in(2);\n n = n + 1; %\n sum_x = sum_x + x; % Calculate \n sum_y = sum_y + y; % statistics\n sum_x2 = sum_x2 + x.^2; %\n sum_xy = sum_xy + x * y; %\n x1(n) = x;\n y1(n) = y;\n\n % Get next (x,y) pair\n [in,count] = fscanf(fid,'%f',[1 2]);\n\n end\n \n % Close the file\n fclose(fid);\n \n % Now calculate the slope and intercept. \n x_bar = sum_x / n;\n y_bar = sum_y / n;\n slope = (sum_xy - sum_x*y_bar) / (sum_x2 - sum_x*x_bar);\n y_int = y_bar - slope * x_bar; \n \n % Tell user.\n fprintf('Regression coefficients for the least-squares line:\\n');\n fprintf(' Slope (m) = %12.3f\\n',slope);\n fprintf(' Intercept (b) = %12.3f\\n',y_int);\n fprintf(' No of points = %12d\\n',n);\n \n % Now plot this data set\n figure(1);\n plot(x1,y1,'bo','LineWidth',2);\n hold on;\n \n % Now plot the fitted line\n x2 = x1;\n y2 = slope .* x2 + y_int;\n plot(x2,y2,'r-','LineWidth',2);\n hold off;\n \n % Title and labels\n title ('\\bfLeast-Squares Fit');\n xlabel ('\\bf\\itx');\n ylabel ('\\bf\\ity');\n grid on;\n\nend\n", "meta": {"author": "101Hub", "repo": "Matlab101", "sha": "07273f68f1147a110443aeb121fa10962234f298", "save_path": "github-repos/MATLAB/101Hub-Matlab101", "path": "github-repos/MATLAB/101Hub-Matlab101/Matlab101-07273f68f1147a110443aeb121fa10962234f298/assets/《Matlab编程》源码/chap8/lsqfit_plot.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.909906997487259, "lm_q1q2_score": 0.8324747767333276}} {"text": "function g = sigmoid(z)\n%SIGMOID Compute sigmoid functoon\n% J = SIGMOID(z) computes the sigmoid of z.\n\n% You need to return the following variables correctly \ng = zeros(size(z));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the sigmoid of each value of z (z can be a matrix,\n% vector or scalar).\n\ng = 1 ./ (1 + (1 ./ exp(z)));\n\n% =============================================================\n\nend\n", "meta": {"author": "sfvsfv", "repo": "Mathematical-modeling", "sha": "cef1a3688246851f067777b3599b1b3831d3d948", "save_path": "github-repos/MATLAB/sfvsfv-Mathematical-modeling", "path": "github-repos/MATLAB/sfvsfv-Mathematical-modeling/Mathematical-modeling-cef1a3688246851f067777b3599b1b3831d3d948/matlab吴恩达机器学习/machine-learning-ex2/ex2/sigmoid.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541561135441, "lm_q2_score": 0.8840392863287585, "lm_q1q2_score": 0.8324592681391269}} {"text": "function a = fourier_cosine ( n )\n\n%*****************************************************************************80\n%\n%% FOURIER_COSINE returns the FOURIER_COSINE matrix.\n%\n% Discussion:\n%\n% FOURIER_COSINE is the discrete Fourier Cosine Transform matrix.\n%\n% Example:\n%\n% N = 5\n%\n% 0.447214 0.447214 0.447214 0.447214 0.447214\n% 0.601501 0.371748 0.000000 -0.371748 -0.601501\n% 0.511667 -0.195440 -0.632456 -0.195439 0.511667\n% 0.371748 -0.601501 0.000000 0.601501 -0.371748\n% 0.195439 -0.511667 0.632456 -0.511668 0.195439\n%\n% Properties:\n%\n% A * A' = I.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 08 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Output, real A(N,N), the matrix.\n%\n a = zeros ( n, n );\n\n a(1,1:n) = 1.0 / sqrt ( n );\n\n for i = 2 : n\n\n for j = 1 : n\n \n angle = ( i - 1 ) * ( 2 * j - 1 ) * pi / ( 2 * n );\n a(i,j) = sqrt ( 2.0 ) * cos ( angle ) / sqrt ( n );\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/fourier_cosine.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509315, "lm_q2_score": 0.8840392832736084, "lm_q1q2_score": 0.8324592667097469}} {"text": "function val=polygamma(k,z)\n%%POLYGAMMA Evaluate the polygamma function. This function is the same as\n% the psi function except it will work with negative values of z.\n% The polygamma function is the value of the kth derivative of\n% the derivative of gamma(z) divided by gamma(z). That is, it is\n% the kth derivative of the digamma function.\n%\n%INPUTS: This function can be used with 1 or two inputs. If two inputs are\n% given, then it is polygamma(k,z). If only one is given, then it is\n% polygamma(z) where k is taken to be zero. The inputs are:\n% k The number of derivatives to take, k>=0. The digamma function is\n% k=0.\n% z A matrix of points at which the polygamma function is to be\n% evaluated.\n%\n%OUTPUTS: val The values of the polygamma function. This is the same size\n% as z.\n%\n%For values of z>0, this function just calls psi(k,z). For values of z<0,\n%this function uses the identity of [1] to deal with negative values. For\n%example, for k=0, one uses the identity:\n%psi(1-x)=psi(x)+pi/tan(pi*x)\n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Polygamma Function.\" From MathWorld--A Wolfram Web\n% Resource. http://mathworld.wolfram.com/PolygammaFunction.html\n%\n%October 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin==1)\n z=k;\n k=0;\nend\n\nnumVals=numel(z);\nval=zeros(size(z));\n\nfor curVal=1:numVals\n x=z(curVal);\n if(x>0)\n val(curVal)=psi(k,x);\n else\n x=1-x;\n val(curVal)=(-1)^k*(psi(k,x)+pi^(k+1)*cotDerivVal(pi*x,k));\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/polygamma.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850442, "lm_q2_score": 0.8918110562208682, "lm_q1q2_score": 0.8324439224478158}} {"text": "function enum = deranged_enum ( n )\n\n%*****************************************************************************80\n%\n%% DERANGED_ENUM returns the number of derangements of N objects.\n%\n% Discussion:\n%\n% A derangement of N objects is a permutation with no fixed\n% points. If we symbolize the permutation operation by \"P\",\n% then for a derangment, P(I) is never equal to I.\n%\n% Recursion:\n%\n% D(0) = 1\n% D(1) = 0\n% D(2) = 1\n% D(N) = (N-1) * ( D(N-1) + D(N-2) )\n%\n% or\n%\n% D(0) = 1\n% D(1) = 0\n% D(N) = N * D(N-1) + (-1)**N\n%\n% Formula:\n%\n% D(N) = N! * ( 1 - 1/1! + 1/2! - 1/3! ... 1/N! )\n%\n% Based on the inclusion/exclusion law.\n%\n% D(N) is the number of ways of placing N non-attacking rooks on\n% an N by N chessboard with one diagonal deleted.\n%\n% Limit ( N -> Infinity ) D(N)/N! = 1 / e.\n%\n% The number of permutations with exactly K items in the right\n% place is COMB(N,K) * D(N-K).\n%\n% First values:\n%\n% N D(N)\n% 0 1\n% 1 0\n% 2 1\n% 3 2\n% 4 9\n% 5 44\n% 6 265\n% 7 1854\n% 8 14833\n% 9 133496\n% 10 1334961\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 N, the number of objects to be permuted.\n%\n% Output, integer ENUM, the number of derangements of N objects.\n%\n if ( n < 0 )\n\n dn = 0;\n\n elseif ( n == 0 )\n\n dn = 1;\n\n elseif ( n == 1 )\n\n dn = 0;\n\n elseif ( n == 2 )\n\n dn = 1;\n\n else\n\n dnm1 = 0;\n dn = 1;\n\n for i = 3 : n\n dnm2 = dnm1;\n dnm1 = dn;\n dn = ( i - 1 ) * ( dnm1 + dnm2 );\n end\n\n end\n\n enum = dn;\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/deranged_enum.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294982, "lm_q2_score": 0.8918110504699678, "lm_q1q2_score": 0.8324439121252508}} {"text": "function [ v, seed ] = vibonacci ( n, seed )\n\n%*****************************************************************************80\n%\n%% VIBONACCI computes the first N Vibonacci numbers.\n%\n% Discussion:\n%\n% The \"Vibonacci numbers\" are a generalization of the Fibonacci numbers:\n% V(N+1) = +/- V(N) +/- V(N-1)\n% where the signs are chosen randomly.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 March 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Brian Hayes,\n% The Vibonacci Numbers,\n% American Scientist,\n% July-August 1999, Volume 87, Number 4.\n%\n% Divakar Viswanath,\n% Random Fibonacci sequences and the number 1.13198824,\n% Mathematics of Computation, 1998.\n%\n% Parameters:\n%\n% Input, integer N, the highest number to compute.\n%\n% Input, integer SEED, a seed for the random number generator.\n%\n% Output, integer V(N), the first N Vibonacci numbers. By convention,\n% V(1) and V(2) are taken to be 1.\n%\n% Output, integer SEED, an updated seed for the random number generator.\n%\n if ( n <= 0 )\n v = [];\n return\n end\n\n v(1) = 1;\n\n if ( n <= 1 )\n return\n end\n\n v(2) = 1;\n\n for i = 3 : n\n \n [ j, seed ] = i4_uniform_ab ( 0, 1, seed );\n\n if ( j == 0 )\n s1 = -1;\n else\n s1 = +1;\n end\n\n [ j, seed ] = i4_uniform_ab ( 0, 1, seed );\n\n if ( j == 0 )\n s2 = -1;\n else\n s2 = +1;\n end\n\n v(i) = s1 * v(i-1) + s2 * v(i-2);\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/polpak/vibonacci.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763572, "lm_q2_score": 0.8872046056466901, "lm_q1q2_score": 0.8323079461337454}} {"text": "function [xopt,fopt,niter,gnorm,dx] = grad_descent(varargin)\n% grad_descent.m demonstrates how the gradient descent method can be used\n% to solve a simple unconstrained optimization problem. Taking large step\n% sizes can lead to algorithm instability. The variable alpha below\n% specifies the fixed step size. Increasing alpha above 0.32 results in\n% instability of the algorithm. An alternative approach would involve a\n% variable step size determined through line search.\n%\n% This example was used originally for an optimization demonstration in ME\n% 149, Engineering System Design Optimization, a graduate course taught at\n% Tufts University in the Mechanical Engineering Department. A\n% corresponding video is available at:\n% \n% http://www.youtube.com/watch?v=cY1YGQQbrpQ\n%\n% Author: James T. Allison, Assistant Professor, University of Illinois at\n% Urbana-Champaign\n% Date: 3/4/12\n\nif nargin==0\n % define starting point\n x0 = [3 3]';\nelseif nargin==1\n % if a single input argument is provided, it is a user-defined starting\n % point.\n x0 = varargin{1};\nelse\n error('Incorrect number of input arguments.')\nend\n\n% termination tolerance\ntol = 1e-6;\n\n% maximum number of allowed iterations\nmaxiter = 1000;\n\n% minimum allowed perturbation\ndxmin = 1e-6;\n\n% step size ( 0.33 causes instability, 0.2 quite accurate)\nalpha = 0.1;\n\n% initialize gradient norm, optimization vector, iteration counter, perturbation\ngnorm = inf; x = x0; niter = 0; dx = inf;\n\n% define the objective function:\nf = @(x1,x2) x1.^2 + x1.*x2 + 3*x2.^2;\n\n% plot objective function contours for visualization:\nfigure(1); clf; ezcontour(f,[-5 5 -5 5]); axis equal; hold on\n\n% redefine objective function syntax for use with optimization:\nf2 = @(x) f(x(1),x(2));\n\n% gradient descent algorithm:\nwhile and(gnorm>=tol, and(niter <= maxiter, dx >= dxmin))\n % calculate gradient:\n g = grad(x);\n gnorm = norm(g);\n % take step:\n xnew = x - alpha*g;\n % check step\n if ~isfinite(xnew)\n display(['Number of iterations: ' num2str(niter)])\n error('x is inf or NaN')\n end\n % plot current point\n plot([x(1) xnew(1)],[x(2) xnew(2)],'ko-')\n refresh\n % update termination metrics\n niter = niter + 1;\n dx = norm(xnew-x);\n x = xnew;\n \nend\nxopt = x;\nfopt = f2(xopt);\nniter = niter - 1;\n\n% define the gradient of the objective\nfunction g = grad(x)\ng = [2*x(1) + x(2)\n x(1) + 6*x(2)];", "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/35535-simplified-gradient-descent-optimization/grad_descent.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.9005297807787537, "lm_q1q2_score": 0.8322172286725129}} {"text": "function [ THD, ph, amp ] = compute_THD( t,x, freq )\n% function [ THD, ph, amp ] = compute_THD( t,x, freq )\n%\n% Written by Dr. Yoash Levron\n% February 2013.\n%\n% computes the Total-Harmonic-Distortion (THD)\n% of a signal x(t). The amplitude and phase of the\n% basic harmonic are also computed. These values\n% are typically useful in power systems, audio signal\n% processing, and other related fields.\n%\n% DC offset does not affect THD.\n%\n% The function computes the basic harmonic\n% of the signal, in the form:\n% x(t) = amp*cos(w*t - ph) + (higher Harmonics)\n% where : w = 2*pi*freq\n% so 'amp' and 'ph' are the phase and amplitude\n% of the basic harmonic.\n%\n% inputs:\n% t - [sec] time vector. (should be periodical with basic harmonic 'freq')\n% x - signal vector.\n% freq - [Hz] frequency of the basic harmonic. \n%\n% outputs:\n% THD - total harmonic distortion (the scale is 1 = 100%).\n% ph - [rad] phase of the basic harmonic.\n% amp - Amplitude of the basic harmonic.\n\n%%%%%%%%%%%% start function %%%%%%%%%%\n\n%%% check that t,x are the same length\nif (length(t) ~= length(x))\n 'Error: t and x should be the same length'\n THD = NaN; ph = NaN; amp = NaN;\n beep; return\nend\n\nif (size(t,2) == 1)\n t = t.';\nend\nif (size(x,2) == 1)\n x = x.';\nend\n\n%%% condition input time vector\ninput_error = 0;\n%%% add two samples to complete the last cycle.\nt = t - t(1); % remove any time shift\ndtt = t(end) - t(end-1);\nt = [t (t(end)+dtt) (t(end)+2*dtt)];\nx = [x x(end) x(end)];\nT = t(end);\nif (T < (1/freq) )\n input_error = 1;\nend\nif (input_error)\n 'Error: Input time vector is illegal. Time samples should expand at least to 1/freq'\n THD = NaN; ph = NaN; amp = NaN;\n beep; return\nend\n\n% truncate extra samples, to fit in an integer number of cycles of freq\nT = floor(T * freq) /freq;\n\n% resample on a linear grid:\n% t1, x1 is the new input, not including the last sample\nx = x - sum(x)/length(x); % remove any DC offset\nN = max(1e6, length(x)); % number of samples\ndt = T/N;\nt1 = 0:dt:(T-dt);\nx1 = interp1(t,x,t1,'cubic');\n\n%%% compute cos-sin fourier coefficients\nw = 2*pi*freq;\nacs = (2/T) * sum(x1.*cos(w*t1))*dt; % basic frequency cos coefficient.\nbsn = (2/T) * sum(x1.*sin(w*t1))*dt; % basic frequency sin coefficient.\namp = (acs^2 + bsn^2)^0.5;\nph = pi/2 - sign(acs) * acos(bsn/amp);\n\nrms22 = (2/T) * sum(x1.^2) * dt;\nTHD = (rms22/amp^2 - 1)^0.5;\n\n% correct phase to be in the range [-pi : pi]\nif (ph > pi)\n ph = ph - 2*pi;\nend\nif (ph < -pi)\n ph = ph + 2*pi;\nend\n \nend\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/40455-computes-the-total-harmonic-distortion-thd-of-a-signal/compute_THD.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966732132748, "lm_q2_score": 0.8791467564270272, "lm_q1q2_score": 0.8321973949000652}} {"text": "function centroid = triangle_centroid_2d ( t )\n\n%*****************************************************************************80\n%\n%% TRIANGLE_CENTROID_2D computes the centroid of a triangle in 2D.\n%\n% Discussion:\n%\n% The centroid of a triangle can also be considered the\n% center of gravity, or center of mass, assuming that the triangle\n% is made of a thin uniform sheet of massy material.\n%\n% The centroid of a triangle is the intersection of the medians.\n%\n% A median of a triangle is a line connecting a vertex to the\n% midpoint of the opposite side.\n%\n% In barycentric coordinates, in which the vertices of the triangle\n% have the coordinates (1,0,0), (0,1,0) and (0,0,1), the centroid\n% has coordinates (1/3,1/3,1/3).\n%\n% In geometry, the centroid of a triangle is often symbolized by \"G\".\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 30 January 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, real T(2,3), the triangle vertices.\n%\n% Output, real CENTROID(2,1), the coordinates of the centroid.\n%\n dim_num = 2;\n\n for i = 1 : dim_num\n centroid(i,1) = sum ( t(i,1:3) ) / 3.0;\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/triangle_centroid_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252812, "lm_q2_score": 0.905989829267587, "lm_q1q2_score": 0.8321337594701161}} {"text": "% 近似计算 算法稳定性的演示\nclear;\n\n% 解法一 n从小到大\nS0 = 0.182;\nS(1) = 1 - 5*S0;\nfor n = 2 : 8\n S(n) = 1/n - 5*S(n-1);\n S(n) = vpa(S(n),3);\nend\ndisp('解法一:')\ndisp(S)\n\n% 解法二 n从大到小\nS(8) = 0.0204;\nfor n = 8: -1 : 2\n S(n-1) = 1/(5*n) - S(n)/5;\n S(n-1) = vpa(S(n-1),3);\nend\ndisp('解法二:')\ndisp(S)\n\n% 精确值\nsyms x\nfor n = 1 : 5 % 8\n S(n) = int(x^n/(x+5),0,1);\n S(n) = vpa(S(n),3);\nend\ndisp('精确值:')\ndisp(S)", "meta": {"author": "qxr777", "repo": "NumericalAnalysis", "sha": "145e47521459defdcfd6a929702651abe29ba6de", "save_path": "github-repos/MATLAB/qxr777-NumericalAnalysis", "path": "github-repos/MATLAB/qxr777-NumericalAnalysis/NumericalAnalysis-145e47521459defdcfd6a929702651abe29ba6de/第一章 引论/demo_1_2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850110816423, "lm_q2_score": 0.8887587831798665, "lm_q1q2_score": 0.8321315271584682}} {"text": "function Q=cotes(f,a,b,N,nodes)\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% cotes.m\n%\n% 2 to 11 point Summed Newton-Cotes numerical integration formulas.\n%\n% Inputs: \n%\n% f - function to be integrated\n% a - lower limit of integration\n% b - upper limit of integration\n% N - Requested number of grid points\n% nodes - number of nodes in Newton-Cotes formula\n%\n% Sample Usage:\n%\n% >>cotes(@sin,0,pi/2,20,5)\n%\n% ans =\n% 0.999999999501637 \n%\n% Written by: Greg von Winckel\n% Contact: gregvw(at)math(dot)unm(dot)edu\n% URL: http://math.unm.edu/~gregvw\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\nN = (nodes-1)*ceil(N/(nodes-1)); N1=N+1;\nx = linspace(a,b,N1)';\nh = x(2)-x(1); g=f(x);\n\nendpts = g(1)+g(N1);\n\nswitch nodes\n\n case{2} % Trapezoidal Rule\n Q=(h/2)*(endpts+2*sum(g(2:N)));\n\n case{3} % Simpson's Rule\n Q=(h/3)*(endpts+4*sum(g(2:2:N))+2*sum(g(3:2:N)));\n\n case{4} % Simpson's 3/8 Rule\n Q=(3*h/8)*(endpts+3*sum(g(2:3:N)+g(3:3:N))+2*sum(g(4:3:N)));\n\n case{5} % Boole's 4/90 Rule\n Q=(4*h/90)*(7*endpts+32*sum(g(2:4:N))+...\n 12*sum(g(3:4:N))+32*sum(g(4:4:N))+14*sum(g(5:4:N)));\n\n case{6} \n Q=(5*h/288)*(19*endpts+75*sum(g(2:5:N)+g(5:5:N))+...\n 50*sum(g(3:5:N)+g(4:5:N))+38*sum(g(6:5:N)));\n\n case{7} \n Q=(6*h/840)*(41*endpts+216*sum(g(2:6:N)+g(6:6:N))+...\n 27*sum(g(3:6:N)+g(5:6:N))+272*sum(g(4:6:N))+...\n +82*sum(g(7:6:N)));\n\n case{8} \n Q=(7*h/17280)*(751*endpts+3577*sum(g(2:7:N)+g(7:7:N))+...\n 1323*sum(g(3:7:N)+g(6:7:N))+2989*sum(g(4:7:N)+g(5:7:N))+...\n +1502*sum(g(8:7:N)));\n\n case{9}\n Q=(4*h/14175)*(989*endpts+5888*sum(g(2:8:N)+g(8:8:N))-...\n 928*sum(g(3:8:N)+g(7:8:N))+10496*sum(g(4:8:N)+g(6:8:N))-...\n 4540*sum(g(5:8:N))+1978*sum(g(9:8:N)));\n\n case{10}\n Q=(9*h/89600)*(2857*endpts+15741*sum(g(2:9:N)+g(9:9:N))+...\n 1080*sum(g(3:9:N)+g(8:9:N))+19344*sum(g(4:9:N)+g(7:9:N))+...\n 5778*sum(g(5:9:N)+g(6:9:N))+5714*sum(g(10:9:N)));\n\n case{11}\n Q=(5*h/299376)*(16067*endpts+106300*sum(g(2:10:N)+g(10:10:N))-...\n 48525*sum(g(3:10:N)+g(9:10:N))+272400*sum(g(4:10:N)+g(8:10:N))-...\n 260550*sum(g(5:10:N)+g(7:10:N))+427368*sum(g(6:10:N))+...\n 32134*sum(g(11:10:N)));\n otherwise\n error('Order must be between 2 and 11'); \nend\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/QuadratureMethods/cotes.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9637799441350252, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.8321195125455332}} {"text": "function angles = polyangles(x,y)\n%POLYANGLES Computes internal polygon angles.\n%\tANGLES = POLYANGLES(X,Y) computes the interior angles (in degrees) of\n%\tan arbitrary polygon whose vertices have x- and y-coordinates given\n%\tin column vectors X and Y. The vertices must be arranged in a\n%\tclockwise manner. The program eliminates duplicate adjacent rows in\n%\t[X,Y], except that the first row may equal the last, so that the\n%\tpolygon is closed.\n%\n% Copyright 2002-2020 Gatesmark\n%\n% This function, and other functions in the DIPUM Toolbox, are based \n% on the theoretical and practical foundations established in the \n% book Digital Image Processing Using MATLAB, 3rd ed., Gatesmark \n% Press, 2020.\n%\n% Book website: http://www.imageprocessingplace.com\n% License: https://github.com/dipum/dipum-toolbox/blob/master/LICENSE.txt\n\n% Preliminaries.\nxy = [x(:),y(:)];\nif isempty(xy)\n % No vertices!\n angles = zeros(0,1);\n return\nend\n\n% Close the polygon if necessary.\nif (size(xy,1) == 1) || ~isequal(xy(1,:),xy(end,:))\n xy = [xy;xy(1,:)];\nend\n\n% Eliminate duplicate vertices.\nif size(xy,1) > 2\n xy(all(diff(xy,1,1) == 0,2),:) = [];\nend\n\n% Form a set of vectors by taking the differences between adjacent\n% vertices in the polygon. These vectors form a chain directed in the\n% clockwise direction because of the way the data is input.\nv2 = diff(xy,1,1);\n\n% Each angle of the polygon is formed by the head of a vector joining\n% the tail of the vector following it in the sequence. Each vector in\n% the following array precedes its corresponding vector in v2:\nv1 = circshift(v2,[1 0]);\n\n% Get the x- and y-components of each vector.\nv1x = v1(:,1);\nv1y = v1(:,2);\nv2x = v2(:,1);\nv2y = v2(:,2);\n\n% The angles between the vectors in v2 relative to the vectors in v1 is\n% given by the following expression. See, for example,\n% http://www.euclideanspace.com/maths/algebra/vectors/ and (select\n% \"angle between\" for an explanation of this expression).\nangles = (180/pi)*(atan2(v2y,v2x) - atan2(v1y,v1x));\n\n% Because the head of each vector in v1 points to the tail of the\n% subsequent vector in v2 (see above), the preceding expression gives\n% \"outer\" angles. We need the interior angles of the polygon. To do\n% this, we have to reverse the direction of one of the vectors or,\n% equivalently, add (or subtract) 180 degrees from the previous result.\n% We also want to make sure that all angles are in the range 0 to 360\n% degrees. The following expression implements both requirements:\nangles = mod(angles + 180,360);\n\n\n\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/polyangles.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912913, "lm_q2_score": 0.9284088045171237, "lm_q1q2_score": 0.8320876607322679}} {"text": "function [cRow, cCol, ra, rb, phi] = gauss2ellipse( mu, C, rad )\n% Creates an ellipse representing the 2D Gaussian distribution.\n%\n% Creates an ellipse representing the 2D Gaussian distribution with mean mu\n% and covariance matrix C. Returns 5 parameters that specify the ellipse.\n%\n% USAGE\n% [cRow, cCol, ra, rb, phi] = gauss2ellipse( mu, C, [rad] )\n%\n% INPUTS\n% mu - 1x2 vector representing the center of the ellipse\n% C - 2x2 cov matrix\n% rad - [2] Number of std to create the ellipse to\n%\n% OUTPUTS\n% cRow - the row location of the center of the ellipse\n% cCol - the column location of the center of the ellipse\n% ra - semi-major axis length (in pixels) of the ellipse\n% rb - semi-minor axis length (in pixels) of the ellipse\n% phi - rotation angle (radians) of semimajor axis from x-axis\n%\n% EXAMPLE\n% [cRow, cCol, ra, rb, phi] = gauss2ellipse( [5 5], [1 0; .5 2] )\n% plotEllipse( cRow, cCol, ra, rb, phi );\n%\n% See also PLOTELLIPSE, PLOTGAUSSELLIPSES, MASKELLIPSE\n%\n% Piotr's Computer Vision Matlab Toolbox Version 2.0\n% Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com]\n% Licensed under the Simplified BSD License [see external/bsd.txt]\n\nif (nargin<3 || isempty(rad) ); rad=2; end;\n\n% error check\nif (~all(size(mu)==[1,2]) || ~all(size(C)==[2,2]))\n error('Works only for 2D Gaussians'); end\n\n% decompose using SVD\n[~,D,R] = svd(C);\nnormstd = sqrt( diag( D ) );\n\n% get angle of rotation (in row/column format)\nphi = acos(R(1,1));\nif (R(2,1) < 0); phi = 2*pi - phi; end\nphi = pi/2 - phi;\n\n% get ellipse radii\nra = rad*normstd(1);\nrb = rad*normstd(2);\n\n% center of ellipse\ncRow = mu(1);\ncCol = mu(2);\n", "meta": {"author": "pdollar", "repo": "toolbox", "sha": "e87332637bbe8e8b92dd487c87567d9628404523", "save_path": "github-repos/MATLAB/pdollar-toolbox", "path": "github-repos/MATLAB/pdollar-toolbox/toolbox-e87332637bbe8e8b92dd487c87567d9628404523/matlab/gauss2ellipse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632302488964, "lm_q2_score": 0.8740772269642949, "lm_q1q2_score": 0.8320019727452316}} {"text": "% % See also plotbezierpatch3D.m\n\n% % function to plot 3D cubic Bezier surface in many ways.\n\n% % A Bezier surface is composed of one or more patches.\n% % A patch is defined by 16 control points arranged in 4 x 4 x 3 matrix. \n% % A control point has three coordinates (x,y,z)\n\n% % Details\n% % -> Input Matrix S stores all the control points of all the patches of\n% % a Bezier surface such that\n% % -> S(:,:,:,k) holds control points of kth patch, \n% % where k=1..np and np is number of patches in the surface \n% % -> Size of S(:,:,:,k) is 4 x 4 x 3, i.e., 16 control points and each\n% % control point has three coordinates (x,y,z)\n% % S(:,:,1,k): x-coordates of control points of kth patch as 4 x 4 matrix \n% % S(:,:,2,k): y-coordates of control points of kth patch as 4 x 4 matrix \n% % S(:,:,3,k): z-coordates of control points of kth patch as 4 x 4 matrix\n% % -> Input Matrix Q stores interpolated values between control points\n% % Q is similar to S in format but has more values, i.e., it stores \n% % end control points and interpolated values. \n% % see the function bezierpatchinterp.m for more details\n\nfunction plotbeziersurface3D(S,Q)\n\n[r c dim np]=size(S);\n% % np: number of patches\n\nif dim > 3 or dim < 3 \n error ('plotbeziersurface3D.m function handles only 3-D points')\nend\n\naz=21; %azimuth\nel=19; %elevation. \n\nlw=1; %plotting linewidth\n\nstr1='\\bf Control Point';\nstr2='\\bf Control Polygon';\nstr3='\\bf Surface (bi-directional Bezier curve)';\n\n% %-----------------------------------------------\n% % For plotting it is convenient if we reshape the data\n% % into vecotor format and separate (X,Y,Z) coordinates\n\nxS=[]; yS=[]; zS=[];\nfor k=1:np\n xS =horzcat(xS, reshape(S(:,:,1,k),1,[])); \n yS =horzcat(yS, reshape(S(:,:,2,k),1,[]));\n zS =horzcat(zS, reshape(S(:,:,3,k),1,[])); \nend\n\nxQ=[]; yQ=[]; zQ=[];\nfor k=1:np\n xQ =horzcat(xQ, reshape(Q(:,:,1,k),1,[])); \n yQ =horzcat(yQ, reshape(Q(:,:,2,k),1,[])); \n zQ =horzcat(zQ, reshape(Q(:,:,3,k),1,[])); \nend\n% %------------------------------------------------\n% % Wireframe Plot of Bezier Surface using interpolation of control points\n% % Control Points and Control Polygon are marked \nfigure, hold on\nplot3(xS,yS,zS,'ro','LineWidth',lw)\nplot3(xS,yS,zS,'g','LineWidth',lw)\nplot3(xQ,yQ,zQ,'b','LineWidth',lw)\nlegend(str1,str2,str3);\ntitle('\\bf Wireframe Plot of a Bezier Surface with Control Points and Control Polygon')\nview(3); box; view(az,el)\n% %-----------------------------------------------\n% % Wireframe Plot of Bezier Surface using interpolation of control points\nfigure, hold on\nplot3(xQ,yQ,zQ,'b','LineWidth',lw)\nlegend(str3);\ntitle('\\bf Wireframe Plot of a Bezier Surface')\nview(3); box; view(az,el)\n% %-----------------------------------------------\n% % Plot of Surface using control points \nfigure, hold on\nfor k=1:np\n surface(S(:,:,1,k),S(:,:,2,k),S(:,:,3,k),'FaceColor','green')\nend\ntitle('\\bf Bezier Surface using Control Points');\nview(3); box; view(az,el)\n% %-----------------------------------------------\n% % Plot of Surface using interpolation of control points\nfigure, hold on\nfor k=1:np\n surface(Q(:,:,1,k),Q(:,:,2,k),Q(:,:,3,k),'FaceColor','green')\nend\ntitle('\\bf Bezier Surface using Interpolated Points');\nview(3); box; view(az,el)\n\n% %----------------------------------------------- \n% % Surface with interpolated shading\nfigure, hold on\nfor k=1:np\n surface(Q(:,:,1,k),Q(:,:,2,k),Q(:,:,3,k))\nend\nshading interp\ntitle('\\bf Bezier Surface using Interpolated Shading');\nview(3); box; view(az,el)\n% %-----------------------------------------------% \n% % Surface with faceted shading\nfigure, hold on\nfor k=1:np\n surface(Q(:,:,1,k),Q(:,:,2,k),Q(:,:,3,k))\nend\nshading faceted\ntitle('\\bf Bezier Surface using Faceted Shading');\nview(3); box; view(az,el)\n% %-----------------------------------------------% \n\n% % --------------------------------\n% % This program or any other program(s) supplied with it does not provide any\n% % warranty direct or implied.\n% % This program is free to use/share for non-commerical purpose only. \n% % Kindly reference the author.\n% % Author: Dr. Murtaza Khan\n% % URL : http://www.linkedin.com/pub/dr-murtaza-khan/19/680/3b3\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/37876-construction-of-cubic-bezier-patch-and-surface/BezierPatchSurface/plotbeziersurface3D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.9032942080055513, "lm_q1q2_score": 0.8317439770967114}} {"text": "function cdf = inverse_gaussian_cdf ( x, a, b )\n\n%*****************************************************************************80\n%\n%% INVERSE_GAUSSIAN_CDF evaluates the Inverse Gaussian CDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the CDF.\n% 0.0 < X.\n%\n% Input, real A, B, the parameters of the PDF.\n% 0.0 < A,\n% 0.0 < B.\n%\n% Output, real CDF, the value of the CDF.\n%\n if ( x <= 0.0 )\n\n cdf = 0.0;\n\n else\n\n x1 = sqrt ( b / x ) * ( x - a ) / a;\n cdf1 = normal_01_cdf ( x1 );\n\n x2 = - sqrt ( b / x ) * ( x + a ) / a;\n cdf2 = normal_01_cdf ( x2 );\n\n cdf = cdf1 + exp ( 2.0 * b / a ) * cdf2;\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/prob/inverse_gaussian_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778012346835, "lm_q2_score": 0.8688267643505193, "lm_q1q2_score": 0.8317085746313096}} {"text": "function x= BesseliRatio(nu,kappa,maxIter)\n%%BESSELIRATIO Evaluate the ratio of modified Bessel functions of the first\n% kind of the form x=I_{nu}(kappa)/I_{nu-1}(kappa). \n%\n%INPUTS: nu The positive integer (upper) order of the modified Bessel\n% function of the first kind in the ratio; nu>=1.\n% kappa The real argument of the modified Bessel function of the first\n% kind; kappa>=0.\n% maxIter An optional parameter specifying the maximum number of\n% iterations to use for computing the ratio using an iterative\n% method. If this parameter is omitted or an empty matrix is\n% passed, the default value of 2000 is used. Convergence usually\n% occurs long before the maximum number of iterations is reached.\n%\n%OUTPUTS: x The value of the ratio I_{nu}(kappa)/I_{nu-1}(kappa).\n%\n%Numerical precision limitations can make the evaluation of Bessel function\n%radios difficult if one tries to explicitly evaluate the functions. Here,\n%the algorithm of Perron described in [1] is implemented.\n%\n%REFERENCES:\n%[1] W. Gautschi and J. Slavik, \"On the computation of modified Bessel\n% function ratios,\" Mathematics of Computation, vol. 32, no. 143, pp.\n% 865-875, Jul. 1978.\n%\n%September 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n if(nargin<3||isempty(maxIter))\n %It usually converges long before the maximum number of iterations.\n maxIterations=2000;\n end\n %tolerance for convergence. This should be suitable for double-\n %precision computations.\n tol=1e-15;\n \n k=1;\n cumProd=1;\n pCur=0.5*kappa*(nu+0.5)/((nu+kappa/2)*(nu+kappa+0.5)-0.5*kappa*(nu+0.5));\n cumProd=cumProd*pCur;\n cumSum=1+cumProd;\n while(k= 1)\n fprintf('Warning: significance level must be between 0 and 1\\n');\n return;\nend;\n\nif nargin < 2, \n error('Requires at least two input arguments.');\n return;\nend;\n\na = alpha;\nFc = finv(1-a/n,p,n-p-1); %F distribution critical value with p and n-p-1 degrees of freedom using the Bonferroni correction. \nACR = (p*(n-1)^2*Fc)/(n*(n-p-1)+(n*p*Fc)); % = ((-1*((1/(1+(Fc*p/(n-p-1))))-1))*((n-1)^2))/n;\nx = ACR;\n\nreturn,", "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/12161-acr/ACR.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422227627597, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.8313717690009861}} {"text": "function value = angle_rad ( p1, p2, p3 )\n\n%*****************************************************************************80\n%\n%% ANGLE_RAD returns the angle swept out between two rays.\n%\n% Discussion:\n%\n% Except for the zero angle case, it should be true that\n%\n% ANGLE_RAD(P1,P2,P3) + ANGLE_RAD(P3,P2,P1) = 2 * PI\n%\n% P1\n% /\n% /\n% /\n% /\n% P2--------->P3\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 P1(2,1), P2(2,1), P3(2,1), define the rays\n% P1 - P2 and P3 - P2 which in turn define the angle.\n%\n% Output, real VALUE, the angle swept out by the rays, measured\n% in radians. 0 <= VALUE < 2*PI. If either ray has zero length,\n% then VALUE is set to 0.\n%\n p(1,1) = ( p3(1,1) - p2(1,1) ) * ( p1(1,1) - p2(1,1) ) ...\n + ( p3(2,1) - p2(2,1) ) * ( p1(2,1) - p2(2,1) );\n\n p(2,1) = ( p3(1,1) - p2(1,1) ) * ( p1(2,1) - p2(2,1) ) ...\n - ( p3(2,1) - p2(2,1) ) * ( p1(1,1) - p2(1,1) );\n\n if ( p(1,1) == 0.0 & p(2,1) == 0.0 )\n value = 0.0;\n return\n end\n\n value = atan2 ( p(2,1), p(1,1) );\n\n if ( value < 0.0 )\n value = value + 2.0 * pi;\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/polygon_properties/angle_rad.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370313, "lm_q2_score": 0.8887588008585925, "lm_q1q2_score": 0.8312974392704979}} {"text": "function [phi,theta] = sphCoord(Coord3D)\n% [phi,theta] = sphCoord(Coord3D)\n% \n% This function transforms spherical 3D XYZ spherical coordinates to 2D \n% (theta,phi) spherical coordinates.\n%\n% Input\n% Coord3D: Data Matrix with the spherical XYZ coordinates at the first\n% three columns respectively.\n%\n% Output\n% theta: Latitude \n% phi: Longitud.\n%\n% $Revision: 1.2 $ $Date: 2015/01/06 17:14:55 $\n% Original Author: Jorge Luis Bernal Rusiel \n% CVS Revision Info:\n% $Author: mreuter $\n% $Date: 2015/01/06 17:14:55 $\n% $Revision: 1.2 $\n\n% [theta,phi,r] = cart2sph(overlayData(:,1),overlayData(:,2),overlayData(:,3));\n% //It was confusion\n\nX=Coord3D(:,1); Y=Coord3D(:,2); Z=Coord3D(:,3);\nphi=atan2(Y,X);\ntheta=atan2(sqrt(X.^2+Y.^2),Z);\n\n", "meta": {"author": "vistalab", "repo": "vistasoft", "sha": "7f0102c696c091c858233340cc7e1ab02f064d4c", "save_path": "github-repos/MATLAB/vistalab-vistasoft", "path": "github-repos/MATLAB/vistalab-vistasoft/vistasoft-7f0102c696c091c858233340cc7e1ab02f064d4c/external/freesurfer/lme/mass_univariate/sphCoord.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.966914018751051, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.8312209369948249}} {"text": "function [fResult] = calc_log10poisspdf2(nX, fLambda)\n % Calculates the logarithm to the basis of 10 of the Poisson probability density function.\n % [fResult] = calc_log10poisspdf2(nX, fLambda)\n % --------------------------------------------------\n % Calculates the logarithm to the basis of 10 of the Poisson probability density function.\n % !!! Does not use zero values as input for fLambda!!!!!!\n %\n % Input parameters:\n % nX Parameter x (see help for 'poisspdf')\n % fLambda Parameter lambda (see help for 'poisspdf')\n %\n % Output parameters:\n % fResult Logarithm to the basis of 10 of the Poisson probability density\n %\n % J. Woessner, woessner@seismo.ifg.ethz.ch\n % updated: 03.12.2002\n \n % Create emtpy matrix for results\n fResult = zeros(size(nX));\n if isempty(fResult)\n return;\n end\n fResult(fLambda < 0) = NaN;\n \n % Select all computable elements\n vSel = (nX >= 0 & nX == round(nX) & fLambda > 0);\n \n % Adding of realmin to 0 cases is to get the effect of 0^0 = 1.\n if (any(vSel))\n fResult(vSel) = 1/log(10) * (-fLambda(vSel) + nX(vSel) .* log(fLambda(vSel) + realmin*(fLambda(vSel)==0)) ...\n - gammaln(nX(vSel) + 1));\n %fResult(vSel) = log10(poisspdf(nX(vSel),fLambda(vSel)));\n end\nend\n", "meta": {"author": "CelsoReyes", "repo": "zmap7", "sha": "3895fcb3ca3073608abe22ca71960eb082fd0d9a", "save_path": "github-repos/MATLAB/CelsoReyes-zmap7", "path": "github-repos/MATLAB/CelsoReyes-zmap7/zmap7-3895fcb3ca3073608abe22ca71960eb082fd0d9a/src/jochen/seisvar/calc/calc_log10poisspdf2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566341999997378, "lm_q2_score": 0.8688267796346599, "lm_q1q2_score": 0.8311494112741513}} {"text": "function theta = angle3Points(varargin)\n%ANGLE3POINTS Compute oriented angle made by 3 points.\n%\n% ALPHA = angle3Points(P1, P2, P3);\n% Computes the angle between the points P1, P2 and P3.\n% Pi are either [1*2] arrays, or [N*2] arrays, in this case ALPHA is a \n% [N*1] array. The angle computed is the directed angle between line \n% (P2P1) and line (P2P3).\n% Result is always given in radians, between 0 and 2*pi.\n%\n% See Also:\n% points2d, angles2d, angle2points\n%\n%\n% ---------\n% Author: David Legland\n% e-mail: david.legland@grignon.inra.fr\n% created the 23/02/2004.\n% Copyright 2010 INRA - Cepia Software Platform.\n\n\n% HISTORY :\n% 25/09/2005 : enable single parameter\n\nif length(varargin)==3\n p1 = varargin{1};\n p2 = varargin{2};\n p3 = varargin{3};\nelseif length(varargin)==1\n var = varargin{1};\n p1 = var(1,:);\n p2 = var(2,:);\n p3 = var(3,:);\nend \n\n% angle line (P2 P1)\ntheta = lineAngle(createLine(p2, p1), createLine(p2, p3));\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/z_geom3d/geom3d/private/angle3Points.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9585377284730285, "lm_q2_score": 0.8670357615200474, "lm_q1q2_score": 0.8310864893523087}} {"text": "function J = computeCostMulti(X, y, theta)\n%COMPUTECOSTMULTI Compute cost for linear regression with multiple variables\n% J = COMPUTECOSTMULTI(X, y, theta) computes the cost of using theta as the\n% parameter for linear regression to fit the data points in X and y\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta\n% You should set J to the cost.\n\nJ = (((X*theta)-y)' * ((X*theta)-y))/(2*m);\n\n% =========================================================================\n\nend\n", "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-ex1/ex1/computeCostMulti.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9525741214369554, "lm_q2_score": 0.8723473614033683, "lm_q1q2_score": 0.8309755213766599}} {"text": "function [U, S] = pca(X)\n%PCA Run principal component analysis on the dataset X\n% [U, S, X] = pca(X) computes eigenvectors of the covariance matrix of X\n% Returns the eigenvectors U, the eigenvalues (on diagonal) in S\n%\n\n% Useful values\n[m, n] = size(X);\n\n% You need to return the following variables correctly.\nU = zeros(n);\nS = zeros(n);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: You should first compute the covariance matrix. Then, you\n% should use the \"svd\" function to compute the eigenvectors\n% and eigenvalues of the covariance matrix. \n%\n% Note: When computing the covariance matrix, remember to divide by m (the\n% number of examples).\n%\n\n\nsigma = X' * X / m;\n[U,S,V] = svd(sigma);\n\n\n% =========================================================================\n\nend\n", "meta": {"author": "xjwhhh", "repo": "AndrewNgMachineLearning", "sha": "d9d8491b315755ea3726bc366d72ba069712c363", "save_path": "github-repos/MATLAB/xjwhhh-AndrewNgMachineLearning", "path": "github-repos/MATLAB/xjwhhh-AndrewNgMachineLearning/AndrewNgMachineLearning-d9d8491b315755ea3726bc366d72ba069712c363/code/machine-learning-ex7/ex7/pca.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913343093499, "lm_q2_score": 0.8840392832736084, "lm_q1q2_score": 0.8309203181676781}} {"text": "function [data_mean,data_diff,md,sd] = bland_altman(data1,data2)\n% Function to generate Bland Altman plots. Barry Greene, September 2008\n% Bland, J.M., Altman, D.G. 'Statistical methods for assessing agreement ...\n% between two methods of clinical measurement'(1986) Lancet, 1 (8476), pp. 307-310.\n% Inputs: data1: Data from first instrument\n% data2: Data from second instument \n% Produces Bland Altman plot with mean difference and mean difference +/-\n% 2*SD difference lines.\n\n[m,n] = size(data1);\nif(n>m)\n data1 = data1';\nend\n\nif(size(data1)~=size(data2))\n error('Data matrices must be the same size')\nend\n\ndata_mean = mean([data1,data2],2); % Mean of values from each instrument \ndata_diff = data1 - data2; % Difference between data from each instrument\nmd = mean(data_diff); % Mean of difference between instruments \nsd = std(data_diff); % Std dev of difference between instruments \n\n% figure;\nplot(data_mean,data_diff,'ok','MarkerSize',3,'LineWidth',1); % Bland Altman plot\nhold on; x = [min(data_mean),max(data_mean)];\ny = md*ones(1,2); plot(x,y,'-k'); % Mean difference line \ny = md+2*sd*ones(1,2); \nplot(x,y,'--k'); % Mean plus 2*SD line \n% text(x(2),y(2),'+2 SD'); \ny = md-2*sd*ones(1,2); \nplot(x,y,'--k'); % Mean minus 2*SD line \n\n% text(x(2),y(2),'-2 SD'); \n% grid on\n% title('Bland Altman plot','FontSize',9)\n% xlabel('Mean of two measures','FontSize',8)\n% ylabel('Difference between two measures','FontSize',8)", "meta": {"author": "zhouyuanzxcv", "repo": "Hyperspectral", "sha": "f32dcca86677f8d37596376f57e9c733058f8cff", "save_path": "github-repos/MATLAB/zhouyuanzxcv-Hyperspectral", "path": "github-repos/MATLAB/zhouyuanzxcv-Hyperspectral/Hyperspectral-f32dcca86677f8d37596376f57e9c733058f8cff/common/bland_altman.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133430934989, "lm_q2_score": 0.8840392802184581, "lm_q1q2_score": 0.8309203152961014}} {"text": "function a = forsythe ( alpha, beta, n )\n\n%*****************************************************************************80\n%\n%% FORSYTHE returns the FORSYTHE matrix.\n%\n% Discussion:\n%\n% The Forsythe matrix represents a Jordan canonical matrix, perturbed\n% by a rank one update.\n%\n% Formula:\n%\n% If ( I = J )\n% A(I,J) = BETA\n% else if ( J = I+1 )\n% A(I,J) = 1\n% else if ( I = N and J = 1 ) then\n% A(I,J) = ALPHA\n% else\n% A(I,J) = 0\n%\n% Example:\n%\n% ALPHA = 2, BETA = 3, N = 5\n%\n% 3 1 0 0 0\n% 0 3 1 0 0\n% 0 0 3 1 0\n% 0 0 0 3 1\n% 2 0 0 0 3\n%\n% Properties:\n%\n% A is generally not symmetric: A' /= A.\n%\n% A is Toeplitz: constant along diagonals.\n%\n% A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\n%\n% The characteristic equation of A is\n%\n% ( BETA - LAMBDA )^N - (-1)^N*ALPHA = 0\n%\n% The eigenvalues of A are\n%\n% LAMBDA(I) = BETA\n% + abs ( ALPHA )^1/N * exp ( 2 * I * PI * sqrt ( - 1 ) / N )\n%\n% Gregory and Karney consider the special case where BETA is 0,\n% and ALPHA is a \"small\" value. In that case, the characteristic\n% equation is LAMBDA^N - ALPHA = 0, and the eigenvalues are the\n% N-th root of ALPHA times the N roots of unity.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 08 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Robert Gregory, David Karney,\n% Example 5.22,\n% A Collection of Matrices for Testing Computational Algorithms,\n% Wiley, New York, 1969, page 103, \n% LC: QA263.G68.\n%\n% Parameters:\n%\n% Input, real ALPHA, BETA, define the matrix. A typical \n% value of ALPHA is the square root of the machine precision; a typical\n% value of BETA is 0.0.\n%\n% Input, integer N, the order of A.\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 ( j == i )\n a(i,j) = beta;\n elseif ( j == i + 1 )\n a(i,j) = 1.0;\n elseif ( i == n & j == 1 )\n a(i,j) = alpha;\n else\n a(i,j) = 0.0;\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/test_mat/forsythe.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.899121377945727, "lm_q1q2_score": 0.830915668475064}} {"text": "function probVal=bivarGaussRectangleCDF(rectMin,rectMax,mu,R)\n%%BIVARGAUSSRECTANGLECDF Evaluate the an integral of the probability\n% density function of the bivariate normal distribution with a\n% specified mean and covariance matrix over a specified rectangular\n% region. In other words, it is the cumulative distribution function\n% (CDF) over a rectangular region.\n%\n%INPUTS: rectMin The 2X1 minimum bounds of the rectangular region.\n% rectMax The 2X1 maximum bounds of the rectangular region. Note that\n% rectMax>=rectMin.\n% mu The 2X1 mean of the distribution. If this is omitted or an\n% empty matrix is passed, then the default of [0;0] is used.\n% R The 2X2 covariance matrix of the distribution. If this is\n% omitted or an empty matrix is passed, then R=eye(2,2) is used.\n%\n%OUTPUTS: val The value of the integral.\n%\n%We can use the function bivarNormCDF to evaluate the probability of any\n%region of the form Pr{x1 tol\n\t\t\t% Normalize and store\n\t\t\tO(:,k) = v / n;\n\t\t\tk = k + 1;\n\t\tend\n\tend", "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/32704-icaam-inverse-compositional-active-appearance-models/icaam/gs_orthonorm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075711974104, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.830675603173153}} {"text": "function pdf = benford_pdf ( x )\n\n%*****************************************************************************80\n%\n%% BENFORD_PDF returns the Benford probability of one or more significant digits.\n%\n% Discussion:\n%\n% Benford's law is an empirical formula explaining the observed\n% distribution of initial digits in lists culled from newspapers,\n% tax forms, stock market prices, and so on. It predicts the observed\n% high frequency of the initial digit 1, for instance.\n%\n% Note that the probabilities of digits 1 through 9 are guaranteed\n% to add up to 1, since\n% LOG10 ( 2/1 ) + LOG10 ( 3/2) + LOG10 ( 4/3 ) + ... + LOG10 ( 10/9 )\n% = LOG10 ( 2/1 * 3/2 * 4/3 * ... * 10/9 ) = LOG10 ( 10 ) = 1.\n%\n% PDF(X) = LOG10 ( ( X + 1 ) / X ).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% F Benford,\n% The Law of Anomalous Numbers,\n% Proceedings of the American Philosophical Society,\n% Volume 78, pages 551-572, 1938.\n%\n% T P Hill,\n% The First Digit Phenomenon,\n% American Scientist,\n% Volume 86, July/August 1998, pages 358 - 363.\n%\n% R Raimi,\n% The Peculiar Distribution of First Digits,\n% Scientific American,\n% December 1969, pages 109-119.\n%\n% Parameters:\n%\n% Input, integer X, the string of significant digits to be checked.\n% If X is 1, then we are asking for the Benford probability that\n% a value will have first digit 1. If X is 123, we are asking for\n% the probability that the first three digits will be 123, and so on.\n%\n% Output, real PDF, the Benford probability that an item taken\n% from a real world distribution will have the initial digits X.\n%\n if ( x <= 0 )\n pdf = 0.0;\n else\n pdf = log10 ( ( x + 1 ) / x );\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/prob/benford_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966686936261, "lm_q2_score": 0.8774767762675405, "lm_q1q2_score": 0.8306165932708761}} {"text": "function piece_num = slice ( dim_num, slice_num )\n\n%*****************************************************************************80\n%\n%% SLICE: maximum number of pieces created by a given number of slices.\n%\n% Discussion:\n%\n% If we imagine slicing a pizza, each slice produce more pieces. \n% The position of the slice affects the number of pieces created, but there\n% is a maximum. \n%\n% This function determines the maximum number of pieces created by a given\n% number of slices, applied to a space of a given dimension.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 31 March 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Robert Banks,\n% Slicing Pizzas, Racing Turtles, and Further Adventures in \n% Applied Mathematics,\n% Princeton, 1999,\n% ISBN13: 9780691059471,\n% LC: QA93.B358.\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the spatial dimension.\n%\n% Input, integer SLICE_NUM, the number of slices.\n%\n% Input, integer PIECE_NUM, the maximum number of pieces that can\n% be created by the given number of slices applied in the given dimension.\n%\n piece_num = 0;\n for j = 0 : min ( dim_num, slice_num )\n piece_num = piece_num + i4_choose ( slice_num, 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/polpak/slice.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299529686201, "lm_q2_score": 0.8976953030553434, "lm_q1q2_score": 0.8305745830260466}} {"text": "%Example demonstrating peak interpolation (finds the peak of a function,\n%interpolated between samples using the peak and its two neighbors). \n%This example finds the peak of sin(2*pi*f*x+phi) for unevenly spaced x\n\nN_p=10;%number of points\nf=1/N_p;%frequency (relative to sampling frequency)\n\nx=2*pi*rand(1,N_p);\nx=sort(x);\ny=sin(2*pi*f*x);\n\nx_max_th=N_p/4;%theoretical x for maximum y\ny_max_th=1;%theoretical maximum y\n\n[y_max_int idx_max]=max(y);\nx_max_int=x(idx_max);%integer estimate of peak position\n\n%do a parabolic estimate\n[x_max_p y_max_p A_p]=crit_interp_p(y(idx_max+(-1:1)),x(idx_max+(-1:1)));\n\n%do a Gaussian estimate\n[x_max_g y_max_g A_g]=crit_interp_g(y(idx_max+(-1:1)),x(idx_max+(-1:1)));\n\n%plot the curves\nN_plot=1000;%number of points to plot\nx_plot=linspace(x(idx_max-2),x(idx_max+2),N_plot);\ny_th=sin(2*pi*f*x_plot);\ny_p=A_p(1)*x_plot.^2+A_p(2)*x_plot+A_p(3);\ny_g=A_g(1)*exp(-A_g(2)*(x_plot-A_g(3)).^2);\n\nfprintf('True: y_max=%f at x_max=%f\\nParabolic Estimate: y_max=%f at x_max=%f\\nGaussian Estimate: y_max=%f at x_max=%f\\n',...\n y_max_th,x_max_th,y_max_p,x_max_p,y_max_g,x_max_g)\n\nfigure(1)\nclf\nsubplot(2,1,1)\nplot(x,y,'o',x_plot,y_th,'g',x_plot,y_p,'k',x_plot,y_g,'r')\nxlabel('x')\nylabel('y')\nlegend('Sampled points','Theoretical Curve','Parabolic interpolation','Gaussian Interpolation','location','Best')\n\nsubplot(2,1,2)\nplot(x(idx_max+(-1:1)),y(idx_max+(-1:1)),'o',x_plot,y_th,'g',x_plot,y_p,'k',x_plot,y_g,'r',x_max_p, y_max_p,'kx',x_max_g, y_max_g,'rx',x_max_th, y_max_th,'gx')\nxlabel('x')\nylabel('y')\nlegend('Sampled points','Theoretical Curve','Parabolic interpolation','Gaussian Interpolation','location','Best')", "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/24465-peak-interpolation/peak_interp_0_01/example1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545377452443, "lm_q2_score": 0.8757869819218865, "lm_q1q2_score": 0.830381401007449}} {"text": "function quality2 = tetrahedron_quality2_3d ( tetra )\n\n%*****************************************************************************80\n%\n%% TETRAHEDRON_QUALITY2_3D: \"quality\" of a tetrahedron in 3D.\n%\n% Discussion:\n%\n% The quality measure #2 of a tetrahedron is:\n%\n% QUALITY2 = 2 * sqrt ( 6 ) * RIN / LMAX\n%\n% where\n%\n% RIN = radius of the inscribed sphere;\n% LMAX = length of longest side of the tetrahedron.\n%\n% An equilateral tetrahredron achieves the maximum possible quality of 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 16 August 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Qiang Du and Desheng Wang,\n% The Optimal Centroidal Voronoi Tesselations and the Gersho's\n% Conjecture in the Three-Dimensional Space,\n% Computers and Mathematics with Applications,\n% Volume 49, 2005, pages 1355-1373.\n%\n% Parameters:\n%\n% Input, real TETRA(3,4), the tetrahedron vertices.\n%\n% Output, real QUALITY2, the quality of the tetrahedron.\n%\n dim_num = 3;\n\n edge_length(1:6) = tetrahedron_edge_length_3d ( tetra );\n\n l_max = max ( edge_length(1:6) );\n\n [ r_in, pc ] = tetrahedron_insphere_3d ( tetra );\n\n quality2 = 2.0 * sqrt ( 6.0 ) * r_in / l_max;\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/tet_mesh/tetrahedron_quality2_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632288833652, "lm_q2_score": 0.8723473680407889, "lm_q1q2_score": 0.8303553824512107}} {"text": "function theCombos=genAllRDCombinations(n,t,startVal)\n%%GENALLRDCOMBINATIONS Generate all length t combinations of n elements\n% (n>=t>1) in a resolving door gray-code order. This is\n% such that the difference between each successiuve\n% combination involves changing a single number.\n%\n%INPUTS: n The number of items from which t items are chosen; n>0.\n% t The number of items chosen, t<=n.\n% startVal This is zero or 1, indicating which value the value at which the\n% elements in the combinations can start. The default if omitted\n% or an empty matrix is passed is 0;\n%\n%OUTPUTS: theCombos A tXnumCombos matrix containing all possible\n% combinations of values in the \"revolving door\" order.\n%\n%This function implements algorithm R of Chapter 7.2.1.3 of [1].\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\nif(nargin<3||isempty(startVal))\n startVal=0; \nend\n\nif(n==t&&t==1)\n theCombos=startVal;\n return\nend\n\nnumCombos=binomial(n,t);\ntheCombos=zeros(t,numCombos);\n\n%Step R1, Initialization\nc=[(0:(t-1)).';n];\n\nfor curCombo=1:numCombos\n %Step R2, visit the combination.\n theCombos(:,curCombo)=c(1:t);\n\n %Step R3\n if(mod(t,2)==1)\n if(c(1)+10)\n c(1)=c(1)-1;\n continue;\n else\n j=2;\n skip4=true;\n end\n end\n \n while(1)\n if(skip4==false)\n %Step R4\n if(c(j)>=j)\n c(j)=c(j-1);\n c(j-1)=j-2;\n break;\n else\n j=j+1;\n end\n end\n skip4=false;\n \n %Step R5.\n if(c(j)+1= 1 - u_i for i = 1,...,N\n% a'*y_i - b <= -(1 - v_i) for i = 1,...,M\n% u >= 0 and v >= 0\n% where gamma gives the relative weight of the number of misclassified\n% points compared to the width of the slab.\n\n% data generation\nn = 2;\nrandn('state',2);\nN = 50; M = 50;\nY = [1.5+0.9*randn(1,0.6*N), 1.5+0.7*randn(1,0.4*N);\n 2*(randn(1,0.6*N)+1), 2*(randn(1,0.4*N)-1)];\nX = [-1.5+0.9*randn(1,0.6*M), -1.5+0.7*randn(1,0.4*M);\n 2*(randn(1,0.6*M)-1), 2*(randn(1,0.4*M)+1)];\nT = [-1 1; 1 1];\nY = T*Y; X = T*X;\ng = 0.1; % gamma\n\n% Solution via CVX\ncvx_begin\n variables a(n) b(1) u(N) v(M)\n minimize (norm(a) + g*(ones(1,N)*u + ones(1,M)*v))\n X'*a - b >= 1 - u; %#ok\n Y'*a - b <= -(1 - v); %#ok\n u >= 0; %#ok\n v >= 0; %#ok\ncvx_end\n\n% Displaying results\nlinewidth = 0.5; % for the squares and circles\nt_min = min([X(1,:),Y(1,:)]);\nt_max = max([X(1,:),Y(1,:)]);\ntt = linspace(t_min-1,t_max+1,100);\np = -a(1)*tt/a(2) + b/a(2);\np1 = -a(1)*tt/a(2) + (b+1)/a(2);\np2 = -a(1)*tt/a(2) + (b-1)/a(2);\n\ngraph = plot(X(1,:),X(2,:), 'o', Y(1,:), Y(2,:), 'o');\nset(graph(1),'LineWidth',linewidth);\nset(graph(2),'LineWidth',linewidth);\nset(graph(2),'MarkerFaceColor',[0 0.5 0]);\nhold on;\nplot(tt,p, '-r', tt,p1, '--r', tt,p2, '--r');\naxis equal\ntitle('Approximate linear discrimination via support vector classifier');\n% print -deps svc-discr2.eps\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/cvxbook/Ch08_geometric_probs/svm_2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533163686646, "lm_q2_score": 0.8902942348544447, "lm_q1q2_score": 0.8301578118339297}} {"text": "function value = angle_rad_2d ( p1, p2, p3 )\n\n%*****************************************************************************80\n%\n%% ANGLE_RAD_2D returns the angle swept out between two rays in 2D.\n%\n% Discussion:\n%\n% Except for the zero angle case, it should be true that\n%\n% ANGLE_RAD_2D(P1,P2,P3) + ANGLE_RAD_2D(P3,P2,P1) = 2 * PI\n%\n% P1\n% /\n% /\n% /\n% /\n% P2--------->P3\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 P1(2,1), P2(2,1), P3(2,1), define the rays\n% P1 - P2 and P3 - P2 which in turn define the angle.\n%\n% Output, real VALUE, the angle swept out by the rays, measured\n% in radians. 0 <= VALUE < 2*PI. If either ray has zero length,\n% then VALUE is set to 0.\n%\n p(1,1) = ( p3(1,1) - p2(1,1) ) * ( p1(1,1) - p2(1,1) ) ...\n + ( p3(2,1) - p2(2,1) ) * ( p1(2,1) - p2(2,1) );\n\n p(2,1) = ( p3(1,1) - p2(1,1) ) * ( p1(2,1) - p2(2,1) ) ...\n - ( p3(2,1) - p2(2,1) ) * ( p1(1,1) - p2(1,1) );\n\n if ( p(1,1) == 0.0 & p(2,1) == 0.0 )\n value = 0.0;\n return\n end\n\n value = atan2 ( p(2,1), p(1,1) );\n\n if ( value < 0.0 )\n value = value + 2.0 * pi;\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_rad_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.8902942304882371, "lm_q1q2_score": 0.8301578044203497}} {"text": "function value = h_hofstadter ( n )\n\n%*****************************************************************************80\n%\n%% H_HOFSTADTER computes the Hofstadter H sequence.\n%\n% Discussion:\n%\n% H(N) = 0 if N = 0\n% = N - H ( H ( H ( N - 1 ) ), otherwise.\n%\n% H(N) is defined for all nonnegative integers.\n%\n% Table:\n%\n% N H(N)\n% -- ----\n%\n% 0 0\n% 1 1\n% 2 1\n% 3 2\n% 4 3\n% 5 4\n% 6 4\n% 7 5\n% 8 5\n% 9 6\n% 10 7\n% 11 7\n% 12 8\n% 13 9\n% 14 10\n% 15 10\n% 16 11\n% 17 12\n% 18 13\n% 19 13\n% 20 14\n% 21 14\n% 22 15\n% 23 16\n% 24 17\n% 25 17\n% 26 18\n% 27 18\n% 28 19\n% 29 20\n% 30 20\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 27 July 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Douglas Hofstadter,\n% Goedel, Escher, Bach,\n% Basic Books, 1979.\n%\n% Parameters:\n%\n% Input, integer N, the argument of the function.\n%\n% Output, integer VALUE, the value of the function.\n%\n if ( n <= 0 )\n value = 0;\n else\n value = n - h_hofstadter ( h_hofstadter ( h_hofstadter ( n-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/polpak/h_hofstadter.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533013520764, "lm_q2_score": 0.8902942268497306, "lm_q1q2_score": 0.8301577910007257}} {"text": "function [x, y, z, it]=icosahedron_nodes(f, r)\n% % Syntax;\n% % \n% % [x, y, z, it]=icosahedron_nodes(f, r);\n% % \n% % ***********************************************************\n% % \n% % Description\n% % \n% % Program makes the master triangle for an icosahedron of \n% % f frequency of type 2. \n% % \n% % ***********************************************************\n% % \n% % Input Variables\n% % \n% % f is the frquency of the icosahedron. \n% % f=2 is similar to a soccer ball.\n% % \n% % r is the radius of the icosahedron. \n% % \n% % ***********************************************************\n% % \n% % Output Variables\n% % \n% % x, y, and z are vectors with the rectangular coordinates for the nodes \n% % of a hemispherical icosahedron. \n% % \n% % it is the matrix of coordinate indices for the rectangular coordinate \n% % vectors. \n% % \n% % ***********************************************************\n% % \n% \n% Example\n% \n% f=2; % 2 frequency icosahedron.\n% \n% r=4; % 4 meter radius.\n% \n% [x2, y2, z2, it]=icosahedron_nodes(f, r);\n% \n% % \n% % ***********************************************************\n% % \n% % This program was written by Edward L. Zechmann \n% % \n% % date January 2007 \n% % \n% % modified 11 March 2008 added examples\n% % \n% % ***********************************************************\n% % \n% % Feel free to modify this code.\n% % \n\n\n%calculate the coordinate indices\n% i1 -> x\n% i2 -> y\n% i3 -> z\n\nnum_pts=0.5*((f+1)^2+(f+1));\n\nit=zeros(3,num_pts);\n\nfor e1=1:(f+1);\n i1=f-e1+1;\n for e2=1:(e1);\n i2=(e2-1);\n i3=(f-i1-i2);\n \n a=e1+1;\n b=f+1;\n if a <= f+1;\n pt=0.5*(b^2+b-a^2+a)+i2+1;\n else\n pt=i2+1;\n end\n \n it(1, pt)=i1;\n it(2, pt)=i2;\n it(3, pt)=i3;\n end\nend\n\nx1=1:num_pts;\ny1=1:num_pts;\nz1=1:num_pts;\n\n% Coordinate formulas for base pentagon\n% Icosahedron class 1, type 2, frequency f\ntau=0.5*(1+sqrt(5));\n\nfor e1=1:num_pts;\n \n i1=it(1, e1);\n i2=it(2, e1);\n i3=it(3, e1);\n \n x1(e1)=i1*sin(72/180*pi);\n y1(e1)=i2+i1*cos(72/180*pi);\n z1(e1)=f/2+i3/tau;\n\nend\n\n[rho, theta, phi]=spherical_angle_ed(x1, y1, z1);\n[x, y, z]=spherical_to_rectangular(r, theta, phi);\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/19169-make-icosahedron/icosahedron_nodes.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012686491107, "lm_q2_score": 0.8774767906859264, "lm_q1q2_score": 0.8299186618408995}} {"text": "function basis = basis_col(A)\n%\n% Bases\n% \n% basis_col(A) produces a basis for the subspace of Eucldiean n-space \n% spanned by the vectors {u1,u2,...}, where the matrix A is formed from \n% these vectors as its columns. That is, the subspace is the column space \n% of A. The columns of the matrix that is returned are the basis vectors \n% for the subspace. These basis vectors will be a subset of the original \n% vectors. An error is returned if a basis for the zero vector space is \n% attempted to be produced.\n%\n% For example, if the vector space V = span{u1,u2,...}, where u1,u2,... are\n% row vectors, then set A to be [u1' u2' ...].\n%\n% For example, if the vector space V = Col(B), where B is an m x n matrix,\n% then set A to be equal to B.\n\nmatrix_size = size(A);\n\nm = matrix_size(1,1);\nn = matrix_size(1,2);\n\nif A == zeros(m,n)\n error('There does not exist a basis for the zero vector space.');\nelseif n == 1\n basis = A;\nelse\n flag = 0;\n\n if n == 2\n multiple = A(1,2)/A(1,1);\n count = 0;\n \n for i = 1:m\n if A(i,2)/A(i,1) == multiple\n count = count + 1;\n end\n end\n \n if count == m\n basis = A(1:m,1);\n flag = 1;\n end\n end\n\n if flag == 0\n [ref_A pivot_columns] = ref(A);\n\n for i = 1:size(pivot_columns,2)\n B(1:m,i) = A(1:m,pivot_columns(1,i));\n end\n\n basis = B;\n end\nend", "meta": {"author": "xiuyechen", "repo": "FishExplorer", "sha": "c61392cf0835480d64fc03c15f1992935fdc7106", "save_path": "github-repos/MATLAB/xiuyechen-FishExplorer", "path": "github-repos/MATLAB/xiuyechen-FishExplorer/FishExplorer-c61392cf0835480d64fc03c15f1992935fdc7106/ref functions/Gram-Schmidt Process/basis_col.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750400464604, "lm_q2_score": 0.8705972650509008, "lm_q1q2_score": 0.8299186427057363}} {"text": "function [ vX, mP ] = ApplyKalmanFilterIteration( vX, mP, vZ, hF, hH, hMf, hMh, mQ, mR )\n% ----------------------------------------------------------------------------------------------- %\n% [ vX, mP ] = ApplyKalmanFilterIteration( vX, mP, vZ, hF, hH, mQ, mR, mF, mH )\n% Applies iteration of the Kalman Filter (Prediction + Update). Supports\n% both Linear and Non Linear Mode (Extended Kalman Filter).\n% Input:\n% - vX - Input State Vector.\n% Structure: Vector (Column).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - mP - Error Covariance.\n% Structure: Matrix.\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - vZ - Measurement Vector.\n% Structure: Vector (Column).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - hF - Model Function.\n% Structure: Function Handler.\n% Type: Function Handler.\n% Range: NA.\n% - hH - Measurement Function.\n% Structure: Function Handler.\n% Type: Function Handler.\n% Range: NA.\n% - mQ - Process Noise Covariance.\n% Structure: Matrix.\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - mR - Measurement Noise Covariance.\n% Structure: Matrix.\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - hMf - Model Matrix Function.\n% Generates the matrix `mF` from the state vector vX.\n% Structure: Function Handler.\n% Type: Function Handler.\n% Range: NA.\n% - hMh - Measurement Matrix Function.\n% Generates the matrix `mH` from the state vector vX.\n% The state vector is hF(vX).\n% Structure: Function Handler.\n% Type: Function Handler.\n% Range: NA.\n% Output:\n% - vX - Updated State Vector.\n% Structure: Vector (Column).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - mP - Error Covariance.\n% Structure: Matrix.\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% References\n% 1. Extended Kalman Filter (Wikipedia) - https://en.wikipedia.org/wiki/Extended_Kalman_filter.\n% 2. Kalman Filter (Wikipedia) - https://en.wikipedia.org/wiki/Kalman_filter.\n% Remarks:\n% 1. If the Complex Mode is selected the function must return complex\n% values in order to work. For instance, if the input function is\n% 'norm(vX)' use 'sum(vX .^ 2)' and if the input function is\n% 'sum(abs(vX))' use 'sum(sqrt(vX .^ 2))'.\n% 2. This implementation use the Joseph Form of the Covariance Update.\n% While it requires more computational effort it is more stable and\n% guaranteed to generate PSD matrix.\n% TODO:\n% 1. U.\n% Release Notes:\n% - 1.1.000 25/07/2021 Royi Avital\n% * Added support for a fnction handle to calculate the matrices mF\n% and mH.\n% * Add `arguments` block.\n% * Added a step to ensure symmetry of mP.\n% - 1.0.000 22/08/2018 Royi Avital\n% * First release version.\n% ----------------------------------------------------------------------------------------------- %\n\narguments\n vX (:, 1) {mustBeNumeric, mustBeReal}\n mP (:, :) {mustBeNumeric, mustBeReal, mustBePdMatrix}\n vZ (:, 1) {mustBeNumeric, mustBeReal}\n hF (1, 1) {mustBeFunctionHandler}\n hH (1, 1) {mustBeFunctionHandler}\n hMf (1, 1) {mustBeFunctionHandler}\n hMh (1, 1) {mustBeFunctionHandler}\n mQ (:, :) {mustBeNumeric, mustBeReal, mustBePdMatrix}\n mR (:, :) {mustBeNumeric, mustBeReal, mustBePdMatrix}\nend\n\nFALSE = 0;\nTRUE = 1;\n\nOFF = 0;\nON = 1;\n\nmI = eye(size(vX, 1));\n\n% Prediction Step\nvX = hF(vX);\nmF = hMf(vX);\nmP = (mF * mP * mF.') + mQ;\n\nmH = hMh(vX);\n\n% Update Step\nvY = vZ - hH(vX);\nmS = (mH * mP * mH.') + mR;\nmK = (mP * mH.') / mS;\nvX = vX + (mK * vY);\n% Joseph Form of the Covariance Update (Numerically more stable)\nmT = mI - (mK * mH);\nmP = (mT * mP * mT.') + (mK * mR * mK.'); % 0)))\n \nelse\n errorId = 'mustBePdMatrix:notPositiveDefiniteMatrix';\n errorMsg = 'The input must be a Positive Definite Matrix';\n throwAsCaller(MException(errorId, errorMsg));\nend\n\n\nend\n\n\nfunction [ ] = mustBeFunctionHandler( hF )\n% https://www.mathworks.com/matlabcentral/answers/107552\nif(~isa(hF, 'function_handle'))\n errorId = 'mustBeFunctionHandler:notFunctionHandler';\n errorMsg = 'The input must be a Function Handler';\n throwAsCaller(MException(errorId, errorMsg));\nend\n\n\nend\n\n", "meta": {"author": "RoyiAvital", "repo": "StackExchangeCodes", "sha": "d2a934616995fa8a9f4df1ca29029402435b9e6f", "save_path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes", "path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes/StackExchangeCodes-d2a934616995fa8a9f4df1ca29029402435b9e6f/SignalProcessing/Q76443/ApplyKalmanFilterIteration.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542852576265, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.8298833848452}} {"text": "function row_new = catalan_row_next ( ido, n, row )\n\n%*****************************************************************************80\n%\n%% CATALAN_ROW computes row N of Catalan's triangle.\n%\n% Example:\n%\n% I\\J 0 1 2 3 4 5 6\n%\n% 0 1\n% 1 1 1\n% 2 1 2 2\n% 3 1 3 5 5\n% 4 1 4 9 14 14\n% 5 1 5 14 28 42 42\n% 6 1 6 20 48 90 132 132\n%\n% Recursion:\n%\n% C(0,0) = 1\n% C(I,0) = 1\n% C(I,J) = 0 for I < J\n% C(I,J) = C(I,J-1) + C(I-1,J)\n% C(I,I) is the I-th Catalan number.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 August 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer IDO, indicates whether this is a call for\n% the 'next' row of the triangle.\n% IDO = 0, this is a startup call. Row N is desired, but\n% presumably this is a first call, or row N-1 was not computed\n% on the previous call.\n% IDO = 1, this is not the first call, and row N-1 was computed\n% on the previous call. In this case, much work can be saved\n% by using the information from the previous values of IROW\n% to build the next values.\n%\n% Input, integer N, the index of the row of the triangle desired. \n%\n% Input, integer ROW(1:N), the previous row of coefficients, if \n% IDO = 1.\n%\n% Output, integer ROW_NEW(1:N+1), the next row of coefficients.\n%\n if ( n < 0 )\n row_new = [];\n return\n end\n\n if ( ido == 0 )\n \n row_new(1) = 1;\n row_new(2:n+1) = 0;\n \n for i = 1 : n\n\n row_new(1) = 1;\n\n for j = 1 : i-1\n row_new(j+1) = row_new(j+1) + row_new(j);\n end\n\n row_new(i+1) = row_new(i);\n\n end\n \n else\n\n row_new(1:n) = row(1:n);\n row_new(n+1) = 0;\n \n row_new(1) = 1;\n\n for j = 1 : n-1\n row_new(j+1) = row_new(j+1) + row_new(j);\n end\n\n if ( 1 <= n )\n row_new(n+1) = row_new(n);\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/polpak/catalan_row_next.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.9173026567597713, "lm_q1q2_score": 0.8298383392871955}} {"text": "%% Floyd algorithm\nfunction [S, P]=FloydSPR(AdjMax)\n% *INPUT:* \n% AdjMax: Adjacent matrix that represents a weighted, directed graph\n%\n% *OUTPUT:*\n% S: distance to destination node\n% P: next hop node\n%\n% *DESCRIPTION*\n% Given a input adjacent matrix (AdjMax) that represents a weighted, directed graph. \n% The function finds the shorest path from one vertex 'i' to another 'j'. \n% The return values includes a matrix (S) that denotes the shortest distance \n% between vertices 'i' and 'j', and a matrix (P) that denotes the next vertex 'k' \n% on the path from vertex 'i' to vertex 'j' \n\n\nN=min(length(AdjMax(:,1)),length(AdjMax(1,:)));\nP=-1*ones(N,N);\nS=AdjMax;\n\nfor k=1:N\n for i=1:N\n for j=1:N\n if S(i,k)==inf\n continue;\n end\n if S(k,j)==inf\n continue;\n end\n if S(i,j)>S(i,k)+S(k,j)\n if P(i,k)==-1\n P(i,j)=k; \n else\n P(i,j)=P(i,k);\n end\n S(i,j)=S(i,k)+S(k,j);\n end\n end\n end\nend\n\n%% END", "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/11549-floyd-shortest-path-routing/FloydSPR.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422269175634, "lm_q2_score": 0.8723473630627235, "lm_q1q2_score": 0.8297264135491431}} {"text": "function zp=nearestPointOnPlane(z,n,p0)\n%%NEARESTPOINTONPLANE Given a point z, determine the nearest point on the\n% plane given by the equation n'*(x-p0)=0, where n is a normal to\n% the plane, p0 is a point and x is the free variable. All\n% quantities are real.\n%\n%INPUTS: z A numDimXnumPoints set of points to project.\n% n A numDimX1 normal to the plane.\n% p0 A numDimX1 point on the plane.\n%\n%OUTPUTS: zp The numDimXnumPoints set of projections of the points in z\n% onto the plane.\n%\n%The expression for the nearest point to a plane is given in Chapter 12.1\n%of [1].\n%\n%EXAMPLE:\n% n=[1;2;3];\n% p0=[0;-1;2];\n% z=[4;4;4];\n% zp=nearestPointOnPlane(z,n,p0)\n% %One will get zp=[2.571428571428572;1.142857142857143;-0.285714285714286].\n% %It can be verified that \n% n'*(zp-p0)\n% %is zero within finite precision limits and \n% cross(n,(z-zp))\n% %is also zero within finite precision limits.\n%\n%REFERENCES:\n%[1] P. J. Schneider and D. H. Eberly, Geometric Tools for Computer\n% Graphics. Amsterdam: Morgan Kaufmann Publishers, 2003.\n%\n%April 2017 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nd=-n'*p0;\n%The equation for the plane is now:\n%x'*n+d=0;\n\nu=n/(n'*n);\n\n%For a single point z, the following line is equivalent to\n%zp=z-(z'*n+d)*u;\nzp=bsxfun(@minus,z,bsxfun(@times,sum(bsxfun(@times,z,n),1)+d,u));\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/Geometry/nearestPointOnPlane.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995703, "lm_q2_score": 0.903294206053042, "lm_q1q2_score": 0.8296578747396778}} {"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n%\n% \n% Problem 5\n% 0.9^n, 0<=n<=3\n% z-Transform computation of f[n]= 2^-n , 4<=n<=6\n% 1, 7<=n<=10\n\n\n\nn1=0:3;\nf1=0.9.^n1;\nn2=4:6;\nf2=2.^(-n2);\nn3=7:10;\nf3=ones(size(n3));\nn=[n1 n2 n3];\nf=[f1 f2 f3];\nstem(n,f);\naxis([-.5 10.5 -.1 1.1]);\n\nfigure\nsyms n z\nn1=4;\nn2=7;\nn3=11;\nf1=0.9^n;\nf2=2^(-n);\nf3=1;\nf=f1*(heaviside(n)-heaviside(n-n1)) +f2*(heaviside(n-n1)-heaviside(n-n2)) +f3*(heaviside(n-n2)-heaviside(n-n3));\nn_s=0:10;\nf_s=subs(f,n_s);\nstem(n_s,f_s);\naxis([-.5 10.5 -.1 1.1]);\n\n\n% a)z-Transform of f[n]\nF1=ztrans(f,z)\n\n% b)z-Transform of f[n]\nn1=0:3;\nf1=0.9.^n1;\nn2=4:6;\nf2=2.^(-n2);\nn3=7:10;\nf3=ones(size(n3));\nn=[n1 n2 n3];\nf=[f1 f2 f3];\nF2=sum(f.*(z.^-n))\n\n% c) confirmation\nfigure\nsyms n\nftest=iztrans(F1,n)\nn=0:10;\nftest1=subs(ftest,n);\nstem(n,ftest1);\naxis([-.5 10.5 -.1 1.1]);\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/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/10/c108c.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.924141826246517, "lm_q2_score": 0.897695298265595, "lm_q1q2_score": 0.8295977723520788}} {"text": "function v3 = r8vec_cross_product_3d ( v1, v2 )\n\n%*****************************************************************************80\n%\n%% R8VEC_CROSS_PRODUCT_3D computes the cross product of two R8VEC's in 3D.\n%\n% Discussion:\n%\n% The cross product in 3D can be regarded as the determinant of the\n% symbolic matrix:\n%\n% [ i j k ]\n% det [ x1 y1 z1 ]\n% [ x2 y2 z2 ]\n%\n% = ( y1 * z2 - z1 * y2 ) * i\n% + ( z1 * x2 - x1 * z2 ) * j\n% + ( x1 * y2 - y1 * x2 ) * k\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 31 October 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real V1(3), V2(3), the two vectors.\n%\n% Output, real V3(3), the cross product vector.\n%\n v3 = zeros ( 3, 1 );\n\n v3(1) = v1(2) * v2(3) - v1(3) * v2(2);\n v3(2) = v1(3) * v2(1) - v1(1) * v2(3);\n v3(3) = v1(1) * v2(2) - v1(2) * v2(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/r8lib/r8vec_cross_product_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342061815148, "lm_q2_score": 0.8670357718273068, "lm_q1q2_score": 0.8294360773129927}} {"text": "function H=haarmtx(n)\n\n% HAARMTX Compute Haar orthogonal transform matrix.\n%\n% H = HAARMTX(N) returns the N-by-N HAAR transform matrix. H*A\n% is the HAAR transformation of the columns of A and H'*A is the inverse\n% transformation of the columns of A (when A is N-by-N).\n% If A is square, the two-dimensional Haar transformation of A can be computed\n% as H*A*H'. This computation is sometimes faster than using\n% DCT2, especially if you are computing large number of small\n% Haar transformation, because H needs to be determined only once.\n%\n% Class Support\n% -------------\n% N is an integer scalar of class double. H is returned \n% as a matrix of class double.\n% \n% \n% I/O Spec\n% N - input must be double\n% D - output DCT transform matrix is double\n%\n% Author : Frederic Chanal (f.j.chanal@student.tue.nl) - 2004\n\n\na=1/sqrt(n);\nfor i=1:n\n H(1,i)=a;\nend\nfor k=1:n-1\n p=fix(log2(k));\n q=k-2^p+1;\n t1=n/2^p;\n sup=fix(q*t1);\n mid=fix(sup-t1/2);\n inft=fix(sup-t1);\n t2=2^(p/2)*a;\n for j=1:inft\n H(k+1,j)=0;\n end\n for j=inft+1:mid\n H(k+1,j)=t2;\n end\n for j=mid+1:sup\n H(k+1,j)=-t2;\n end\n for j=sup+1:n\n H(k+1,j)=0;\n end\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/41333-simulation-of-dct-walsh-hadamard-haar-and-slant-transform-using-variable-block-sizes/haarmtx.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.941654159388319, "lm_q2_score": 0.8807970779778824, "lm_q1q2_score": 0.8294062320549506}} {"text": "function value = mono_upto_enum ( m, n )\n\n%*****************************************************************************80\n%\n%% MONO_UPTO_ENUM enumerates monomials in M dimensions of degree up to N.\n%\n% Discussion:\n%\n% For M = 2, we have the following values:\n%\n% N VALUE\n%\n% 0 1\n% 1 3\n% 2 6\n% 3 10\n% 4 15\n% 5 21\n%\n% In particular, VALUE(2,3) = 10 because we have the 10 monomials:\n%\n% 1, x, y, x^2, xy, y^2, x^3, x^2y, xy^2, y^3.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 09 September 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, the spatial dimension.\n%\n% Input, integer N, the maximum degree.\n%\n% Output, integer VALUE, the number of monomials in D variables,\n% of total degree N or less.\n%\n value = nchoosek ( n + m, 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/monomial/mono_upto_enum.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088084787998, "lm_q2_score": 0.8933093954028816, "lm_q1q2_score": 0.8293563113889063}} {"text": "function [Theta, k] = estimate_plane(X, s)\n\n% [Theta k] = estimate_plane(X)\n%\n% DESC:\n% estimate the parameters of a 3D plane given the pairs [x, y, z]^T\n% Theta = [a; b; c; d] where:\n%\n% a*x1+b*y1+c*z1+d = 0\n% a*x2+b*y2+c*z2+d = 0\n% a*x3+b*y3+c*z3+d = 0\n%\n% AUTHOR\n% Marco Zuliani - marco.zuliani@gmail.com\n%\n% VERSION:\n% 1.0.0\n%\n% INPUT:\n% X = 3D points \n% s = indices of the points used to estimate the parameter\n% vector. If empty all the points are used\n%\n% OUTPUT:\n% Theta = estimated parameter vector Theta = [a; b; c; d]\n% k = dimension of the minimal subset\n\n% HISTORY:\n% 1.0.0 = 07/05/08 - initial version\n\n% cardinality of the MSS\nk = 3;\n\nif (nargin == 0) || isempty(X)\n Theta = [];\n return;\nend;\n\nif (nargin == 2) && ~isempty(s)\n X = X(:, s);\nend;\n\n% check if we have enough points\nN = size(X, 2);\nif (N < k)\n error('estimate_plane:inputError', ...\n 'At least 3 points are required');\nend;\n\nA = [transpose(X(1, :)) transpose(X(2, :)) transpose(X(3, :)) ones(N, 1)];\n[U S V] = svd(A);\nTheta = V(:, 4);\n\nreturn;\n", "meta": {"author": "RANSAC", "repo": "RANSAC-Toolbox", "sha": "c08308bf61aaf669b00533409cb0daaa10c000aa", "save_path": "github-repos/MATLAB/RANSAC-RANSAC-Toolbox", "path": "github-repos/MATLAB/RANSAC-RANSAC-Toolbox/RANSAC-Toolbox-c08308bf61aaf669b00533409cb0daaa10c000aa/Models/Plane/estimate_plane.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475715065793, "lm_q2_score": 0.879146761176671, "lm_q1q2_score": 0.8293409621538873}} {"text": "function h_new = fd1d_heat_explicit ( x_num, x, t, dt, cfl, rhs, bc, h )\n\n%*****************************************************************************80\n%\n%% FD1D_HEAT_EXPLICIT: Finite difference solution of 1D heat equation.\n%\n% Discussion:\n%\n% This program takes one time step to solve the 1D heat equation \n% with an explicit method.\n%\n% This program solves\n%\n% dUdT - k * d2UdX2 = F(X,T)\n%\n% over the interval [A,B] with boundary conditions\n%\n% U(A,T) = UA(T),\n% U(B,T) = UB(T),\n%\n% over the time interval [T0,T1] with initial conditions\n%\n% U(X,T0) = U0(X)\n%\n% The code uses the finite difference method to approximate the\n% second derivative in space, and an explicit forward Euler approximation\n% to the first derivative in time.\n%\n% The finite difference form can be written as\n%\n% U(X,T+dt) - U(X,T) ( U(X-dx,T) - 2 U(X,T) + U(X+dx,T) )\n% ------------------ = F(X,T) + k * ------------------------------------\n% dt dx * dx\n%\n% or, assuming we have solved for all values of U at time T, we have\n%\n% U(X,T+dt) = U(X,T) + cfl * ( U(X-dx,T) - 2 U(X,T) + U(X+dx,T) ) + dt * F(X,T) \n%\n% Here \"cfl\" is the Courant-Friedrichs-Loewy coefficient:\n%\n% cfl = k * dt / dx / dx\n%\n% In order for accurate results to be computed by this explicit method,\n% the CFL coefficient must be less than 0.5!\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 31 January 2012\n%\n% Author:\n% \n% John Burkardt\n%\n% Reference:\n%\n% George Lindfield, John Penny,\n% Numerical Methods Using MATLAB,\n% Second Edition,\n% Prentice Hall, 1999,\n% ISBN: 0-13-012641-1,\n% LC: QA297.P45.\n%\n% Parameters:\n%\n% Input, integer X_NUM, the number of points to use in the spatial dimension.\n%\n% Input, real X(X_NUM,1), the coordinates of the nodes.\n%\n% Input, real T, the current time.\n%\n% Input, real DT, the size of the time step.\n%\n% Input, real CFL, the Courant-Friedrichs-Loewy coefficient,\n% computed by FD1D_HEAT_EXPLICIT_CFL.\n%\n% Input, real H(X_NUM,1), the solution at the current time.\n%\n% Input, @RHS, the function which evaluates the right hand side.\n%\n% Input, @BC, the function which evaluates the boundary conditions.\n%\n% Output, real H_NEW(X_NUM,1), the solution at time T+DT.\n%\n h_new = zeros(x_num,1);\n\n L = 1 : x_num - 2;\n C = 2 : x_num - 1;\n R = 3 : x_num;\n\n f = rhs ( x_num, x, t );\n\n h_new(C) = h(C) + cfl * ( h(L) - 2.0 * h(C) + h(R) ) + dt * f(C);\n\n h_new = bc ( x_num, x, t + dt, h_new );\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/fd1d_heat_explicit/fd1d_heat_explicit.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.8962513738264114, "lm_q1q2_score": 0.829238621996901}} {"text": "function [feven,fodd] = filterGabor1d( r, sig, omega, show )\n% Creates an even/odd pair of 1D Gabor filters.\n%\n% USAGE\n% [feven,fodd] = filterGabor1d( r, sig, omega, [show] )\n%\n% INPUTS\n% r - final filter will be 2r+1 (good choice for r is r=2*sig)\n% sig - standard deviation of Gaussian mask\n% omega - frequency of underlying sine/cosine in [1/(2r+1) r/(2r+1)]\n% show - [0] figure to use for optional display\n%\n% OUTPUTS\n% feven - even symmetric filter (-cosine masked with Gaussian)\n% fodd - odd symmetric filter (-sine masked with Gaussian)\n%\n% EXAMPLE\n% sig = 15; f=filterGabor1d(2*sig,sig,1/sig,1);\n%\n% See also FILTERGABOR2D\n%\n% Piotr's Image&Video Toolbox Version 2.0\n% Copyright 2012 Piotr Dollar. [pdollar-at-caltech.edu]\n% Please email me if you find bugs, or have suggestions or questions!\n% Licensed under the Simplified BSD License [see external/bsd.txt]\n\nif( nargin<4 || isempty(show) ); show=0; end;\n\nr = ceil(r); n=2*r+1;\nif( omega<1/(n) || omega>r/(n) )\n error(['omega=' num2str(omega) ' out of range =[' num2str([1 r]/n) ']']);\nend;\n\n% create even and odd pair\nx = -r:r;\nfeven = -cos(2*pi*x*omega) .* exp(-(x.^2)/sig^2);\nfodd = -sin(2*pi*x*omega) .* exp(-(x.^2)/sig^2); %=imag(hilbert(feven));\n\n% normalize to mean==0, but only in locs that are nonzero\ninds = abs(feven)>.00001; feven(inds) = feven(inds) - mean(feven(inds));\ninds = abs(fodd)>.00001; fodd(inds) = fodd(inds) - mean(fodd(inds));\n\n% set L1norm to 0\nfeven = feven/norm(feven(:),1);\nfodd = fodd/norm(fodd(:),1);\n\n% visualization\nif( show )\n filterVisualize( feven, show );\n filterVisualize( fodd, show+1 );\nend\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/Toolbox/SketchTokens-master/toolbox/filters/filterGabor1d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.900529795461386, "lm_q1q2_score": 0.8291985384930561}} {"text": "function sig=sigmerge(x1,x2,ratio);\n%SIGMERGE Add two signals with given energy ratio in dB.\n%\tSIG=SIGMERGE(X1,X2,RATIO) adds two signals so that a given\n%\tenergy ratio expressed in deciBels is satisfied.\n% \n%\tX1, X2 : input signals.\n%\tRATIO : Energy ratio in deciBels\t(default : 0 dB).\n%\tX : output signal.\n%\tX= X1+H*X2, such that 10*log(Energy(X1)/Energy(H*X2))=RATIO\n%\n%\tExample : \n%\t sig=fmlin(64,0.01,0.05,1); noise=hilbert(randn(64,1));\n%\t SNR=15; x=sigmerge(sig,noise,SNR);\n%\t Esig=mean(abs(sig).^2); Enoise=mean(abs(x-sig).^2);\n%\t 10*log10(Esig/Enoise)\n\n%\tF. Auger, July 1995.\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 (nargin<2)\n error('At least two parameters are required');\nelseif nargin==2,\n ratio=0;\nend;\n\n[x1row,x1col] = size(x1);\n[x2row,x2col] = size(x2);\n\nif (x1col~=1)|(x2col~=1),\n error('X1 and X2 must have only one column');\nelseif (x1row~=x2row),\n error('X1 and X2 must have the same number of rows');\nelseif (length(ratio)~=1),\n error('RATIO must be a scalar');\nelseif (ratio==inf),\n sig = x1;\nelse\n Ex1=mean(abs(x1).^2);\n Ex2=mean(abs(x2).^2);\n h=sqrt(Ex1/(Ex2*10^(ratio/10)));\n sig=x1+h*x2;\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/sigmerge.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951570602081, "lm_q2_score": 0.8872045981907006, "lm_q1q2_score": 0.8289996798709386}} {"text": "function density = calc_packing_density(dim,N,min_euclidean_dist)\n%CALC_PACKING_DENSITY Density of packing given by minimum distance\n%\n%Syntax\n% density = calc_packing_density(dim,N,min_euclidean_dist);\n%\n%Description\n% DENSITY = CALC_PACKING_DENSITY(dim,N,MIN_EUCLIDEAN_DIST) sets DENSITY to\n% be the density of a packing of S^dim by N equal spherical caps with centers\n% having minimum Euclidean distance MIN_EUCLIDEAN_DIST.\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 argument MIN_EUCLIDEAN_DIST must be an array of real nubers of the same array size as N.\n% The result DENSITY will be an array of the same size as N.\n%\n%Notes\n% The packing density is defined to be the sum of the areas of the spherical\n% caps of the packing, divided by the area of the unit sphere S^dim.\n%\n% The spherical radius of the caps in the packing is half the minimum spherical\n% distance between center points. The spherical radius for N == 1 is a special\n% case. It is defined to be pi.\n%\n%Examples\n% > N=2:6\n% N =\n% 2 3 4 5 6\n%\n% > dist=eq_min_dist(2,N)\n% dist =\n% 2.0000 1.4142 1.4142 1.4142 1.4142\n%\n% > calc_packing_density(2,N,dist)\n% ans =\n% 1.0000 0.4393 0.5858 0.7322 0.8787\n%\n%See also\n% EQ_MIN_DIST, AREA_OF_CAP, AREA_OF_SPHERE, EQ_PACKING_DENSITY\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.10 $ $Date 2005-05-27 $\n% Function e2s changed name to euc2sph_dist\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(3,3,nargin));\n%\ns_cap = euc2sph_dist(min_euclidean_dist)/2;\n%\n% The spherical radius for N == 1 is a special case. It is pi.\n%\ns_cap(N == 1) = pi;\ndensity = N.*area_of_cap(dim, s_cap)./area_of_sphere(dim);\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_point_set_props/calc_packing_density.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.9046505318875316, "lm_q1q2_score": 0.8287590512729539}} {"text": "% Derive_pwPoly5.m\n%\n% This script derives the equations that give the bezier coefficients for a\n% curve, given the value, slope, and curvature at each endpoint.\n%\n\nclc; clear;\n\n% Control Points:\nn = 5; %order of bezier curve\np = sym('p',[n+1,1]); assume(p,'real');\n\n% Independent variable:\nsyms t 'real'\n\n% Build up the equation for a 5th-order bezier curve:\nx = sym(0);\nfor i=0:n\n tt = (t.^i).*(1-t).^(n-i);\n binom = nchoosek(n,i);\n x = x + binom*p(i+1)*tt;\nend\n\n% Now compute the derivaives:\ndx = diff(x,t);\nddx = diff(dx,t);\n\n% Evaluate at endpoints:\nX0 = simplify(subs(x,t,0));\ndX0 = simplify(subs(dx,t,0));\nddX0 = simplify(subs(ddx,t,0));\nX1 = simplify(subs(x,t,1));\ndX1 = simplify(subs(dx,t,1));\nddX1 = simplify(subs(ddx,t,1));\n\n% User-Inputs:\nsyms x0 dx0 ddx0 x1 dx1 ddx1 'real'\n\n% Constraint equations:\neqns = [...\n X0-x0;\n dX0-dx0;\n ddX0-ddx0;\n X1-x1;\n dX1-dx1;\n ddX1-ddx1];\n \n% Solve for unknowns\n[A,b] = equationsToMatrix(eqns,p);\npSoln = A\\b;\n\n% Substitute solution:\nxSoln = simplify(subs(x,p,pSoln));\ndxSoln = simplify(subs(dx,p,pSoln));\nddxSoln = simplify(subs(ddx,p,pSoln));\n\n% Write solution to a matlab function:\nmatlabFunction(xSoln, dxSoln, ddxSoln,...\n 'file','autoGen_pwPoly5.m',...\n 'vars',{t,x0 dx0 ddx0 x1 dx1 ddx1},...\n 'outputs',{'x','dx','ddx'});\n\n\n\n\n", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/pwPoly/Derive_pwPoly5.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620550745212, "lm_q2_score": 0.8633916134888613, "lm_q1q2_score": 0.8286505092961762}} {"text": "function area = sphere_cap_area_3d ( r, h )\n\n%*****************************************************************************80\n%\n%% SPHERE_CAP_AREA_3D computes the surface area of a spherical cap in 3D.\n%\n% Discussion:\n%\n% Draw any radius of the sphere and note the point P where the radius\n% intersects the sphere. Consider the point on the radius line which is\n% H units from P. Draw the circle that lies in the plane perpendicular to\n% the radius, and which intersects the sphere. The circle divides the sphere\n% into two pieces, and the corresponding disk divides the solid sphere into\n% two pieces. The spherical cap is the part of the solid sphere that\n% includes the point P.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 February 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R, the radius of the sphere.\n%\n% Input, real H, the \"height\" of the spherical cap. \n% H must be between 0 and 2 * R.\n%\n% Output, real AREA, the area of the spherical cap.\n%\n if ( h <= 0.0 )\n area = 0.0;\n elseif ( 2.0 * r <= h )\n area = 4.0 * pi * r * r;\n else\n area = 2.0 * pi * r * h;\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/sphere_cap_area_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506726044381, "lm_q2_score": 0.8791467564270271, "lm_q1q2_score": 0.8286017311125742}} {"text": "function result=L1median(x,tol);\n\n%L1MEDIAN is an orthogonally equivariant location estimator,\n% also known as the spatial median. It is defined as the point which\n% minimizes the sum of the Euclidean distances to all observations in the\n% data matrix x. It can resist 50% outliers. \n%\n% Reference (for the algorithm): \n% Hossjer, O. and Croux, C. (1995)\n% \"Generalizing univariate signed rank statistics for testing and estimating \n% a multivariate location parameter\", Nonparametric Statistics, 4, 293-308.\n%\n% Required input argument:\n% x : either a data matrix with n observations in rows, p variables in columns\n% or a vector of length n.\n%\n% Optional input argument:\n% tol : convergence criterium; the iterative process stops when the norm between two solutions < tol.\n% (default = 1.e-08).\n%\n% I/O: result=L1median(x,tol);\n%\n% This function is part of LIBRA: the Matlab Library for Robust Analysis,\n% available at: \n% http://wis.kuleuven.be/stat/robust.html\n%\n% Original Gauss code by C. Croux, translated to MATLAB by Sabine Verboven\n% Last updated 18/02/2004\n\nif nargin <2\n tol=1.e-08;\nend;\n[n,p]=size(x);\nmaxstep=200;\n%initializing starting value for m\nm=median(x);\nk=1;\nwhile (k<=maxstep)\n mold=m;\n Xext=sortrows([norme(x-repmat(m,n,1)) x],1);\n dx=Xext(:,1);\n x=Xext(:,2:p+1);\n if all(dx)\n w=1./dx;\n else\n ww=dx(all(dx,2));\n w=1./ww;\n w=[zeros(length(dx)-length(w),1);w];\n end\n delta=sum((x-repmat(m,n,1)).*repmat(w,1,p),1)./sum(w);\n nd=norme(delta);\n if all(nd=mrobj(x,mold))&(nstep<=maxhalf)\n nstep=nstep+1;\n m=mold+delta./(2^nstep);\n end\n if (nstep>maxhalf)\n mX=mold;\n break\n end\n k=k+1;\nend\nif k>maxstep\n display('Iteration failed')\nend\nresult=m;\n\n%------------------------------------------------------------------\nfunction n=norme(x);\n\n%NORME calculates the Euclidian norm of a matrix x\n% the output is a column vector containing the norm of each row\n% I/O: n=norme(X);\n\nfor i=1:size(x,1)\n n(i)=norm(x(i,:));\nend;\nn=n';\n\n%------------------------------------------------------------------\nfunction s=mrobj(x,m)\n\n%MROBJ computes the objective function in m based on x and a\n\nxm=norme(x-repmat(m,size(x,1),1));\ns=sum(xm,1)';\n\n", "meta": {"author": "marianux", "repo": "ecg-kit", "sha": "c8e3de47c54a9214138143676d2aa546b0540dd2", "save_path": "github-repos/MATLAB/marianux-ecg-kit", "path": "github-repos/MATLAB/marianux-ecg-kit/ecg-kit-c8e3de47c54a9214138143676d2aa546b0540dd2/common/LIBRA/l1median.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029486, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.8285311634664531}} {"text": "function area = sphere_cap_area_3d ( r, h )\n\n%*****************************************************************************80\n%\n%% SPHERE_CAP_AREA_3D computes the surface area of a spherical cap in 3D.\n%\n% Discussion:\n%\n% Draw any radius of the sphere and note the point P where the radius\n% intersects the sphere. Consider the point on the radius line which is\n% H units from P. Draw the circle that lies in the plane perpendicular to\n% the radius, and which intersects the sphere. The circle divides the sphere\n% into two pieces, and the corresponding disk divides the solid sphere into\n% two pieces. The spherical cap is the part of the solid sphere that\n% includes the point P.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 02 April 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R, the radius of the sphere.\n%\n% Input, real H, the \"height\" of the spherical cap. \n%\n% Output, real AREA, the area of the spherical cap.\n%\n if ( h <= 0.0 )\n area = 0.0;\n elseif ( 2.0 * r <= h )\n area = 4.0 * pi * r * r;\n else\n area = 2.0 * pi * r * h;\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/stroud/sphere_cap_area_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768651485395, "lm_q2_score": 0.8774767922879693, "lm_q1q2_score": 0.8284932869830509}} {"text": "function x = chebyshev1 ( n )\n\n%*****************************************************************************80\n%\n%% CHEBYSHEV1 returns the Type 1 Chebyshev points.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 March 2018\n%\n% Author:\n%\n% John Burkardt.\n%\n% Parameters:\n%\n% Input, integer N, the number of points.\n%\n% Input, real X(N), the points.\n%\n x(1:n) = cos ( ( 2.0 * (0:n-1) + 1.0 ) * pi / 2 / 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/lebesgue/chebyshev1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.944176863577751, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.8284932735038261}} {"text": "% Derive_acrobot.m\n%\n% This script derives the equations of motion for the simple acrobot robot:\n% a double pendulum with a motor at the elbow joint. \n%\n\nsyms q1 q2 dq1 dq2 ddq1 ddq2 'real' % states\nsyms u 'real' % actuation\nsyms m1 m2 g l1 l2 'real' % physical parameters\n\n%%%% Unit vectors:\ni = sym([1;0]);\nj = sym([0;1]);\n\ne1 = cos(q1)*(-j) + sin(q1)*(i); % shoulder -> elbow\ne2 = cos(q2)*(-j) + sin(q2)*(i); % elbow -> wrist\n\n%%%% State vectors:\nz = [q1;q2;dq1;dq2];\ndz = [dq1;dq2;ddq1;ddq2];\n\n%%%% Kinematics:\np1 = l1*e1;\np2 = p1 + l2*e2;\n\ndp1 = jacobian(p1,z)*dz; %Chain rule to get velocity of elbow joint\ndp2 = jacobian(p2,z)*dz; \n\nddp1 = jacobian(dp1,z)*dz; \nddp2 = jacobian(dp2,z)*dz; \n\n%%%% Define a function for doing '2d' cross product: dot(a x b, k)\ncross2d = @(a,b)(a(1)*b(2) - a(2)*b(1));\n\n%%%% Angular momentum balance of system about shoulder joint:\nsumTorques1 = cross2d(p1,-m1*g*j) + cross2d(p2,-m2*g*j);\nsumInertial1 = cross2d(p1,m1*ddp1) + cross2d(p2,m2*ddp2);\neqn1 = sumTorques1-sumInertial1;\n\n%%%% Angular momentum balance of outer link about elbow joint:\nsumTorques2 = cross2d(p2-p1,-m2*g*j) + u;\nsumInertial2 = cross2d(p2-p1,m2*ddp2);\neqn2 = sumTorques2-sumInertial2;\n\n%%%% Write out dynamics in matrix form: MM*ddq = ff\nddq = [ddq1;ddq2];\neqns = [eqn1;eqn2];\n[MM,ff] = equationsToMatrix(eqns,ddq); \n\n%%%% Generate an optimized matlab function for dynamics:\nmatlabFunction(MM(1,1),MM(1,2),MM(2,1),MM(2,2),ff(1),ff(2),G,B,...\n 'file','autoGen_acrobotDynamics.m',...\n 'vars',{q1,q2,dq1,dq2,u,m1,m2,g,l1,l2},...\n 'outputs',{'M11','M12','M21','M22','f1','f2'});\n\n%%%% Compute the energy of the system:\nU = m1*g*dot(p1,j) + m2*g*dot(p2,j); %Potential Energy\nT = 0.5*m1*dot(dp1,dp1) + 0.5*m2*dot(dp2,dp2); %Kinetic Energy\n\n%%%% Generate an optimized matlab function for energy:\nmatlabFunction(U,T,...\n 'file','autoGen_acrobotEnergy.m',...\n 'vars',{q1,q2,dq1,dq2,m1,m2,g,l1,l2},...\n 'outputs',{'U','T'});\n\n%%%% Generate a function for computing the kinematics:\nmatlabFunction(p1,p2,dp1,dp2,...\n 'file','autoGen_acrobotKinematics.m',...\n 'vars',{q1,q2,dq1,dq2,l1,l2},...\n 'outputs',{'p1','p2','dp1','dp2'});", "meta": {"author": "MatthewPeterKelly", "repo": "OptimTraj", "sha": "c97b57fda511dacc6a6187f683428f0f3a1965f2", "save_path": "github-repos/MATLAB/MatthewPeterKelly-OptimTraj", "path": "github-repos/MATLAB/MatthewPeterKelly-OptimTraj/OptimTraj-c97b57fda511dacc6a6187f683428f0f3a1965f2/demo/acrobot/Derive_acrobot.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693674025232, "lm_q2_score": 0.8723473879530491, "lm_q1q2_score": 0.8284415920726156}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% polint1.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% function [g,G] = polint1(x,f)\n% quadratic polynomial interpolation\n% Input:\n% x(1:3) 3 pairwise distinct support points\n% f(1:3) corresponding function values\n% Output:\n% g, G\n% the interpolating polynomial is given by\n% p(x) = f(1) + g(x - x(1)) + G/2(x - x(1))^2\n\nfunction [g,G] = polint1(x,f)\nf13 = (f(3)-f(1))/(x(3)-x(1));\nf12 = (f(2)-f(1))/(x(2)-x(1));\nf23 = (f(3)-f(2))/(x(3)-x(2));\ng = f13 + f12 - f23;\nG = 2*(f13-f12)/(x(3)-x(2));\n", "meta": {"author": "lacerbi", "repo": "optimviz", "sha": "2cc41c19ffeaaa9a23239f53d80691cf3599357d", "save_path": "github-repos/MATLAB/lacerbi-optimviz", "path": "github-repos/MATLAB/lacerbi-optimviz/optimviz-2cc41c19ffeaaa9a23239f53d80691cf3599357d/utils/mcs/private/polint1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693702514737, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.8284415866786974}} {"text": "%% 2D Laplace Equation\n% This program solves the following PDE:\n%\n% $$\\frac{\\partial^2{T}}{\\partial{x^2}}+\\frac{\\partial^2{T}}{\\partial{y^2}}=0$$\n\nclear\nclc\nclose all\n\n%% Discretization of space\n% Length and heigth of our 2D domain:\nL = 1; % length in x direction\nH = 1; % height in y direction\n\n% our target is to evaluate the step h size, thus\nh = 0.05; % we asume and equally spaced XY grid\nhx = h;\nhy = h; \n\n% number of points\nn = round(L/hx);\nm = round(H/hy);\n\n% initaliza Matriz T\nT=zeros(n+1,m+1);\n\n%% Boundary Contidions\n% Our domain requires 4 boudary conditions in total, can be only nuemann, \n% or only dirichlet or a combination of both.\n\n%% Nuemann Boundary Conditions (Prescribed values at the borders)\n% Bottom (last row of the matrix)\nT(1,:)=0;\n% Top (first row of the matrix)\n%T(1,:)=1;\nfor i=0:n\n %using function of x to prescribe the values.\n T(m+1,i+1)=1-cos(pi/(n)*i); \nend\n% Left\n%T(:,1)=0;\n% Right\n%T(:,n+1)=2;\n\n%T\n\n% Vector of Prescribed Bondary Values\n% Bottom\nfb=(T(1,2:n)).' ; %transpose this array\n% Top\nft=T(m+1,2:n).' ; %transpose this array\n% Left\nfl=T(2:n,1);\n% Right\nfr=T(2:n,n+1);\n\n% Computing vector of known values\nfs=zeros(n-1,1);\nfs(1)=fl(1);\nfs(n-1)=fr(1);\nw=fb+fs;\nfor i=2:n-2\n fs(1)=fl(i);\n fs(n-1)=fr(i);\n w=cat(1,w,fs);\nend\nfs=zeros(n-1,1);\nfs(1)=fl(n-1);\nfs(n-1)=fr(n-1);\ny=ft+fs;\nw=cat(1,w,y);\n\n%% Dirichlect Boundary Conditions (flux at the borders of the domain)\n% This conditions requires de mofification of the diagonal values of our\n% solution matrix:\n\n% Bottom (last row of the matrix)\n%sb=ones(n-1,1); % to insulate this boundary\nsb=zeros(n-1,1); %to suppres this condition\n% Top (first row of the matrix)\n%st=ones(n-1,1); % to insulate this boundary\nst=zeros(n-1,1); %to suppres this condition\n% Left\nsl=zeros(m-1,1); \nsl(1)=1; % to insulate this boundary\n% Right\nsr=zeros(m-1,1);\nsr(m-1)=1; % to insulate this boundary\n\n% Computing the diagonal matrix to substract\ns=sl+sr; %sum condition in the right and left\nstt=st+s; %sum condition of the top and sides\nsbb=sb+s; %sum condition of the bottom and sides\nu=cat(1,s,s);\nfor i=4:n-2\n u=cat(1,u,s);\nend\nz=cat(1,stt,u);\nz=cat(1,z,sbb);\nZ=spdiags(z,0,length(z),length(z)); %transforms the vector in a diagonal mat.\n%spy(Z)\n\n%% System Solution\n% Our solution has the shape: \n%\n% $$ A_{ij}u_j=f_i $$\n\n% Formulating A:\nI=eye(m-1);\ne=ones(m-1,1);\nK=spdiags([e,-4*e,e],[-1,0,1],m-1,m-1);\nS=spdiags([e,e],[-1,1],m-1,m-1);\nA=(kron(I,K)+kron(S,I)); \nA=(A+Z); %(for flux conditions)\nu=inv(A)*(-w);\nspy(A)\n\n%% Re-arranging the data in vector u\n\nfor j=1:n-1\n for i=1:n-1\n t(j,i)=u(i+(n-1)*(j-1));\n end\nend\nfor j=1:n-1\n for i=1:n-1\n T(i+1,j+1)=t(i,j);\n end\nend\n\n% Make up for the plot\nif sum(sb)>=1\n T(1,:)=T(2,:);\nend\nif sum(st)>=1\n T(n+1,:)=T(n,:);\nend\nif sum(sl)>=1\n T(:,1)=T(:,2);\nend\nif sum(sr)>=1\n T(:,n+1)=T(:,n);\nend\n%T\n%surf(T)\ncontourf(T)\ncolormap hot\ncolorbar('location','southoutside')\n\n%% Computing the Error of our aproximation\n% % The exact solution of our problem is given by:\n% %\n% % $$ T(x,y)=y-\\frac{sinh(\\pi y))}{sinh(\\pi)}cos(\\pi x) $$\n% for j=1:m+1\n% for i=1:n+1\n% T2(j,i)=j/(m+1)-sinh(pi/(m+1)*j)/sinh(pi)*cos(pi/(n+1)*i);\n% end\n% end\n% Error=T2-T;\n% %T2\n% h\n% NormError=norm(Error)\n% %surf(T2)\n% contourf(T2)\n% colormap hot\n% colorbar('location','southoutside')\n\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/Eliptic/Laplace2D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693702514736, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.8284415866786973}} {"text": "function a = borderband ( n )\n\n%*****************************************************************************80\n%\n%% BORDERBAND returns the BORDERBAND matrix.\n%\n% Formula:\n%\n% If ( I = J )\n% A(I,I) = 1\n% else if ( I = N )\n% A(N,J) = 2^(1-J)\n% else if ( J = N )\n% A(I,N) = 2^(1-I)\n% else\n% A(I,J) = 0\n%\n% Example:\n%\n% N = 5\n%\n% 1 0 0 0 1\n% 0 1 0 0 1/2\n% 0 0 1 0 1/4\n% 0 0 0 1 1/8\n% 1 1/2 1/4 1/8 1\n%\n% Properties:\n%\n% A is symmetric: A' = A.\n%\n% A is border-banded.\n%\n% A has N-2 eigenvalues of 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 September 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Output, real A(N,N), the matrix.\n%\n a = zeros ( n, n );\n\n for i = 1 : n\n\n for j = 1 : n\n\n if ( i == j )\n a(i,j) = 1.0;\n elseif ( j == n )\n a(i,j) = 2.0^(1-i);\n elseif ( i == n )\n a(i,j) = 2.0^(1-j);\n else\n a(i,j) = 0.0;\n end\n\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/borderband.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.8933094124452287, "lm_q1q2_score": 0.8284223589641174}} {"text": "function alpha = anglePoints3d(varargin)\n%ANGLEPOINTS3D Compute angle between three 3D points\n%\n% ALPHA = anglePoints3d(P1, P2)\n% Computes angle (P1, O, P2), in radians, between 0 and PI.\n%\n% ALPHA = anglePoints3d(P1, P2, P3)\n% Computes angle (P1, P2, P3), in radians, between 0 and PI.\n%\n% ALPHA = anglePoints3d(PTS)\n% PTS is a 3x3 or 2x3 array containing coordinate of points.\n%\n% See also\n% points3d, angles3d\n%\n% ---------\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 21/02/2005.\n%\n\n% HISTORY\n% 20/09/2005: add case of single argument for all points\n% 04/01/2007: check typo\n% 27/05/2014: adjust known vector sizes n1, n0, n2 once corrected for\n\n\np2 = [0 0 0];\nif length(varargin) == 1\n pts = varargin{1};\n if size(pts, 1)==2\n p1 = pts(1,:);\n p0 = [0 0 0];\n p2 = pts(2,:);\n else\n p1 = pts(1,:);\n p0 = pts(2,:);\n p2 = pts(3,:);\n end\n \nelseif length(varargin) == 2\n p1 = varargin{1};\n p0 = [0 0 0];\n p2 = varargin{2};\n \nelseif length(varargin) == 3\n p1 = varargin{1};\n p0 = varargin{2};\n p2 = varargin{3};\nend\n\n% ensure all data have same size\nn1 = size(p1, 1);\nn2 = size(p2, 1);\nn0 = size(p0, 1);\n\nif n1 ~= n0\n if n1 == 1\n p1 = repmat(p1, [n0 1]);\n n1 = n0;\n elseif n0==1\n p0 = repmat(p0, [n1 1]);\n else\n error('Arguments P1 and P0 must have the same size');\n end\nend\n\nif n1 ~= n2\n if n1 == 1\n p1 = repmat(p1, [n2 1]);\n elseif n2 == 1\n p2 = repmat(p2, [n1 1]);\n else\n error('Arguments P1 and P2 must have the same size');\n end\nend\n\n% normalized vectors\np1 = normalizeVector3d(p1 - p0);\np2 = normalizeVector3d(p2 - p0);\n\n% compute angle\nalpha = acos(dot(p1, p2, 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/anglePoints3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242073, "lm_q2_score": 0.8933094117351309, "lm_q1q2_score": 0.8284223547189564}} {"text": "%% DEMOHESSIAN Short demonstration of Hessians\n%\n\n%% Some sample applications of the Hessian toolbox\n% Hessians implement second order automatic differentiation in forward mode, which is\n% conveniently to implement using the Matlab operator concept.\n%\n\nformat compact long infsup\nsetround(0) % set rounding to nearest\n\n%% Initialization of Hessians\n% The initialization follows the same principles as for gradients, for example\n\nx = hessianinit([ -.3 ; pi ])\n\n%% Access of the Hessian\n% Define the function f: R^n->R^n by\n\nf = @(x)( 3*x(1)*x + sin(x).*(sec(x)-sqrt(x)) )\n\n%%\n% The number of unknowns is determined by the length of the input vector x.\n% For example,\n\nf(1:4)\n\n%%\n% The function can be evaluated using the Hessian package as follows:\n\ny = f(hessianinit([1.1 -2.7 pi]'));\n\n%%\n% There is direct access of the Hessian of y=f(x) by\n\ny.hx\n\n%%\n% However, y.hx contains the Hessians of all three component functions of\n% the original function f. To access the Hessians it is recommended to\n% use the Hessian of individual components, not components of y.hx:\n\nH3 = y(3).hx\n\n%%\n% The matrix H3 is the Hessian of the third component function of f at x.\n\n%% A simple example\n% Consider the following function\n \nf = inline(' sin(x-log(x+2))-x*cosh(x)/15 ')\n \n%% \n% To plot the function first vectorize f :\n \nF = vectorize(f)\n \n%% \n% Plot the function including the x-axis:\n \nx = linspace(-1,3); close; plot( x,F(x), x,0*x )\n \n%% Zeros of a function\n% There are two roots near 1.5 and 2.5, and two extrema \n% near -0.5 and 2. The roots can be included by verifynlss.\n% For this simple function the inclusion is of maximum accuracy.\n \nX1 = verifynlss(f,1.5)\nX2 = verifynlss(f,2.5)\n \n%% Extrema of a function\n% The extrema can be approximated and included using Hessians.\n% The following is one step of a simple Newton iteration starting at x=-0.5 :\n \nx = -0.5; \ny = f(hessianinit(x)); \nx = x - y.hx\\y.dx';\ny\n \n%% Inclusion of extrema\n% Inclusions of the extrema of f are computed by \"verifynlss\" with \n% parameter 'h': This parameter specifies that\n% f'(x) = 0 is solved instead of f(x) = 0.\n \nX1 = verifynlss(f,-0.5,'h')\nX2 = verifynlss(f,2,'h')\n \n%% Functions in several unknowns\n% Function with several unknowns are handled in a similar manner. \n% Consider the following test function by N. Gould. It is taken from\n% the Coconut collection of test function for global optimization, \n% http://www.mat.univie.ac.at/~neum/glopt/coconut/benchmark/Library2.html .\n \nf = inline(' x(3)-1 + sqr(x(1)) + sqr(x(2)) + sqr(x(3)+x(4)) + sqr(sin(x(3))) + sqr(x(1))*sqr(x(2)) + x(4)-3 + sqr(sin(x(3))) + sqr(x(4)-1) + sqr(sqr(x(2))) + sqr(sqr(x(3)) + sqr(x(4)+x(1))) + sqr(x(1)-4 + sqr(sin(x(4))) + sqr(x(2))*sqr(x(3))) + sqr(sqr(sin(x(4)))) ')\n \n%% Approximation of an extremum\n% On the Web-site the global minimum of that function in 4 unknowns is \n% given as 5.7444 . We use a couple of a Newton iterations \n% starting at x=ones(4,1) to approximate a stationary point: \n\nformat short\nx = ones(4,1); \nfor i=1:18\n y = f(hessianinit(x)); \n x = x - y.hx\\y.dx';\nend\ny.dx\n\n%%\n% Now x is an approximation of a stationary point:\n% The gradient of f evaluated at x is not too far from zero.\n \n%% Inclusion of a stationary point\n% Using this approximation an inclusion of a stationary point of f is \n% computed by (in this case the last parameter 1 is used to see \n% intermediate results):\n \nformat long\nX = verifynlss(f,x,'h',1)\n \n%% Inclusion of a minimum\n% The interval vector X includes a root of f', i.e. a stationary point xx of f. To prove\n% that f has a minumum at xx we need to prove positive definiteness of\n% the Hessian of f evaluated at xx. The interval vector X includes the stationary point\n% xx of f. So we compute an inclusion Y of the Hessian at X. \n%\n% Mathematically,\n% for every x in X the following is true: Y.x is an inclusion of f(x),\n% Y.dx is an inclusion of f'(x), and Y.hx is an inclusion of the\n% Hessian of f at x. Especially, the Hessian of f evaluated at xx is\n% included in Y.hx. \n \nY = f(hessianinit(X)); \nformat _\nY.hx\n \n%% \n% This interval matrix contains obviously only diagonally dominant\n% matrices, so the stationary point xx of f in X is indeed a (local)\n% minimum. \n%\n\n%% A model problem in 5000 unknowns I\n% The next problem is taken from \n%\n% http://www.sor.princeton.edu/~rvdb/ampl/nlmodels/cute/bdqrtic.mod\n%\n% Source: Problem 61 in\n% A.R. Conn, N.I.M. Gould, M. Lescrenier and Ph.L. Toint,\n% \"Performance of a multifrontal scheme for partially separable optimization\",\n% Report 88/4, Dept of Mathematics, FUNDP (Namur, B), 1988.\n% Copyright (C) 2001 Princeton University\n% All Rights Reserved\n% see bottom of file test_h.m\n% \n% The model problem is\n% \n% N = length(x); % model problem: N = 1000, initial approximation x=ones(N,1);\n% I = 1:N-4;\n% y = sum( (-4*x(I)+3.0).^2 ) + sum( ( x(I).^2 + 2*x(I+1).^2 + ...\n% 3*x(I+2).^2 + 4*x(I+3).^2 + 5*x(N).^2 ).^2 );\n% \n% This function is evaluated by\n%\n% index = 2;\n% y = test_h(x,index);\n\n%% A model problem in 5000 unknowns II\n% The given starting vector is x = ones(5000,1).\n% Recall that y = f(hessianinit(x)) has 5000 elements in y.x, 2.5e7 elements\n% in y.dx and 1.25e11 elements in y.hx. In full storage this would mean 1 TeraByte\n% of storage. \n%\n% The problem can be solved in the above manner. On my 2.8 GHz\n% Laptop this requires about 1 second per Newton iteration, and 5 seconds\n% for one function evaluation with interval argument. \n%\n% The following calculates an inclusion of a stationary point of f by first\n% performing a simple Newton iteration followed by a verification step for\n% the nonlinear system. The Hessian is treated as full matrix, so the \n% computation may take a while.\n \nn = 5000;\nindex = 2;\ntic\nX = verifynlss('test_h',ones(n,1),'h',1,index);\ntfull = toc\nmax(relerr(X))\n \n%% A model problem in 5000 unknowns III\n% Note the small maximum relative error of the inclusion of the result.\n% Verification is faster when solving the nonlinear system treating the\n% Hessian as sparse. This is done by the following. \n \nn = 5000;\nindex = 2;\ntic\nX = verifynlss('test_h',ones(n,1),'hSparseSPD',1,index);\ntsparse = toc\ntfull\nmax(relerr(X))\n \n%% \n% Note that verification is faster at the price of a less narrow inclusion\n% (for comparison the previous time tfull is displayed). \n% \n\n%% Verification of a minimum\n% Finally, the Hessian at X is computed which includes the Hessian at the\n% stationary point xhat in X. \n \ny = test_h(hessianinit(X),index); \nisspd(y.hx)\n \n%%\n% The interval Hessian is proved by \"isspd\" to be symmetric\n% positive definite: Mathematically the result \"isspd(M)=1\" for a symmetric\n% (Hermitian) interval matrix M proves that every symmetric (Hermitian) matrix\n% A within M is positive definite. In our case especially the Hermitian of f\n% at the stationary point xhat. Therefore, xhat is proved to be a local minimum of f.\n\n%% Enjoy INTLAB\n% INTLAB was designed and written by S.M. Rump, head of the Institute for Reliable Computing,\n% Hamburg University of Technology. Suggestions are always welcome to rump (at) tuhh.de\n", "meta": {"author": "douthwja01", "repo": "OpenMAS", "sha": "962f321f82167db78066b2c88c783423ecc3b73a", "save_path": "github-repos/MATLAB/douthwja01-OpenMAS", "path": "github-repos/MATLAB/douthwja01-OpenMAS/OpenMAS-962f321f82167db78066b2c88c783423ecc3b73a/toolboxes/Intlab_V7.1/demos/dhessian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.8933093954028816, "lm_q1q2_score": 0.8284223395730281}} {"text": "function variance = uniform_variance ( a, b )\n\n%*****************************************************************************80\n%\n%% UNIFORM_VARIANCE returns the variance of the Uniform PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A, B, the parameters of the PDF.\n% A < B.\n%\n% Output, real VARIANCE, the variance of the PDF.\n%\n variance = ( b - a )^2 / 12.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/prob/uniform_variance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.8902942290328345, "lm_q1q2_score": 0.828381611788769}} {"text": "% Generic rank-r Newton's iteration routine solving F(z) = 0 where \n% F is a smooth mapping between vector spaces, assuming the Jacobian \n% is of rank r at the solution that can be non-isolated \n% (c.f. http://homepages.neiu.edu/~zzeng/Papers/Rank-r_Newton.pdf) \n% \n% Syntax \n% [z,res,fcond] = Newton({@F,domain,para}, @G, z0) \n% [z,res,fcond] = Newton({@F,domain,para}, @G, z0, trac) \n% [z,res,fcond] = Newton({@F,domain,para}, @G, z0, trac, tol) \n% [z,res,fcond] = Newton({@F,domain,para}, {@G,r}, z0) \n% [z,res,fcond] = Newton({@F,domain,para}, {@G,r}, z0, trac) \n% [z,res,fcond] = Newton({@F,domain,para}, {@G,r}, z0, trac, tol) \n% \n% Input: F -- (function) Matlab function name for calculating y = F(z) \n% with syntax >> y = F(z1,...zk,p1,...,pm) where z1,...,zk \n% are components of z and p1,...,pm are fixed parameters. \n% (F must run on F(domain{:},para{:}). \n% domain -- domain of the homomorphism represented by \n% (i) an mxn matrix of 0 'and 1's representing \n% 0 entries and variable entries respectively, or \n% (ii) a polynomial with variable coefficients being \n% nonzero, or \n% (iii) a cell array of matrices in (i) and/or (ii) \n% assuming the domain is a product of matrix spaces and \n% polynomial spaces \n% para -- (cell) parameters needed for running F \n% G -- (function) Matlab function name for calculating the \n% Jacobian u = F_z(z0)y F as a homomorphism with syntax \n% >> u = G(y1,...,yk,z1,...zk,p1,...,pm) \n% where z1,...,zk,p1,...,pk are the same for F but \n% considered fixed, the variables are y1,...,yk in the \n% same domain of F. \n% r -- (integer, optional) if provided, the rank-r projection \n% of the Jacobian is used for the iteration \n% z0 -- (cell/matrix/polynomial) the initial iterate for the \n% Newton's iteration in the domain \n% trac -- (0,1,or 2, optional) flag for tracking the iteration \n% if tracking = 0 or missing, no tracking \n% if tracking = 1, track the first component z1 of z \n% if tracking = 2, track all components of z \n% tol -- (numeric, optional) error tolerance of the iterate \n% if missing, iteration stops when residule stops \n% decreasing \n% \n% Output: z -- the least squares solution in the domain \n% res -- (optional) the residual ||F(z)|| \n% fcond -- (optional) the condition number \n", "meta": {"author": "zarathustr", "repo": "LibQPEP", "sha": "99e5c23e746ace0bac4a86742c31db6fcf7297ba", "save_path": "github-repos/MATLAB/zarathustr-LibQPEP", "path": "github-repos/MATLAB/zarathustr-LibQPEP/LibQPEP-99e5c23e746ace0bac4a86742c31db6fcf7297ba/MATLAB/homotopy/Newton.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346504434783, "lm_q2_score": 0.8856314768368161, "lm_q1q2_score": 0.8283723060767304}} {"text": "function q = sphere_stereograph ( p )\n\n%*****************************************************************************80\n%\n%% SPHERE_STEREOGRAPH computes the stereographic image of points on a sphere.\n%\n% Discussion:\n%\n% We start with a sphere of radius 1 and center (0,0,0).\n%\n% The north pole N = (0,0,1) is the point of tangency to the sphere \n% of a plane, and the south pole S = (0,0,-1) is the focus for the \n% stereographic projection.\n%\n% For any point P on the sphere, the stereographic projection Q of the\n% point is defined by drawing the line from S through P, and computing\n% Q as the intersection of this line with the plane.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 10 November 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% C F Marcus,\n% The stereographic projection in vector notation,\n% Mathematics Magazine,\n% Volume 39, Number 2, March 1966, pages 100-102.\n%\n% Parameters:\n%\n% Input, real P(3,N), a set of points on the unit sphere.\n%\n% Output, real Q(3,N), the coordinates of the image points,\n%\n n = size ( p, 2 );\n q = zeros ( 3, n );\n \n q(1,1:n) = 2.0 * p(1,1:n) ./ ( 1.0 + p(3,1:n) );\n q(2,1:n) = 2.0 * p(2,1:n) ./ ( 1.0 + p(3,1:n) );\n q(3,1:n) = 1.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/sphere_stereograph_display/sphere_stereograph.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392795, "lm_q2_score": 0.8856314617436728, "lm_q1q2_score": 0.8283722951516671}} {"text": "function pde = sincosNeumanndata\n%% SINCOSNEUMANNDATA trigonometric data for Poisson equation \n%\n% f = 8*pi^2*sin(2*pi*x)*cos(2*pi*y);\n% u = sin(2*pi*x)*cos(2*pi*y);\n% Du = (2*pi*cos(2*pi*x)*cos(2*pi*y), -2*pi*sin(2*pi*x)*sin(2*pi*y));\n% du/dn = g_N on [0,1]^2.\n%\n% Copyright (C) Long Chen. See COPYRIGHT.txt for details.\n\npde = struct('f',@f,'exactu',@exactu,'Du',@Du,'g_D',@g_D,'g_N',@g_N);\n\n% load data (right hand side function)\nfunction rhs = f(p)\n x = p(:,1); y = p(:,2);\n rhs = 8*pi^2*sin(2*pi*x).*cos(2*pi*y);\nend\n% exact solution\nfunction u = exactu(p)\n x = p(:,1); y = p(:,2);\n u = sin(2*pi*x).*cos(2*pi*y);\nend\n% derivative of the exact solution\nfunction uprime = Du(p)\n x = p(:,1); y = p(:,2);\n uprime(:,1) = 2*pi*cos(2*pi*x).*cos(2*pi*y);\n uprime(:,2) = -2*pi*sin(2*pi*x).*sin(2*pi*y);\nend\nfunction u = g_D(p)\n u = exactu(p);\nend\n% Neumann boundary condition \nfunction f = g_N(p,vargin)\n if nargin > 1\n f = dot(Du(p),vargin,2);\n else\n f = zeros(size(p,1),1);\n x = p(:,1); y = p(:,2);\n uprime = [2*pi*cos(2*pi*x).*cos(2*pi*y) -2*pi*sin(2*pi*x).*sin(2*pi*y)];\n leftbd = (abs(x)1)\n error('Usage: TQUANT(n,p) - Probability p must be in [0,1].') \n elseif p == 1\n t = Inf;\n return\n elseif p == 0\n t = -Inf;\n return\n end\n \n if n == 1\n % Cauchy distribution (cf. Devroye [1986, pp. 29 and 450])\n t = tan(pi*(p-.5));\n elseif p >= 0.5 \n % positive t-values (cf. M. Abramowitz and I. A. Stegun [1964,\n % Chapter 26])\n b0 = [0, 1];\n f = inline('1 - betainc(b, n/2, .5)/2 - p', 'b', 'n', 'p'); \n opt = optimset('Display', 'off'); \n b = fzero(f, b0, opt, n, p); \n % old calling sequence (on Windows/Mac with older Matlab versions):\n %b = fzero(f, b0, eps, 0, n, p); \n \n t = sqrt(n/b-n);\n else\n % negative t-values\n b0 = [0, 1];\n f = inline('betainc(b, n/2, .5)/2 - p', 'b', 'n', 'p'); \n %opt = optimset('Display', 'off'); % does not work on Windows/Mac\n %b = fzero(f, b0, opt, n, p); \n % old calling sequence (for Windows/Mac compatibility):\n b = fzero(f, b0, eps, 0, n, p); \n t = -sqrt(n/b-n);\n end", "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/174-arfit/tquant.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.896251377290367, "lm_q1q2_score": 0.828263375222594}} {"text": "function runpenl(w0) \n\n% runpenl(w0) \n% See Article 2.5 \n% This example integrates the pendulum equation\n% theta\"(t) + 0.1*theta'(t)+sin(theta) = 0\n% and animates the motion\n\n% The equation of motion of a pendulum is\n% described by two first order equations:\n% theta'(t)=w; w'(t)=-.1*w-sin(theta). Let \n% z=[theta; w], then\n% z'(t)=[z(2); 0.2*z(2)-sin(z(1))]\n\n% Create a function defining the differential\n% equation in matrix form\n\n% pendulum=inline('[z(2);-sin(z(1))]','t','z');\npendulum=inline(...\n '[z(2);-0.2*z(2)-sin(z(1))]','t','z');\n\n% Choose time limits for the solution\ntmax=30; n=501; t=linspace(0,tmax,n);\n\n% Set integration tolerances\nopts=odeset('reltol',1e-5,'abstol',1e-5);\n\n% Input angular velocity repeatedly\nif nargin==0 \n disp(' ')\n disp(' DAMPED PENDULUM MOTION DESCRIBED BY')\n disp(' theta\"(t)+0.1*theta''(t)+sin(theta) = 0')\n while 1\n disp(' ')\n disp('Select the angular velocity at the lowest')\n disp('point. Values over 2.42 push the pendulum')\n disp('over the top. Input w0 (or press return')\n disp('to stop)')\n w0=input('w0 = ? > ');\n if isempty(w0)\n disp(' '), disp('All Done'), disp(' '), return\n end\n\n % Specify the initial conditions\n theta0=0; z0=[theta0;w0];\n\n % Solve the differential equation using ode45\n [t,th]=ode45(pendulum,t,z0,opts);\n\n % Plot the angular deflection of the pendulum\n plot(t,180/pi*th(:,1)), xlabel('time')\n ylabel('angular deflection (degrees)')\n title('ANGULAR DEFLECTION OF THE PENDULUM')\n disp(' ')\n disp('Press return to see the animation')\n grid on, shg, pause\n\n % Animate the motion\n for j=1:n\n T=th(j,1); X=[0;sin(T)]; Y=[0;-cos(T)];\n plot(X,Y,X(2),Y(2),'o','markersize',12)\n axis([-1,1,-1,1]), axis square, axis off\n drawnow, shg, pause(.05)\n end\n clf\n end\n return\nelse\n theta0=0; z0=[theta0;w0];\n [t,th]=ode45(pendulum,t,z0,opts);\n if max(th(:,1))>pi\n titl='OVER THE TOP';\n else\n titl='LARGE AMPLITUDE MOTION';\n end\n \n for j=1:n\n T=th(j,1); X=[0;sin(T)]; Y=[0;-cos(T)];\n plot(X,Y,X(2),Y(2),'o','markersize',12)\n axis([-1,1,-1,1]), axis square, axis off\n title(titl), drawnow, shg\n end\n pause(1), close, return\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/6558-dynamics-of-some-classical-system-models/dynamics/runpenl.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.8962513627417532, "lm_q1q2_score": 0.8282633673951008}} {"text": "function [est, x, k] = pnorm(A, p, tol, prnt)\n%PNORM Estimate of matrix p-norm (1 <= p <= inf).\n% [EST, x, k] = PNORM(A, p, TOL) estimates the Holder p-norm of a\n% matrix A, using the p-norm power method with a specially\n% chosen starting vector.\n% TOL is a relative convergence tolerance (default 1E-4).\n% Returned are the norm estimate EST (which is a lower bound for the\n% exact p-norm), the corresponding approximate maximizing vector x,\n% and the number of power method iterations k.\n% A nonzero fourth input argument causes trace output to the screen.\n% If A is a vector, this routine simply returns NORM(A, p).\n%\n% See also NORM, NORMEST, NORMEST1.\n\n% Note: The estimate is exact for p = 1, but is not always exact for\n% p = 2 or p = inf. Code could be added to treat p = 2 and p = inf\n% separately.\n%\n% Calls DUAL.\n%\n% Reference:\n% N. J. Higham, Estimating the matrix p-norm, Numer. Math.,\n% 62 (1992), pp. 539-555.\n% N. J. Higham, Accuracy and Stability of Numerical Algorithms,\n% Second edition, Society for Industrial and Applied Mathematics,\n% Philadelphia, PA, 2002; sec. 15.2.\n\nif nargin < 2, error('Must specify norm via second parameter.'), end\n[m,n] = size(A);\nif min(m,n) == 1, est = norm(A,p); return, end\n\nif nargin < 4, prnt = 0; end\nif nargin < 3 | isempty(tol), tol = 1e-4; end\n\n% Stage I. Use Algorithm OSE to get starting vector x for power method.\n% Form y = B*x, at each stage choosing x(k) = c and scaling previous\n% x(k+1:n) by s, where norm([c s],p)=1.\n\nsm = 9; % Number of samples.\ny = zeros(m,1); x = zeros(n,1);\n\nfor k=1:n\n\n if k == 1\n c = 1; s = 0;\n else\n W = [A(:,k) y];\n\n if p == 2 % Special case. Solve exactly for 2-norm.\n [U,S,V] = svd(full(W));\n c = V(1,1); s = V(2,1);\n\n else\n\n fopt = 0;\n for th=linspace(0,pi,sm)\n c1 = cos(th); s1 = sin(th);\n nrm = norm([c1 s1],p);\n c1 = c1/nrm; s1 = s1/nrm; % [c1 s1] has unit p-norm.\n f = norm( W*[c1 s1]', p );\n if f > fopt\n fopt = f;\n c = c1; s = s1;\n end\n end\n\n end\n end\n\n x(k) = c;\n y = x(k)*A(:,k) + s*y;\n if k > 1, x(1:k-1) = s*x(1:k-1); end\n\nend\n\nest = norm(y,p);\nif prnt, fprintf('Alg OSE: %9.4e\\n', est), end\n\n% Stage II. Apply Algorithm PM (the power method).\n\nq = dual(p);\nk = 1;\n\nwhile 1\n\n y = A*x;\n est_old = est;\n est = norm(y,p);\n\n z = A' * dual(y,p);\n\n if prnt\n fprintf('%2.0f: norm(y) = %9.4e, norm(z) = %9.4e', ...\n k, norm(y,p), norm(z,q))\n fprintf(' rel_incr(est) = %9.4e\\n', (est-est_old)/est)\n end\n\n if ( norm(z,q) <= z'*x | abs(est-est_old)/est <= tol ) & k > 1\n return\n end\n\n x = dual(z,q);\n k = k + 1;\n\nend\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/pnorm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8872046041554922, "lm_q1q2_score": 0.8281441164919034}} {"text": "classdef givens\n\nmethods(Static)\n\nfunction [c,s] = rotation(a,b)\n % Givens rotation computation\n % Determines cosine-sine pair (c,s) so that [c s;-s c]'*[a;b] = [r;0]\n % G = [c s; -s c]\n % x = [a; b]\n % G' x = [r; 0]\n % GVL4: algorithm 5.1.3\n if b==0\n % No rotation needed\n c = 1; s = 0;\n else\n if abs(b)>abs(a)\n tau = -a/b; \n s = 1/sqrt(1+tau^2); \n c = s*tau;\n else\n tau = -b/a; \n c = 1/sqrt(1+tau^2); \n s = c*tau;\n end\n end\nend % function\n\nfunction G = planerot(x)\n % Mimics the planerot function of MATLAB\n a = x(1);\n b = x(2);\n if b==0\n % No rotation needed\n c = 1; s = 0;\n else\n sa = sign(a);\n sb = sign(b); \n if abs(b)>abs(a)\n tau = -a/b; \n s = -sb/sqrt(1+tau^2); \n c = s*tau;\n else\n tau = -b/a; \n c = sa/sqrt(1+tau^2); \n s = c*tau;\n end\n end\n G = [c, -s; s c];\nend % function\n\nfunction theta = theta(c, s)\n theta = atan(s/c);\nend\n\nfunction [Q, R] = qr(A)\n % Givens method for computing the QR factorization A = QR.\n % A is modified in the algorithm\n % GVL4: algorithm 5.2.4\n import spx.la.givens.rotation;\n [m,n] = size(A);\n % Space for saving the Q factor\n Q = eye(m,m);\n % Iterate over columns from first to last\n for j=1:n\n % Iterate over rows from last pair to first pair\n for i=m:-1:j+1\n % pick two elements from consecutive rows\n a = A(i-1,j);\n b = A(i,j);\n % Compute the needed rotation for making b 0.\n [c,s] = rotation(a,b);\n % form the Givens rotation matrix\n G = [c s;-s c];\n % Rotate the two consecutive rows based submatrix\n A(i-1:i,j:n) = G'*A(i-1:i,j:n);\n % Rotate corresponding columns in Q matrix\n % by postmultiplication with G\n Q(:,i-1:i) = Q(:,i-1:i)*G;\n end\n end\n % Return the triangular form\n R = A;\nend % function\n\nend % methods \n\nend % classdef\n\n", "meta": {"author": "indigits", "repo": "sparse-plex", "sha": "43cae2978f62938d001baaa03308a2a717ee6c9b", "save_path": "github-repos/MATLAB/indigits-sparse-plex", "path": "github-repos/MATLAB/indigits-sparse-plex/sparse-plex-43cae2978f62938d001baaa03308a2a717ee6c9b/library/+spx/+la/givens.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810421953309, "lm_q2_score": 0.8740772433654401, "lm_q1q2_score": 0.8280842097787726}} {"text": "function[u,v,w]=sphere2uvw(lat,lon,dr,dth,dphi)\n%SPHERE2UVW Converts a 3D spherical vector to a 3D Cartesian vector.\n%\n% [U,V,W]=XYZ2SPHERE(LAT,LON,V1,V2,V3) converts a vector in spherical\n% coordinates with components V1, V2, and V3 located at point \n% (LAT, LON) into a Cartesian 3-vector with components U, V, and W.\n%\n% LAT and LON are in degrees.\n%\n% The vector in the spherical coordinate system has radial component\n% V1, longitudinal component V2, and latitudinal component V3. \n%\n% The Cartesian vector [U,V,W] is in a reference frame with the\n% X-axis at zero degrees longitude and the Z-axis at the North Pole. \n%\n% All input arguments should be arrays of the same size.\n%\n% SPHERE2UVW is inverted by UVW2SPHERE.\n%\n% See JSPHERE for related functions.\n%\n% Usage: [x,y,z]=sphere2uvw(lat,lon,v1,v2,v3);\n% __________________________________________________________________\n% This is part of JLAB --- type 'help jlab' for more information\n% (C) 2007--2014 J.M. Lilly --- type 'help jlab_license' for details\n \nif strcmpi(lat, '--t')\n sphere2uvw_test,return\nend\n[phi,theta]=jdeg2rad(lat,lon);\n\nu = cos(phi).*cos(theta).*dr -sin(theta).*dth - sin(phi).*cos(theta).*dphi;\nv = cos(phi).*sin(theta).*dr + cos(theta).*dth - sin(phi).*sin(theta).*dphi ;\nw = sin(phi).*dr + cos(phi).*dphi;\n\n\nfunction[]=sphere2uvw_test\n \nlat=[0 0 45 0 -90]';\nlon=[0 90 0 90 0 ]';\nv1= [1 1 1 0 0]'; \nv2= [0 0 0 -1 0]';\nv3= [0 0 0 0 1]';\nu= [1 0 sqrt(2)/2 1 1 ]';\nv= [0 1 0 0 0]';\nw= [0 0 sqrt(2)/2 0 0]';\n\n[u2,v2,w2]=sphere2uvw(lat,lon,v1,v2,v3);\ntol=1e-6;\nreporttest('SPHERE2XYZ example points',aresame(u,u2,tol)&&aresame(v,v2,tol)&&aresame(w,w2,tol))\n", "meta": {"author": "jonathanlilly", "repo": "jLab", "sha": "9f32f63e647209bc1cb81c8713deb954857f1919", "save_path": "github-repos/MATLAB/jonathanlilly-jLab", "path": "github-repos/MATLAB/jonathanlilly-jLab/jLab-9f32f63e647209bc1cb81c8713deb954857f1919/jsphere/sphere2uvw.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.920789673717312, "lm_q2_score": 0.8991213813246444, "lm_q1q2_score": 0.8279016833421782}} {"text": "function\t[out,dout]=rodrigues(in)\n\n% RODRIGUES\tTransform rotation matrix into rotation vector and viceversa.\n%\n%\t\tSintax: [OUT]=RODRIGUES(IN)\n% \t\tIf IN is a 3x3 rotation matrix then OUT is the\n%\t\tcorresponding 3x1 rotation vector\n% \t\tif IN is a rotation 3-vector then OUT is the\n%\t\tcorresponding 3x3 rotation matrix\n%\n\n%%\n%%\t\tCopyright (c) March 1993 -- Pietro Perona\n%%\t\tCalifornia Institute of Technology\n%%\n\n%% ALL CHECKED BY JEAN-YVES BOUGUET, October 1995.\n%% FOR ALL JACOBIAN MATRICES !!! LOOK AT THE TEST AT THE END !!\n\n%% BUG when norm(om)=pi fixed -- April 6th, 1997;\n%% Jean-Yves Bouguet\n\n%% Add projection of the 3x3 matrix onto the set of special ortogonal matrices SO(3) by SVD -- February 7th, 2003;\n%% Jean-Yves Bouguet\n\n[m,n] = size(in);\n%bigeps = 10e+4*eps;\nbigeps = 10e+20*eps;\n\nif ((m==1) && (n==3)) | ((m==3) && (n==1)) %% it is a rotation vector\n theta = norm(in);\n if theta < eps\n R = eye(3);\n\n %if nargout > 1,\n\n dRdin = [0 0 0;\n\t 0 0 1;\n\t 0 -1 0;\n\t 0 0 -1;\n\t 0 0 0;\n\t 1 0 0;\n\t 0 1 0;\n\t -1 0 0;\n 0 0 0];\n\n %end;\n\n else\n if n==length(in) in=in'; end; \t%% make it a column vec. if necess.\n\n\t %m3 = [in,theta]\n\n\t dm3din = [eye(3);in'/theta];\n\n\t omega = in/theta;\n\n\t %m2 = [omega;theta]\n\n\t dm2dm3 = [eye(3)/theta -in/theta^2; zeros(1,3) 1];\n\n\t alpha = cos(theta);\n\t beta = sin(theta);\n\t gamma = 1-cos(theta);\n\t omegav=[[0 -omega(3) omega(2)];[omega(3) 0 -omega(1)];[-omega(2) omega(1) 0 ]];\n\t A = omega*omega';\n\n\t %m1 = [alpha;beta;gamma;omegav;A];\n\n\t dm1dm2 = zeros(21,4);\n\t dm1dm2(1,4) = -sin(theta);\n\t dm1dm2(2,4) = cos(theta);\n\t dm1dm2(3,4) = sin(theta);\n\t dm1dm2(4:12,1:3) = [0 0 0 0 0 1 0 -1 0;\n\t 0 0 -1 0 0 0 1 0 0;\n\t\t\t 0 1 0 -1 0 0 0 0 0]';\n\n w1 = omega(1);\n\t w2 = omega(2);\n\t w3 = omega(3);\n\n\t dm1dm2(13:21,1) = [2*w1;w2;w3;w2;0;0;w3;0;0];\n\t dm1dm2(13: 21,2) = [0;w1;0;w1;2*w2;w3;0;w3;0];\n\t dm1dm2(13:21,3) = [0;0;w1;0;0;w2;w1;w2;2*w3];\n\n\t R = eye(3)*alpha + omegav*beta + A*gamma;\n\n\t dRdm1 = zeros(9,21);\n\n\t dRdm1([1 5 9],1) = ones(3,1);\n\t dRdm1(:,2) = omegav(:);\n\t dRdm1(:,4:12) = beta*eye(9);\n\t dRdm1(:,3) = A(:);\n\t dRdm1(:,13:21) = gamma*eye(9);\n\n\t dRdin = dRdm1 * dm1dm2 * dm2dm3 * dm3din;\n\n\n end;\n out = R;\n dout = dRdin;\n\n %% it is prob. a rot matr.\n elseif ((m==n) & (m==3) & (norm(in' * in - eye(3)) < bigeps)...\n\t & (abs(det(in)-1) < bigeps))\n R = in;\n\n % project the rotation matrix to SO(3);\n [U,S,V] = svd(R);\n R = U*V';\n\n tr = (trace(R)-1)/2;\n dtrdR = [1 0 0 0 1 0 0 0 1]/2;\n theta = real(acos(tr));\n\n\n if sin(theta) >= 1e-5,\n\n\t dthetadtr = -1/sqrt(1-tr^2);\n\n\t dthetadR = dthetadtr * dtrdR;\n\t % var1 = [vth;theta];\n\t vth = 1/(2*sin(theta));\n\t dvthdtheta = -vth*cos(theta)/sin(theta);\n\t dvar1dtheta = [dvthdtheta;1];\n\n\t dvar1dR = dvar1dtheta * dthetadR;\n\n\n\t om1 = [R(3,2)-R(2,3), R(1,3)-R(3,1), R(2,1)-R(1,2)]';\n\n\t dom1dR = [0 0 0 0 0 1 0 -1 0;\n\t 0 0 -1 0 0 0 1 0 0;\n\t 0 1 0 -1 0 0 0 0 0];\n\n\t % var = [om1;vth;theta];\n\t dvardR = [dom1dR;dvar1dR];\n\n\t % var2 = [om;theta];\n\t om = vth*om1;\n\t domdvar = [vth*eye(3) om1 zeros(3,1)];\n\t dthetadvar = [0 0 0 0 1];\n\t dvar2dvar = [domdvar;dthetadvar];\n\n\n\t out = om*theta;\n\t domegadvar2 = [theta*eye(3) om];\n\n\t dout = domegadvar2 * dvar2dvar * dvardR;\n\n\n else\n\t if tr > 0; \t\t\t% case norm(om)=0;\n\n\t out = [0 0 0]';\n\n\t dout = [0 0 0 0 0 1/2 0 -1/2 0;\n\t\t 0 0 -1/2 0 0 0 1/2 0 0;\n\t\t 0 1/2 0 -1/2 0 0 0 0 0];\n\t else \t\t\t\t% case norm(om)=pi; %% fixed April 6th\n\n\n\t out = theta * (sqrt((diag(R)+1)/2).*[1;2*(R(1,2:3)>=0)'-1]);\n\t %keyboard;\n\n\t if nargout > 1,\n\t fprintf(1,'WARNING!!!! Jacobian domdR undefined!!!\\n');\n\t\t \tdout = NaN*ones(3,9);\n\t end;\n\t end;\n end;\n\n else\n error('Neither a rotation matrix nor a rotation vector were provided');\n end;\n\nreturn;\n\n%% test of the Jacobians:\n\n%%%% TEST OF dRdom:\nom = randn(3,1);\ndom = randn(3,1)/1000000;\n\n[R1,dR1] = rodrigues(om);\nR2 = rodrigues(om+dom);\n\nR2a = R1 + reshape(dR1 * dom,3,3);\n\ngain = norm(R2 - R1)/norm(R2 - R2a)\n\n%%% TEST OF dOmdR:\nom = randn(3,1);\nR = rodrigues(om);\ndom = randn(3,1)/10000;\ndR = rodrigues(om+dom) - R;\n\n[omc,domdR] = rodrigues(R);\n[om2] = rodrigues(R+dR);\n\nom_app = omc + domdR*dR(:);\n\ngain = norm(om2 - omc)/norm(om2 - om_app)\n\n\n%%% OTHER BUG: (FIXED NOW!!!)\n\nomu = randn(3,1);\nomu = omu/norm(omu)\nom = pi*omu;\n[R,dR]= rodrigues(om);\n[om2] = rodrigues(R);\n[om om2]\n\n%%% NORMAL OPERATION\n\nom = randn(3,1);\n[R,dR]= rodrigues(om);\n[om2] = rodrigues(R);\n[om om2]\n\n", "meta": {"author": "strawlab", "repo": "MultiCamSelfCal", "sha": "0a26c88c63d8513eab76553033a9a6fb15ba6575", "save_path": "github-repos/MATLAB/strawlab-MultiCamSelfCal", "path": "github-repos/MATLAB/strawlab-MultiCamSelfCal/MultiCamSelfCal-0a26c88c63d8513eab76553033a9a6fb15ba6575/CalTechCal/rodrigues.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.8947894682067639, "lm_q1q2_score": 0.8278860157409648}} {"text": "function [ geom, iner, cpmo ] = polygeom( x, y ) \n%POLYGEOM Geometry of a planar polygon\n%\n% POLYGEOM( X, Y ) returns area, X centroid,\n% Y centroid and perimeter for the planar polygon\n% specified by vertices in vectors X and Y.\n%\n% [ GEOM, INER, CPMO ] = POLYGEOM( X, Y ) returns\n% area, centroid, perimeter and area moments of \n% inertia for the polygon.\n% GEOM = [ area X_cen Y_cen perimeter ]\n% INER = [ Ixx Iyy Ixy Iuu Ivv Iuv ]\n% u,v are centroidal axes parallel to x,y axes.\n% CPMO = [ I1 ang1 I2 ang2 J ]\n% I1,I2 are centroidal principal moments about axes\n% at angles ang1,ang2.\n% ang1 and ang2 are in radians.\n% J is centroidal polar moment. J = I1 + I2 = Iuu + Ivv\n\n% H.J. Sommer III - 02.05.14 - tested under MATLAB v5.2\n%\n% sample data\n% x = [ 2.000 0.500 4.830 6.330 ]';\n% y = [ 4.000 6.598 9.098 6.500 ]';\n% 3x5 test rectangle with long axis at 30 degrees\n% area=15, x_cen=3.415, y_cen=6.549, perimeter=16\n% Ixx=659.561, Iyy=201.173, Ixy=344.117\n% Iuu=16.249, Ivv=26.247, Iuv=8.660\n% I1=11.249, ang1=30deg, I2=31.247, ang2=120deg, J=42.496\n%\n% H.J. Sommer III, Ph.D., Professor of Mechanical Engineering, 337 Leonhard Bldg\n% The Pennsylvania State University, University Park, PA 16802\n% (814)863-8997 FAX (814)865-9693 hjs1@psu.edu www.me.psu.edu/sommer/\n\n% begin function POLYGEOM\n\n% check if inputs are same size\nif ~isequal( size(x), size(y) ),\n error( 'X and Y must be the same size');\nend\n\n% number of vertices\n[ x, ns ] = shiftdim( x );\n[ y, ns ] = shiftdim( y );\n[ n, c ] = size( x );\n\n% temporarily shift data to mean of vertices for improved accuracy\nxm = mean(x);\nym = mean(y);\nx = x - xm*ones(n,1);\ny = y - ym*ones(n,1);\n\n% delta x and delta y\ndx = x( [ 2:n 1 ] ) - x;\ndy = y( [ 2:n 1 ] ) - y;\n\n% summations for CW boundary integrals\nA = sum( y.*dx - x.*dy )/2;\nAxc = sum( 6*x.*y.*dx -3*x.*x.*dy +3*y.*dx.*dx +dx.*dx.*dy )/12;\nAyc = sum( 3*y.*y.*dx -6*x.*y.*dy -3*x.*dy.*dy -dx.*dy.*dy )/12;\nIxx = sum( 2*y.*y.*y.*dx -6*x.*y.*y.*dy -6*x.*y.*dy.*dy ...\n -2*x.*dy.*dy.*dy -2*y.*dx.*dy.*dy -dx.*dy.*dy.*dy )/12;\nIyy = sum( 6*x.*x.*y.*dx -2*x.*x.*x.*dy +6*x.*y.*dx.*dx ...\n +2*y.*dx.*dx.*dx +2*x.*dx.*dx.*dy +dx.*dx.*dx.*dy )/12;\nIxy = sum( 6*x.*y.*y.*dx -6*x.*x.*y.*dy +3*y.*y.*dx.*dx ...\n -3*x.*x.*dy.*dy +2*y.*dx.*dx.*dy -2*x.*dx.*dy.*dy )/24;\nP = sum( sqrt( dx.*dx +dy.*dy ) );\n\n% check for CCW versus CW boundary\nif A < 0,\n A = -A;\n Axc = -Axc;\n Ayc = -Ayc;\n Ixx = -Ixx;\n Iyy = -Iyy;\n Ixy = -Ixy;\nend\n\n% centroidal moments\nxc = Axc / A;\nyc = Ayc / A;\nIuu = Ixx - A*yc*yc;\nIvv = Iyy - A*xc*xc;\nIuv = Ixy - A*xc*yc;\nJ = Iuu + Ivv;\n\n% replace mean of vertices\nx_cen = xc + xm;\ny_cen = yc + ym;\nIxx = Iuu + A*y_cen*y_cen;\nIyy = Ivv + A*x_cen*x_cen;\nIxy = Iuv + A*x_cen*y_cen;\n\n% principal moments and orientation\nI = [ Iuu -Iuv ;\n -Iuv Ivv ];\n[ eig_vec, eig_val ] = eig(I);\nI1 = eig_val(1,1);\nI2 = eig_val(2,2);\nang1 = atan2( eig_vec(2,1), eig_vec(1,1) );\nang2 = atan2( eig_vec(2,2), eig_vec(1,2) );\n\n% return values\ngeom = [ A x_cen y_cen P ];\niner = [ Ixx Iyy Ixy Iuu Ivv Iuv ];\ncpmo = [ I1 ang1 I2 ang2 J ];\n\n% end of function POLYGEOM\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/319-polygeom-m/polygeom.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133447766225, "lm_q2_score": 0.8807970795424087, "lm_q1q2_score": 0.8278729291021861}} {"text": "function value = r8_log_2 ( x )\n\n%*****************************************************************************80\n%\n%% R8_LOG_2 returns the logarithm base 2 of |X|.\n%\n% Discussion:\n%\n% R8_LOG_2 ( X ) = Log ( |X| ) / Log ( 2.0 )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 21 March 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the number whose base 2 logarithm is desired.\n% X should not be 0.\n%\n% Output, real VALUE, the logarithm base 2 of the absolute\n% value of X. It should be true that |X| = 2**R8_LOG_2.\n%\n if ( x == 0.0 )\n value = -inf;\n else\n value = log ( abs ( x ) ) / log ( 2.0 );\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/r8_log_2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.8807970701552505, "lm_q1q2_score": 0.827872921761561}} {"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\nfor i = 1:K\n idx_i = idx == i;\n centroids(i, :) = (idx_i' * X) ./ sum(idx_i);\nend\n\n% =============================================================\n\n\nend\n\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/ex7/computeCentroids.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.9073122282528899, "lm_q1q2_score": 0.8278644902216449}} {"text": "function [kEst,thetaEst]=PoissonRateLikeGammaConjUpdate(xMeas,kEst,thetaEst)\n%%POISSONRATELIKEGAMMACONJUPDATE When estimating the rate parameter of the\n% Poisson distribution, the conjugate prior distribution is a\n% central (lambda=0) gamma distribution. Given the prior\n% shape and rate parameters of the gamma distribution, this\n% function updates those parameters conditioned on the\n% measurements. The result is the parameters of the posterior\n% distribution, which is also a gamma distribution.\n%\n%INPUTS: xMeas An NX1 or 1XN set of N independent measurements of the\n% Poisson distribution.\n% kEst The shape parameter of the prior (central gamma)\n% distribution.\n% thetaEst The scale parameter of the prior distribution.\n%\n%OUTPUTS: kEst The shape parameter of the posterior (central gamma)\n% distribution.\n% thetaEst The scale parameter of the posterior distribution.\n%\n%A distribution that is conjugate prior to a particular likelihood function\n%is such that after performing Bayes' rule to update using a measurement,\n%one obtains the same type of distribution back again. This function just\n%performs Bayes rule with the given measurements.\n%\n%The conjugate prior relation for the Poisson distribution is given in [1].\n%\n%REFERENCES:\n%[1] D. Fink, \"A compendium of conjugate priors,\" Montana State University,\n% Department of Biology, Environmental Statistics Group, Tech. Rep., May\n% 1997. [Online].\n% Available: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.157.5540\n%\n%October 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nnumMeas=length(xMeas);\n\nkEst=kEst+sum(xMeas);\nif(isfinite(thetaEst))\n thetaEst=thetaEst/(numMeas*thetaEst+1);\nelse%If an uninformativ prior is given (thetaEst=Inf), use the asymptotic\n %result.\n thetaEst=1/numMeas;\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/Conjugate_Prior_Updates/PoissonRateLikeGammaConjUpdate.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.907312215721497, "lm_q1q2_score": 0.8278644787875489}} {"text": "function value = sphere_shell_volume_nd ( n, r1, r2 )\n\n%*****************************************************************************80\n%\n%% SPHERE_SHELL_VOLUME_ND computes the volume of a spherical shell in ND.\n%\n% Integration region:\n%\n% Points X(1:N) such that:\n%\n% R1**2 <= Sum ( X(1:N) - XC(1:N) )**2 <= R2**2.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 20 May 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the dimension of the space.\n%\n% Input, real R1, R2, the radiuses of the inner and\n% outer spheres.\n%\n% Output, real SPHERE_SHELL_VOLUME_ND, the volume of the\n% spherical shell.\n%\n value = ball_volume_nd ( n, r2 ) - ball_volume_nd ( n, r1 );\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/stroud/sphere_shell_volume_nd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541626630937, "lm_q2_score": 0.8791467706759584, "lm_q1q2_score": 0.8278522161988324}} {"text": "function rx = vecrotx(angle) \n% \n% Function Name: \n% \n% vecrotx - Transformation matrix for a rotation around the x axis. \n% \n% Calling Sequence: \n% \n% rx = vecrotx(angle); \n% \n% Parameters: \n% \n% angle\t\t: rotation angle defined in radians \n% \n% rx\t\t: (4x4) Transformation matrix. \n% \n% \n% Description: \n% \n% Return the (4x4) Transformation matrix for a rotation about the x axis \n% by the defined angle. \n% \n% The matrix is: \n% \n% [ 1 0 0 0] \n% [ 0 cos(angle) -sin(angle) 0] \n% [ 0 sin(angle) 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 x-axis \n% \n% line = nrbline([0.0 0.0 0.0],[3.0 3.0 3.0]); \n% trans = vecrotx(%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); \nrx = [1 0 0 0; 0 cn -sn 0; 0 sn 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/vecrotx.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9715639636617014, "lm_q2_score": 0.8519528019683105, "lm_q1q2_score": 0.8277266411330243}} {"text": "function circle_forward ( a )\n\n%*****************************************************************************80\n%\n%% CIRCLE_FORWARD plots the image of the unit circle under the 2x2 matrix A.\n%\n% Discussion:\n%\n% A typical 2x2 matrix will map the unit circle to some kind of tilted ellipse.\n% The aspect ratio of the ellipse (ratio of major to minor axes) is a measure\n% of the conditioning of the matrix.\n%\n% A singular matrix maps the unit circle to a line.\n%\n% A diagonal matrix maps the unit circle to an ellipse with no tilting.\n% (There is no rotation.)\n%\n% An orthogonal matrix maps the unit circle to the unit circle (but points\n% may have rotated.)\n%\n% The identity matrix maps the unit circle to itself.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 27 January 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A(2,2), the matrix whose mapping of the unit circle \n% is to be studied.\n%\n\n%\n% This call produces matrices U, S and V.\n%\n% [ u, s, v ] = svd ( a );\n%\n% This call produces just the singular values, and in a vector, not a matrix.\n%\n s = svd ( a );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Singular values of A are %f and %f\\n', s(1), s(2) );\n%\n% Select N+1 evenly spaced points X on the unit circle.\n%\n n = 32;\n\n i = [ 0 : n ];\n\n angle = 2 * pi * i / n;\n\n r = 1;\n\n x = [ r * cos(angle); r * sin(angle) ];\n%\n% AX contains the image of each point under the mapping X -> A*X.\n%\n ax = a * x;\n%\n% Plot the corners of the region. This is a trick to force MATLAB\n% to plot in a square with equal axes. I don't know why it seems to\n% hard to get this to happen in general!\n%\n s = [];\n\n p_min = min ( min ( min ( ax ) ), min ( min ( x ) ) );\n p_max = max ( max ( max ( ax ) ), max ( max ( x ) ) );\n\n scatter ( [ p_min, p_max, p_max, p_min ], [ p_min, p_min, p_max, p_max ], s, 'k' );\n axis ( [ p_min, p_max, p_min, p_max ] );\n\n axis equal\n axis tight\n axis square\n\n hold on\n%\n% Plot the points X on the unit circle.\n%\n scatter ( x(1,:), x(2,:), s, 'b', 'filled' );\n%\n% Plot the points AX on the image of the unit circle.\n%\n scatter ( ax(1,:), ax(2,:), s, 'r', 'filled' );\n%\n% Plot vectors for \"3-oclock\" and \"12-oclock\".\n%\n line ( [ 0, x(1,1)], [ 0, x(2,1)], 'color', 'b' );\n line ( [ 0, x(1,n/4+1)], [ 0, x(2,n/4+1)], 'color', 'b' );\n%\n% Plot the images of \"3-oclock\" and \"12-oclock\".\n%\n line ( [ 0, ax(1,1)], [ 0, ax(2,1)], 'color', 'r' );\n line ( [ 0, ax(1,n/4+1)], [ 0, ax(2,n/4+1)], 'color', 'r' );\n\n xlabel ( '--X axis--' )\n ylabel ( '--Y axis--' )\n title ( 'X in blue, A*X in red' );\n\n hold off\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/svd_demo/circle_forward.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480347, "lm_q2_score": 0.8840392878563336, "lm_q1q2_score": 0.8277127297120558}} {"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\nJ = 1 / 2 * sum(sum(R .* (X * Theta' - Y) .^ 2)) + lambda / 2 * (sum(sum(Theta .^ 2)) + sum(sum(X .^ 2)));\n\nfor i=1:num_movies\n idx = find(R(i, :) == 1);\n Theta_temp = Theta(idx, :);\n Y_temp = Y(i, idx);\n X_grad(i, :) = (X(i, :) * Theta_temp' - Y_temp) * Theta_temp + lambda * X(i, :);\nend\n\nfor i=1:num_users\n idx = find(R(:, i) == 1);\n X_temp = X(idx, :);\n Y_temp = Y(idx, i);\n Theta_grad(i, :) = (X_temp * Theta(i, :)' - Y_temp)' * X_temp + lambda * Theta(i, :);\nend\n\n% =============================================================\n\ngrad = [X_grad(:); Theta_grad(:)];\n\nend\n", "meta": {"author": "merwan", "repo": "ml-class", "sha": "0b06b73d4aac0b8d7c726325200c3781b5c9d3b0", "save_path": "github-repos/MATLAB/merwan-ml-class", "path": "github-repos/MATLAB/merwan-ml-class/ml-class-0b06b73d4aac0b8d7c726325200c3781b5c9d3b0/mlclass-ex8/cofiCostFunc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.884039278690883, "lm_q1q2_score": 0.8277127179871692}} {"text": "function r=rot(psi,theta,phi);\n% function r=rot(psi,theta,phi)\n%\n% Description\n% Computes the rotarion matrix corresponding to a oritentation vector\n% The input data are:\n% - psi .- the psi angle (radians)\n% - theta .- the theta angle (radians)\n% - phi .- the phi angle (radians)\n%\n% The return value is\n% the rotation matrix (dim 3x3)\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%% Grupo de Robotica %%\n%% Departamento de Informatica e Ingenieria de Sistemas %%\n%% Universidad de Zaragoza %%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%% Name : .m %%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%% Programmer : Jose Maria Martinez %%\n%% Languaje : Matlab 4.2 c %%\n%% Date : February 1996 %%\n%% Status : Prueba %%\n%% History\t: 16-8-95 creation %%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\n\n\ncosphi=cos(phi);\nsinphi=sin(phi);\ncostheta=cos(theta);\nsintheta=sin(theta);\ncospsi=cos(psi);\nsinpsi=sin(psi);\n\nr=zeros(3,3);\nr(1,1)=cosphi*costheta;\nr(1,2)=cosphi*sintheta*sinpsi-sinphi*cospsi;\nr(1,3)=cosphi*sintheta*cospsi+sinphi*sinpsi;\nr(2,1)=sinphi*costheta;\nr(2,2)=sinphi*sintheta*sinpsi+cosphi*cospsi;\nr(2,3)=sinphi*sintheta*cospsi-cosphi*sinpsi;\nr(3,1)=-sintheta;\nr(3,2)=costheta*sinpsi;\nr(3,3)=costheta*cospsi;\nreturn;\n", "meta": {"author": "JzHuai0108", "repo": "ekfmonoslam", "sha": "443f6be744732453cdb90679abcaf5c962a6295e", "save_path": "github-repos/MATLAB/JzHuai0108-ekfmonoslam", "path": "github-repos/MATLAB/JzHuai0108-ekfmonoslam/ekfmonoslam-443f6be744732453cdb90679abcaf5c962a6295e/EKF_monoSLAM_1pRANSAC/matlab_code/rot.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741227833249, "lm_q2_score": 0.8688267677469951, "lm_q1q2_score": 0.8276218961372653}} {"text": "\n\nfunction call_price=american_call_baw(S, X, r, b, sigma, time, accuracy)\n\n\n%--------------------------------------------------------------------------\n%\n% DESCRIPTION:\n%\n% Barone-Adesi and Whaley (1987) quadratic approximation to the price \n% of a call option.\n%\n%\n% Reference:\n%\n% Giovanni Barone-Adesi and Robert E. Whaley, \n% \"Efficient analytic approximation of American option values\", \n% Journal of Finance, 42(2):301-320, June 1987.\n%\n% \n%--------------------------------------------------------------------------\n%\n% INPUTS:\n%\n% S: spot price\n% X: exercise price\n% r: interest rate\n% b: dividend yield\n% sigma: volatility \n% time: time to maturity\n% accuracy: approximation accuracy\n%\n%--------------------------------------------------------------------------\n%\n% OUTPUT:\n%\n% call_price: price of a call option\n%\n%--------------------------------------------------------------------------\n%\n% Author: Paolo Z., February 2012\n%\n%--------------------------------------------------------------------------\n\n\n\nsigma_sqr = sigma*sigma;\ntime_sqrt = sqrt(time);\n\nnn = 2.0*b/sigma_sqr;\n\nm = 2.0*r/sigma_sqr;\nK = 1.0-exp(-r*time);\n\nq2 = ( -(nn-1) + sqrt( (nn-1)^2 + (4*m/K) ) )*0.5;\nq2_inf = 0.5 * ( -(nn-1) + sqrt( (nn-1)^2 + 4.0*m ) ); \n\nS_star_inf = X / (1.0 - 1.0/q2_inf);\nh2 = -(b*time+2.0*sigma*time_sqrt)*(X/(S_star_inf-X));\n\nS_seed = X + (S_star_inf-X)*(1.0-exp(h2));\n\nno_iterations=0; \n\nSi = S_seed;\ng = 1;\ngprime = 1;\n\n\nwhile ((abs(g) > accuracy) && (abs(gprime)>accuracy) && ( no_iterations<500) && (Si>0.0)) \n c = european_call_contpay(Si,X,r,b,sigma,time);\n \n d1 = (log(Si/X)+(b+0.5*sigma_sqr)*time)/(sigma*time_sqrt);\n g =(1.0-1.0/q2)*Si-X-c+(1.0/q2)*Si*exp((b-r)*time)*normcdf(d1);\n \n gprime =( 1.0-1.0/q2)*(1.0-exp((b-r)*time)*normcdf(d1))+(1.0/q2)*exp((b-r)*time)*normcdf(d1)*(1.0/(sigma*time_sqrt));\n Si = Si-(g/gprime);\nend\n\n\nS_star = 0;\n\n\nif (abs(g)>accuracy) \n S_star = S_seed; %// did not converge\nelse \n S_star = Si; \nend\n\n\nC=0;\nc = european_call_contpay(S,X,r,b,sigma,time);\n\n\nif (S>=S_star) \n C = S-X;\nelse \n d1 = (log(S_star/X)+(b+0.5*sigma_sqr)*time)/(sigma*time_sqrt);\n A2 = (1.0-exp((b-r)*time)*normcdf(d1))* (S_star/q2);\n C = c+A2*((S/S_star)^q2);\nend\n\n\ncall_price = max(C,c); \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/35351-option-pricing-package/american_call_baw.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.94499471015743, "lm_q2_score": 0.8757869867849166, "lm_q1q2_score": 0.8276140697364612}} {"text": "function [ alpha, beta, gamma ] = bdf_set ( n )\n\n%*****************************************************************************80\n%\n%% BDF_SET sets weights for backward differentiation ODE weights.\n%\n% Discussion:\n%\n% GAMMA * Y(N+1) = Sum ( 1 <= I <= N ) ALPHA(I) * Y(N+1-I)\n% + dX * BETA * Y'(X(N+1),Y(N+1))\n%\n% This is equivalent to the backward differentiation corrector formulas.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 October 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order.\n% N must be between 1 and 6.\n%\n% Output, real ALPHA(N), BETA, GAMMA, the weights.\n%\n alpha = zeros ( n, 1 );\n\n if ( n == 1 )\n beta = 1.0;\n gamma = 1.0;\n alpha(1) = 1.0;\n elseif ( n == 2 )\n beta = 2.0;\n gamma = 3.0;\n alpha(1) = 4.0;\n alpha(2) = - 1.0;\n elseif ( n == 3 )\n beta = 6.0;\n gamma = 11.0;\n alpha(1) = 18.0;\n alpha(2) = - 9.0;\n alpha(3) = 2.0;\n elseif ( n == 4 )\n beta = 12.0;\n gamma = 25.0;\n alpha(1) = 48.0;\n alpha(2) = - 36.0;\n alpha(3) = 16.0;\n alpha(4) = - 3.0;\n elseif ( n == 5 )\n beta = 60.0;\n gamma = 137.0;\n alpha(1) = 300.0;\n alpha(2) = - 300.0;\n alpha(3) = 200.0;\n alpha(4) = - 75.0;\n alpha(5) = 12.0;\n elseif ( n == 6 )\n beta = 60.0;\n gamma = 147.0;\n alpha(1) = 360.0;\n alpha(2) = - 450.0;\n alpha(3) = 400.0;\n alpha(4) = - 225.0;\n alpha(5) = 72.0;\n alpha(6) = - 10.0;\n else\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BDF_SET - Fatal error!\\n' );\n fprintf ( 1, ' Illegal order requested = %d\\n', n );\n error ( 'BDF_SET - 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/quadrule/bdf_set.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.8976952968970955, "lm_q1q2_score": 0.8276048914045928}} {"text": "function mean = truncated_normal_ab_mean ( mu, sigma, a, b )\n\n%*****************************************************************************80\n%\n%% TRUNCATED_NORMAL_AB_MEAN returns the mean of the truncated Normal PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 August 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real MU, SIGMA, the mean and standard deviation of the\n% parent Normal distribution.\n%\n% Input, real A, B, the lower and upper truncation limits.\n%\n% Output, real MEAN, the mean of the PDF.\n%\n alpha = ( a - mu ) / sigma;\n beta = ( b - mu ) / sigma;\n\n alpha_cdf = normal_01_cdf ( alpha );\n beta_cdf = normal_01_cdf ( beta );\n\n alpha_pdf = normal_01_pdf ( alpha );\n beta_pdf = normal_01_pdf ( beta );\n\n mean = mu + sigma * ( alpha_pdf - beta_pdf ) / ( beta_cdf - alpha_cdf );\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/truncated_normal_ab_mean.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9585377249197138, "lm_q2_score": 0.8633916152464017, "lm_q1q2_score": 0.8275934345930428}} {"text": "function value = r8vec_distance ( dim_num, v1, v2 )\n\n%*****************************************************************************80\n%\n%% R8VEC_DISTANCE returns the Euclidean distance between two R8VEC's.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 11 August 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the spatial dimension.\n%\n% Input, real V1(DIM_NUM), V2(DIM_NUM), the vectors.\n%\n% Output, real VALUE, the Euclidean distance\n% between the vectors.\n%\n value = sqrt ( sum ( ( v1(1:dim_num) - v2(1:dim_num) ).^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/r8lib/r8vec_distance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951698485603, "lm_q2_score": 0.8856314858927011, "lm_q1q2_score": 0.8275297826839433}} {"text": "function [U, S] = pca(X)\n%PCA Run principal component analysis on the dataset X\n% [U, S, X] = pca(X) computes eigenvectors of the covariance matrix of X\n% Returns the eigenvectors U, the eigenvalues (on diagonal) in S\n%\n\n% Useful values\n[m, n] = size(X);\n\n% You need to return the following variables correctly.\nU = zeros(n);\nS = zeros(n);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: You should first compute the covariance matrix. Then, you\n% should use the \"svd\" function to compute the eigenvectors\n% and eigenvalues of the covariance matrix. \n%\n% Note: When computing the covariance matrix, remember to divide by m (the\n% number of examples).\n%\nSigma=(1./m).*X'*X;\n[U, S, V]=svd(Sigma);\n\n\n\n\n\n% =========================================================================\n\nend\n", "meta": {"author": "yhyap", "repo": "machine-learning-coursera", "sha": "fb33f0ad54ff2104660c86b0d26456b15029a798", "save_path": "github-repos/MATLAB/yhyap-machine-learning-coursera", "path": "github-repos/MATLAB/yhyap-machine-learning-coursera/machine-learning-coursera-fb33f0ad54ff2104660c86b0d26456b15029a798/mlclass-ex7/pca.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951552333004, "lm_q2_score": 0.8856314632529872, "lm_q1q2_score": 0.82752974858577}} {"text": "function [Q, R] = gs_m(A)\n%GS_M Modified Gram-Schmidt QR factorization.\n% [Q, R] = GS_M(A) uses the modified Gram-Schmidt method to compute the\n% factorization A = Q*R for m-by-n A of full rank,\n% where Q is m-by-n with orthonormal columns and R is n-by-n.\n\n% Reference:\n% N. J. Higham, Accuracy and Stability of Numerical Algorithms,\n% Second edition, Society for Industrial and Applied Mathematics,\n% Philadelphia, PA, 2002; sec 19.8.\n\n[m, n] = size(A);\nQ = zeros(m,n);\nR = zeros(n);\n\nfor k=1:n\n R(k,k) = norm(A(:,k));\n Q(:,k) = A(:,k)/R(k,k);\n R(k,k+1:n) = Q(:,k)'*A(:,k+1:n);\n A(:,k+1:n) = A(:,k+1:n) - Q(:,k)*R(k,k+1:n);\nend\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/gs_m.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9504109798251322, "lm_q2_score": 0.8705972768020108, "lm_q1q2_score": 0.827425210878491}} {"text": "function cdf = gompertz_cdf ( x, a, b )\n\n%*****************************************************************************80\n%\n%% GOMPERTZ_CDF evaluates the Gompertz CDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Johnson, Kotz, and Balakrishnan,\n% Continuous Univariate Distributions, Volume 2, second edition,\n% Wiley, 1994, pages 25-26.\n%\n% Parameters:\n%\n% Input, real X, the argument of the CDF.\n%\n% Input, real A, B, the parameters of the PDF.\n% 1 < A, 0 < B.\n%\n% Output, real CDF, the value of the CDF.\n%\n if ( x <= 0.0 )\n cdf = 0.0;\n else\n cdf = 1.0 - exp ( - b * ( a^x - 1.0 ) / log ( a ) );\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/prob/gompertz_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9504109770159682, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.8274252004554234}} {"text": "function v = haar_2d ( u )\n\n%*****************************************************************************80\n%\n%% HAAR_2D computes the Haar transform of an array.\n%\n% Discussion:\n%\n% Thanks to Stephen Becker for pointing out that a previous version of\n% the haar_2d code was not inverted by haar_2d_inverse in cases where\n% M and N were not powers of 2, 05 March 2014.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 March 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real U(M,N), the vector to be transformed.\n%\n% Output, real V(M,N), the transformed vector.\n%\n [ m, n ] = size ( u );\n\n v = u;\n\n s = sqrt ( 2.0 );\n\n w = zeros ( m, n );\n%\n% Determine K, the largest power of 2 such that K <= M.\n%\n k = 1;\n while ( k * 2 <= m )\n k = k * 2;\n end\n%\n% Transform all columns.\n%\n while ( 1 < k )\n \n k = floor ( k / 2 );\n\n w( 1: k,:) = ( v(1:2:2*k-1,:) + v(2:2:2*k,:) ) / s;\n w(k+1:k+k,:) = ( v(1:2:2*k-1,:) - v(2:2:2*k,:) ) / s;\n\n v(1:2*k,:) = w(1:2*k,:);\n\n end\n%\n% Determine K, the largest power of 2 such that K <= N.\n%\n k = 1;\n while ( k * 2 <= n )\n k = k * 2;\n end\n%\n% Transform all rows.\n%\n while ( 1 < k )\n \n k = floor ( k / 2 );\n\n w(:, 1: k) = ( v(:,1:2:2*k-1) + v(:,2:2:2*k) ) / s;\n w(:,k+1:k+k) = ( v(:,1:2:2*k-1) - v(:,2:2:2*k) ) / s;\n\n v(:,1:2*k) = w(:,1:2*k);\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/haar/haar_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026595857204, "lm_q2_score": 0.9019206686206199, "lm_q1q2_score": 0.8273342280610259}} {"text": "function value = ellipse_area_2d ( r1, r2 )\n\n%*****************************************************************************80\n%\n%% ELLIPSE_AREA_2D returns the area of an ellipse in 2D.\n%\n% Discussion:\n%\n% The ellipse is defined as points (X,Y) such that\n%\n% ( ( X - XC ) / R1 )^2 + ( ( Y - YC ) / R2 )^2 <= 1\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 20 May 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R1, R2, the major and minor semi-axes.\n%\n% Output, real ELLIPSE_AREA_2D, the area of the ellipse.\n%\n value = pi * r1 * 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/geometry/ellipse_area_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533032291502, "lm_q2_score": 0.8872045981907006, "lm_q1q2_score": 0.8272768582230098}} {"text": "function pdf = gamma_pdf ( x, a, b, c )\n\n%*****************************************************************************80\n%\n%% GAMMA_PDF evaluates the Gamma PDF.\n%\n% Discussion:\n%\n% PDF(X)(A,B,C) = EXP ( - ( X - A ) / B ) * ( ( X - A ) / B )^(C-1)\n% / ( B * GAMMA ( C ) )\n%\n% GAMMA_PDF(A,B,C), where C is an integer, is the Erlang PDF.\n% GAMMA_PDF(A,B,1) is the Exponential PDF.\n% GAMMA_PDF(0,2,C/2) is the Chi Squared PDF with C degrees of freedom.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 11 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the PDF.\n% A <= X.\n%\n% Input, real A, B, C, the parameters of the PDF.\n% A controls the location of the peak; A is often chosen to be 0.0.\n% B is the \"scale\" parameter; 0.0 < B, and is often 1.0.\n% C is the \"shape\" parameter; 0.0 < C, and is often 1.0.\n%\n% Output, real PDF, the value of the PDF.\n%\n if ( x <= a )\n\n pdf = 0.0;\n\n else\n\n y = ( x - a ) / b;\n\n pdf = y^( c - 1.0 ) / ( b * gamma ( c ) * exp ( y ) );\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/prob/gamma_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.95598134762883, "lm_q2_score": 0.8652240721511739, "lm_q1q2_score": 0.8271380744959833}} {"text": "function xyz = sphere_cubed_ijk_to_xyz ( n, i, j, k )\n\n%*****************************************************************************80\n%\n%% SPHERE_CUBED_IJK_TO_XYZ: cubed sphere IJK to XYZ coordinates.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 10 October 2012\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 I, J, K, indices between 0 and N. Normally,\n% at least one of the indices should have the value 0 or N.\n%\n% Output, real XYZ(3,1), coordinates of the point.\n%\n if ( i == 0 )\n xc = -1.0;\n elseif ( i == n )\n xc = +1.0;\n else\n xc = tan ( ( 2 * i - n ) * 0.25 * pi / n );\n end\n\n if ( j == 0 )\n yc = -1.0;\n elseif ( j == n )\n yc = +1.0;\n else\n yc = tan ( ( 2 * j - n ) * 0.25 * pi / n );\n end\n\n if ( k == 0 )\n zc = -1.0;\n elseif ( k == n )\n zc = +1.0;\n else\n zc = tan ( ( 2 * k - n ) * 0.25 * pi / n );\n end\n\n xyzn = sqrt ( xc^2 + yc^2 + zc^2 );\n\n xyz = zeros ( 3, 1 );\n\n xyz(1) = xc / xyzn;\n xyz(2) = yc / xyzn;\n xyz(3) = zc / xyzn;\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_grid/sphere_cubed_ijk_to_xyz.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.8807970811069351, "lm_q1q2_score": 0.8270903197811067}} {"text": "function variance = r8row_variance ( m, n, x )\n\n%*****************************************************************************80\n%\n%% R8ROW_VARIANCE returns the variances of an R8ROW.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 30 September 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns in the array.\n%\n% Input, real X(M,N), the R8ROW whose row means are desired.\n%\n% Output, real VARIANCE(M), the variances of the rows of X.\n%\n for i = 1 : m\n\n mean = sum ( x(i,1:n) ) / n;\n\n variance(i) = sum ( ( x(i,1:n) - mean ).^2 );\n\n if ( 1 < n )\n variance(i) = variance(i) / ( n - 1 );\n else\n variance(i) = 0.0;\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/r8lib/r8row_variance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.939024825960626, "lm_q2_score": 0.880797071719777, "lm_q1q2_score": 0.8270903169782925}} {"text": "function [Qx,Qy]=CubicBezier1(Px,Py,n)\n% Input:\n% Px contains x-coordinates of control points [Px0,Px1,Px2,Px3]\n% Py contains y-coordinates of control points [Py0,Py1,Py2,Py3]\n% n is number of intervals (uniform parameterization)\n\n%Output:\n% Qx contains parameteric evaluted x-value\n% Qy contains parameteric evaluted y-value\n\n% Equation of Bezier Curve, utilizes Horner's rule for efficient computation.\n% Q(t)=(-P0 + 3*(P1-P2) + P3)*t^3 + 3*(P0-2*P1+P2)*t^2 + 3*(P1-P0)*t + Px0\n\n\nPx0=Px(1);\nPy0=Py(1);\nPx1=Px(2);\nPy1=Py(2);\nPx2=Px(3);\nPy2=Py(3);\nPx3=Px(4);\nPy3=Py(4);\n\ncx3=-Px0 + 3*(Px1-Px2) + Px3;\ncy3=-Py0 + 3*(Py1-Py2) + Py3;\ncx2=3*(Px0-2*Px1+Px2); \ncy2=3*(Py0-2*Py1+Py2);\ncx1=3*(Px1-Px0);\ncy1=3*(Py1-Py0);\ncx0=Px0;\ncy0=Py0;\n\ndt=1/n;\nQx(1)=Px0; % Qx at t=0\nQy(1)=Py0; % Qy at t=0\nfor i=1:n \n t=i*dt;\n Qx(i+1)=((cx3*t+cx2)*t+cx1)*t + cx0;\n Qy(i+1)=((cy3*t+cy2)*t+cy1)*t + cy0; \nend\n\n\n% % % --------------------------------\n% % % Author: Dr. Murtaza Khan\n% % % Email : drkhanmurtaza@gmail.com\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/6844-approximation-of-circle-using-cubic-bezier-curve/circleaproxbezier/CubicBezier1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075744568837, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.8270890041220174}} {"text": "% Minimum volume ellipsoid covering a finite set\n% Section 8.4.1, Boyd & Vandenberghe \"Convex Optimization\"\n% Almir Mutapcic - 10/05\n% (a figure is generated)\n%\n% Given a finite set of points x_i in R^2, we find the minimum volume\n% ellipsoid (described by matrix A and vector b) that covers all of\n% the points by solving the optimization problem:\n%\n% maximize log det A\n% subject to || A x_i + b || <= 1 for all i\n%\n% CVX cannot yet handle the logdet function, but this problem can be\n% represented in an equivalent way as follows:\n%\n% maximize det(A)^(1/n)\n% subject to || A x_i + b || <= 1 for all i\n%\n% The expression det(A)^(1/n) is SDP-representable, and is implemented\n% by the MATLAB function det_rootn().\n\n% Generate data\nx = [ 0.55 0.0;\n 0.25 0.35\n -0.2 0.2\n -0.25 -0.1\n -0.0 -0.3\n 0.4 -0.2 ]';\n[n,m] = size(x);\n\n% Create and solve the model\ncvx_begin\n variable A(n,n) symmetric\n variable b(n)\n maximize( det_rootn( A ) )\n subject to\n norms( A * x + b * ones( 1, m ), 2 ) <= 1;\ncvx_end\n\n% Plot the results\nclf\nnoangles = 200;\nangles = linspace( 0, 2 * pi, noangles );\nellipse = A \\ [ cos(angles) - b(1) ; sin(angles) - b(2) ];\nplot( x(1,:), x(2,:), 'ro', ellipse(1,:), ellipse(2,:), 'b-' );\naxis off\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/Ch08_geometric_probs/min_vol_elp_finite_set.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.957912273285902, "lm_q2_score": 0.8633916029436189, "lm_q1q2_score": 0.8270534131116809}} {"text": "function area = polygonArea(poly, varargin)\n%POLYGONAREA Compute the signed area of a polygon\n%\n% A = polygonArea(POINTS);\n% Compute area of a polygon defined by POINTS. POINTS is a N-by-2 array\n% of double containing coordinates of vertices.\n% \n% Vertices of the polygon are supposed to be oriented Counter-Clockwise\n% (CCW). In this case, the signed area is positive.\n% If vertices are oriented Clockwise (CW), the signed area is negative.\n%\n% If polygon is self-crossing, the result is undefined.\n%\n% Examples\n% % compute area of a simple shape\n% poly = [10 10;30 10;30 20;10 20];\n% area = polygonArea(poly)\n% area = \n% 200\n%\n% % compute area of CW polygon\n% area2 = polygonArea(poly(end:-1:1, :))\n% area2 = \n% -200\n%\n% % Computes area of a paper hen\n% x = [0 10 20 0 -10 -20 -10 -10 0];\n% y = [0 0 10 10 20 10 10 0 -10];\n% poly = [x' y'];\n% area = polygonArea(poly)\n% area =\n% 400\n%\n% % Area of unit square with 25% hole\n% pccw = [0 0; 1 0; 1 1; 0 1];\n% pcw = pccw([1 4 3 2], :) * .5 + .25;\n% polygonArea ([pccw; nan(1,2); pcw])\n% ans =\n% 0.75\n%\n% References\n% algo adapted from P. Bourke web page\n% http://paulbourke.net/geometry/polygonmesh/\n%\n% See also:\n% polygons2d, polygonCentroid, polygonSecondAreaMoments, triangleArea\n%\n\n% ---------\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 05/05/2004.\n%\n\n% HISTORY\n% 25/04/2005: add support for multiple polygons\n% 12/10/2007: update doc\n\n\n%% Process special cases\n\n% in case of polygon sets, computes the sum of polygon areas\nif iscell(poly)\n area = 0;\n for i = 1:length(poly)\n area = area + polygonArea(poly{i});\n end\n return;\nend\n\n% check there are enough points\nif size(poly, 1) < 2\n area = 0;\n return;\nend\n\n% case of polygons with holes -> computes the sum of areas\nif any(isnan(poly))\n area = sum(polygonArea(splitPolygons(poly)));\n return;\nend\n\n\n%% Process single polygons or single rings\n\n% extract coordinates\nif nargin == 1\n % polygon given as N-by-2 array\n px = poly(:, 1);\n py = poly(:, 2);\n \nelseif nargin == 2\n % poylgon given as two N-by-1 arrays\n px = poly;\n py = varargin{1};\nend\n\n% indices of next vertices\nN = length(px);\niNext = [2:N 1];\n\n% compute area (vectorized version)\narea = sum(px .* py(iNext) - px(iNext) .* py) / 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/polygons2d/polygonArea.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692238, "lm_q2_score": 0.891811041124754, "lm_q1q2_score": 0.8270328315625197}} {"text": "function f=shah(L,a);\n%SHAH Discrete Shah-distribution\n% Usage: f=shah(L,a);\n% \n% `shah(L,a)` computes the discrete, normalized Shah-distribution of\n% length *L* with a distance of *a* between the spikes.\n%\n% The Shah distribution is defined by \n%\n% .. f(n*a+1)=1/sqrt(L/a) \n%\n% .. math:: f(n\\cdot a+1)=\\frac{1}{\\sqrt(L/a)} \n%\n% for integer *n*, otherwise *f* is zero.\n% \n% This is also known as an impulse train or as the comb function, because\n% the shape of the function resembles a comb. It is the sum of unit\n% impulses ('diracs') with the distance *a*.\n% \n% If *a* divides *L*, then the |dft| of `shah(L,a)` is `shah(L,L/a)`.\n% \n% The Shah function has an extremely bad time-frequency localization.\n% It does not generate a Gabor frame for any *L* and *a*.\n%\n% Examples:\n% ---------\n%\n% A simple spectrogram of the Shah function (includes the negative\n% frequencies to display the whole TF-plane):::\n%\n% sgram(shah(256,16),'dynrange',80,'nf')\n%\n \n% AUTHOR : Peter L. Søndergaard\n% TESTING: OK\n% REFERENCE: OK\n\nif nargin~=2\n error('Wrong number of input parameters.');\nend;\n\n%if mod(L,a)~=0\n% error('a must divide L.');\n%end;\n\nf=zeros(L,1);\n\nf(1:a:L)=1/sqrt(L/a);\n\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/fourier/shah.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067179697694, "lm_q2_score": 0.8774767922879692, "lm_q1q2_score": 0.8270277715939749}} {"text": "function mi = imMutualInformation(img1, img2)\n%IMMUTUALINFORMATION Mutual information between two images\n%\n% MI = imMutualInformation(IMG1, IMG2)\n% Computes the mutual information between two images. \n% The mutual information can be related to entropy and joint entropy:\n% MI = H1 + H2 - H12\n% where H1 and H2 are the entropies computed on images IMG1 and IMG2, and\n% H12 is the joint entropy of images IMG1 and IMG2.\n%\n% The mutual information between two independant images corresponds to\n% the sum of the entropies computed for each image. The mutual\n% information of an image with itself equals the entropy of this image.\n% \n% Example\n% % compute mutual information between an image and a shifted copy of\n% % itself\n% img = imread('cameraman.tif');\n% img2 = circshift(img, [2 3]);\n% MI = imMutualInformation(img, img2)\n% img3 = circshift(img, [5, 7]);\n% MI3 = imMutualInformation(img, img2)\n%\n% % Check that we get same results by computing entropies (could be wrong\n% % when computed on double images)\n% img1 = imread('rice.png');\n% img2 = circshift(img1, [3, 4]);\n% imMutualInformation(img1, img2)\n% ans =\n% 1.0551\n% h1 = imEntropy(img1);\n% h2 = imEntropy(img2);\n% h12 = imJointEntropy(img1, img2);\n% h1 + h2 - h12\n% ans =\n% 1.0551\n\n% See also\n% imJointEntropy, imJointHistogram, imEntropy\n%\n% ------\n% Author: David Legland\n% e-mail: david.legland@grignon.inra.fr\n% Created: 2010-08-26, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2010 INRA - Cepia Software Platform.\n\n% joint histogram, and reduced hisograms\nhist12 = imJointHistogram(img1, img2);\nhist1 = sum(hist12, 2);\nhist2 = sum(hist12, 1);\n\n% normalisation of histograms\nhist12 = hist12(hist12 > 0) / sum(hist12(:));\nhist1 = hist1(hist1 > 0) / sum(hist1(:));\nhist2 = hist2(hist2 > 0) / sum(hist2(:));\n\n% entropy of each image\nh12 = -sum(hist12 .* log2(hist12));\nh1 = -sum(hist1 .* log2(hist1));\nh2 = -sum(hist2 .* log2(hist2));\n\n% compute mutual information\nmi = h1 + h2 - h12;\n", "meta": {"author": "mattools", "repo": "matImage", "sha": "94d892c7beac0db32daadf2646ce37f58e894caf", "save_path": "github-repos/MATLAB/mattools-matImage", "path": "github-repos/MATLAB/mattools-matImage/matImage-94d892c7beac0db32daadf2646ce37f58e894caf/matImage/imMeasures/imMutualInformation.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632261523028, "lm_q2_score": 0.8688267898240861, "lm_q1q2_score": 0.8270042711295034}} {"text": "function [xn, xmean, xstd] = normdata(x,xmean,xstd)\n%NORMDATA Normalize input to zero mean and unit variance\n%\n% Description\n% [XN, XMEAN, XSTD] = NORMDATA(X) normalizes X to zero mean and\n% unit variance. Returns normalized XN, mean of X XMEAN and\n% standard deviance of X XSTD.\n% \n% XN = NORMDATA(X,XMEAN,XSTD) normalizes X using precomputed\n% XMEAN and XSTD.\n%\n% See also DENORMDATA\n%\n% Copyright (c) 2010 Aki Vehtari\n\n% This software is distributed under the GNU General Public \n% License (version 3 or later); please refer to the file \n% License.txt, included with the software, for details.\n\n if nargin<=1\n xmean=nanmean(x);\n xstd=nanstd(x);\n end\n xn=bsxfun(@rdivide,bsxfun(@minus,x,xmean),xstd);\n", "meta": {"author": "gpstuff-dev", "repo": "gpstuff", "sha": "114937ec0a201306489a66cbba38283e722fb998", "save_path": "github-repos/MATLAB/gpstuff-dev-gpstuff", "path": "github-repos/MATLAB/gpstuff-dev-gpstuff/gpstuff-114937ec0a201306489a66cbba38283e722fb998/misc/normdata.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8991213826762113, "lm_q1q2_score": 0.826870264200428}} {"text": "function r = normal_dataset ( m, n, seed, mu, a )\n\n%*****************************************************************************80\n%\n%% NORMAL_DATASET generates a multivariate normal dataset and writes it to a file.\n%\n% Usage:\n%\n% x = normal_dataset ( m, n, seed, mu, a )\n%\n% where\n%\n% * M the spatial dimension;\n% * N the number of points to generate;\n% * SEED the seed, a positive integer;\n% * MU is the mean vector of dimension M;\n% * A is the MxM positive definite symmetric variance-covariance matrix;\n% * R is the M by N array created.\n%\n% The command creates an M by N multivariate normal dataset and writes \n% it to the file \"normal_M_N.txt\".\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 08 December 2009\n%\n% Author:\n%\n% John Burkardt\n%\n timestamp ( );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'NORMAL_DATASET\\n' );\n fprintf ( 1, ' MATLAB version\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Generate a multivariate normal random dataset.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The program requests input values from the user:\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' * M, the spatial dimension,\\n' );\n fprintf ( 1, ' * N, the number of points to generate,\\n' );\n fprintf ( 1, ' * SEED, a seed for the random number generator.\\n' );\n fprintf ( 1, ' * MU, the mean vector of length M.\\n' );\n fprintf ( 1, ' * A, the MxM positive definite symmetric variance-covariance matrix.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The program generates the data and writes it to the file\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' normal_M_N.txt\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' where \"M\" and \"N\" are the numeric values.\\n' );\n%\n% Get the spatial dimension.\n%\n if ( nargin < 1 )\n fprintf ( 1, '\\n' );\n m = input ( ' Enter the spatial dimension M: ' );\n else\n m = str2num ( m );\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Spatial dimension M = %d\\n', m );\n%\n% Get the number of points.\n%\n if ( nargin < 2 )\n fprintf ( 1, '\\n' );\n n = input ( ' Enter the number of points N: ' );\n else\n n = str2num ( n );\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Number of points N = %d\\n', n );\n%\n% Get the seed.\n%\n if ( nargin < 3 )\n fprintf ( 1, '\\n' );\n seed = input ( ' Enter the seed: ' );\n else\n seed = str2num ( seed );\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The seed = %d\\n', seed );\n%\n% Get the mean vector.\n%\n if ( nargin < 4 )\n fprintf ( 1, '\\n' );\n mu(1:m) = input ( ' Enter the mean vector MU' );\n else\n mu(1:m) = str2num ( mu(1:m) );\n end\n\n r8vec_print ( m, mu, ' The mean vector MU:' )\n%\n% Get the variance-covariance matrix A.\n%\n if ( nargin < 5 )\n fprintf ( 1, '\\n' );\n a(1:m,1:m) = input ( ' Enter the variance-covariance matrix A' );\n else\n a(1:m,1:m) = str2num ( a(1:m,1:m) );\n end\n\n r8mat_print ( m, m, a, ' The variance-covariance matrix A:' )\n%\n% Compute the data.\n%\n r = multinormal_sample ( m, n, a, mu, seed );\n%\n% Write it to a file.\n%\n output_filename = ...\n strcat ( 'normal_', num2str ( m ), '_', num2str ( n ), '.txt' );\n\n r8mat_write ( output_filename, m, n, r );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The data was written to the file \"%s\".\\n', ...\n output_filename );\n%\n% Terminate.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'NORMAL_DATASET:\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n\n fprintf ( 1, '\\n' );\n timestamp ( );\n\n return\nend\nfunction [ x, seed ] = multinormal_sample ( m, n, a, mu, seed )\n\n%*****************************************************************************80\n%\n%% MULTINORMAL_SAMPLE samples a multivariate normal distribution.\n%\n% Discussion:\n%\n% The multivariate normal distribution for the M dimensional vector X\n% has the form:\n%\n% pdf(X) = (2*pi*det(A))**(-M/2) * exp(-0.5*(X-MU)'*inverse(A)*(X-MU))\n%\n% where MU is the mean vector, and A is a positive definite symmetric\n% matrix called the variance-covariance matrix.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 08 December 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, the dimension of the space.\n%\n% Input, integer N, the number of points.\n%\n% Input, real A(M,M), the variance-covariance \n% matrix. A must be positive definite symmetric.\n%\n% Input, real MU(M), the mean vector.\n%\n% Input, integer SEED, the random number seed.\n%\n% Output, real X(M), the points.\n%\n% Output, integer SEED, the random number seed.\n%\n\n%\n% Compute the upper triangular Cholesky factor R of the variance-covariance\n% matrix.\n%\n [ r, info ] = r8po_fa ( m, a );\n\n if ( info ~= 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'MULTINORMAL_SAMPLE - Fatal error!\\n' );\n fprintf ( 1, ...\n ' The variance-covariance matrix is not positive definite symmetric.\\n' );\n error ( 'MULTINORMAL_SAMPLE - Fatal error!' );\n end\n%\n% Get an MxN vector of samples of the 1D normal distribution with mean 0\n% and variance 1. \n%\n [ x(1:m*n), seed ] = r8vec_normal_01 ( m*n, seed );\n%\n% Reshape the vector to an MxN matrix.\n%\n x = reshape ( x, m, n );\n%\n% Compute MU + R' * X.\n%\n for j = 1 : n\n x(1:m,j) = mu(1:m)' + r(1:m,1:m)' * x(1:m,j);\n end\n\n return\nend\nfunction r8mat_print ( m, n, a, title )\n\n%*****************************************************************************80\n%\n%% R8MAT_PRINT prints an R8MAT.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 06 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, the number of rows in A.\n%\n% Input, integer N, the number of columns in A.\n%\n% Input, real A(M,N), the matrix.\n%\n% Input, string TITLE, a title to be printed.\n%\n r8mat_print_some ( m, n, a, 1, 1, m, n, title );\n\n return\nend\nfunction r8mat_print_some ( m, n, a, ilo, jlo, ihi, jhi, title )\n\n%*****************************************************************************80\n%\n%% R8MAT_PRINT_SOME prints out a portion of an R8MAT.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 10 September 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns of the matrix.\n%\n% Input, real A(M,N), an M by N matrix to be printed.\n%\n% Input, integer ILO, JLO, the first row and column to print.\n%\n% Input, integer IHI, JHI, the last row and column to print.\n%\n% Input, string TITLE, a title.\n%\n incx = 5;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, '%s\\n', title );\n\n for j2lo = max ( jlo, 1 ): incx : min ( jhi, n )\n\n j2hi = j2lo + incx - 1;\n j2hi = min ( j2hi, n );\n j2hi = min ( j2hi, jhi );\n \n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Col: ' );\n\n for j = j2lo : j2hi\n fprintf ( 1, '%7d ', j );\n end\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Row\\n' );\n\n i2lo = max ( ilo, 1 );\n i2hi = min ( ihi, m );\n\n for i = i2lo : i2hi\n\n fprintf ( 1, '%7d ', i );\n \n for j = j2lo : j2hi\n fprintf ( 1, '%12g ', a(i,j) );\n end\n\n fprintf ( 1, '\\n' );\n\n end\n\n end\n\n return\nend\nfunction r8mat_write ( output_filename, m, n, table )\n\n%*****************************************************************************80\n%\n%% R8MAT_WRITE writes an R8MAT file.\n%\n% Discussion:\n%\n% An R8MAT is an array of R8's.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 11 August 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, string OUTPUT_FILENAME, the output filename.\n%\n% Input, integer M, the spatial dimension.\n%\n% Input, integer N, the number of points.\n%\n% Input, real TABLE(M,N), the points.\n%\n\n%\n% Open the file.\n%\n output_unit = fopen ( output_filename, 'wt' );\n\n if ( output_unit < 0 ) \n fprintf ( 1, '\\n' );\n fprintf ( 1, 'R8MAT_WRITE - Error!\\n' );\n fprintf ( 1, ' Could not open the output file.\\n' );\n error ( 'R8MAT_WRITE - Error!' );\n end\n%\n% Write the data.\n%\n% For smaller data files, and less precision, try:\n%\n% fprintf ( output_unit, ' %14.6f', table(i,j) );\n%\n for j = 1 : n\n for i = 1 : m\n fprintf ( output_unit, ' %24.16f', table(i,j) );\n end\n fprintf ( output_unit, '\\n' );\n end\n%\n% Close the file.\n%\n fclose ( output_unit );\n\n return\nend\nfunction [ r, info ] = r8po_fa ( n, a )\n\n%*****************************************************************************80\n%\n%% R8PO_FA factors a R8PO matrix.\n%\n% Discussion:\n%\n% The R8PO storage format is appropriate for a symmetric positive definite \n% matrix and its inverse. (The Cholesky factor of a R8PO matrix is an\n% upper triangular matrix, so it will be in R8GE storage format.)\n%\n% Only the diagonal and upper triangle of the square array are used.\n% This same storage scheme is used when the matrix is factored by\n% R8PO_FA, or inverted by R8PO_INVERSE. For clarity, the lower triangle\n% is set to zero.\n%\n% The positive definite symmetric matrix A has a Cholesky factorization\n% of the form:\n%\n% A = R' * R\n%\n% where R is an upper triangular matrix with positive elements on\n% its diagonal. This routine overwrites the matrix A with its\n% factor R.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 20 February 2004\n%\n% Author:\n%\n% MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Dongarra, Bunch, Moler, Stewart,\n% LINPACK User's Guide,\n% SIAM, 1979.\n%\n% Parameters:\n%\n% Input, integer N, the order of the matrix.\n%\n% Input, real A(N,N), the matrix in R8PO storage.\n%\n% Output, real R(N,N), the Cholesky factor R in R8GE storage.\n%\n% Output, integer INFO, error flag.\n% 0, normal return.\n% K, error condition. The principal minor of order K is not\n% positive definite, and the factorization was not completed.\n%\n r(1:n,1:n) = a(1:n,1:n);\n\n for j = 1 : n\n\n for k = 1 : j - 1\n t = 0.0;\n for i = 1 : k-1\n t = t + r(i,k) * r(i,j);\n end\n r(k,j) = ( r(k,j) - t ) / r(k,k);\n end\n\n t = 0.0;\n for i = 1 : j - 1\n t = t + r(i,j)^2;\n end\n\n s = r(j,j) - t;\n\n if ( s <= 0.0 )\n info = j;\n return;\n end\n\n r(j,j) = sqrt ( s );\n\n end\n\n info = 0;\n%\n% Since the Cholesky factor is stored in R8GE format, be sure to\n% zero out the lower triangle.\n%\n for i = 1 : n\n for j = 1 : i-1\n r(i,j) = 0.0;\n end\n end\n\n return\nend\nfunction [ x, seed ] = r8vec_normal_01 ( n, seed )\n\n%*****************************************************************************80\n%\n%% R8VEC_NORMAL_01 returns a unit pseudonormal R8VEC.\n%\n% Discussion:\n%\n% The standard normal probability distribution function (PDF) has\n% mean 0 and standard deviation 1.\n%\n% This routine can generate a vector of values on one call. It\n% has the feature that it should provide the same results\n% in the same order no matter how we break up the task.\n%\n% Before calling this routine, the user may call RANDOM_SEED\n% in order to set the seed of the random number generator.\n%\n% The Box-Muller method is used, which is efficient, but\n% generates an even number of values each time. On any call\n% to this routine, an even number of new values are generated.\n% Depending on the situation, one value may be left over.\n% In that case, it is saved for the next call.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 17 July 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of values desired. If N is negative,\n% then the code will flush its internal memory; in particular,\n% if there is a saved value to be used on the next call, it is\n% instead discarded. This is useful if the user has reset the\n% random number seed, for instance.\n%\n% Input, integer SEED, a seed for the random number generator.\n%\n% Output, real X(N), a sample of the standard normal PDF.\n%\n% Output, integer SEED, an updated seed for the random number generator.\n%\n% Local parameters:\n%\n% Local, integer MADE, records the number of values that have\n% been computed. On input with negative N, this value overwrites\n% the return value of N, so the user can get an accounting of\n% how much work has been done.\n%\n% Local, real R(N+1), is used to store some uniform random values.\n% Its dimension is N+1, but really it is only needed to be the\n% smallest even number greater than or equal to N.\n%\n% Local, integer SAVED, is 0 or 1 depending on whether there is a\n% single saved value left over from the previous call.\n%\n% Local, integer X_LO_INDEX, X_HI_INDEX, records the range of entries of\n% X that we need to compute. This starts off as 1:N, but is adjusted\n% if we have a saved value that can be immediately stored in X(1),\n% and so on.\n%\n% Local, real Y, the value saved from the previous call, if\n% SAVED is 1.\n%\n persistent made;\n persistent saved;\n persistent y;\n%\n% I'd like to allow the user to reset the internal data.\n% But this won't work properly if we have a saved value Y.\n% I'm making a crock option that allows the user to signal\n% explicitly that any internal memory should be flushed,\n% by passing in a negative value for N.\n%\n if ( n < 0 )\n made = 0;\n saved = 0;\n y = 0.0;\n x = [];\n return\n elseif ( n == 0 )\n x = [];\n return\n end\n%\n% Record the range of X we need to fill in.\n%\n x_lo_index = 1;\n x_hi_index = n;\n%\n% Use up the old value, if we have it.\n%\n if ( saved == 1 )\n x(1) = y;\n saved = 0;\n x_lo_index = 2;\n end\n%\n% Maybe we don't need any more values.\n%\n if ( x_hi_index - x_lo_index + 1 == 0 )\n%\n% If we need just one new value, do that here to avoid null arrays.\n%\n elseif ( x_hi_index - x_lo_index + 1 == 1 )\n\n [ r, seed ] = r8vec_uniform_01 ( 2, seed );\n\n x(x_hi_index) = ...\n sqrt ( -2.0 * log ( r(1) ) ) * cos ( 2.0 * pi * r(2) );\n y = sqrt ( -2.0 * log ( r(1) ) ) * sin ( 2.0 * pi * r(2) );\n\n saved = 1;\n\n made = made + 2;\n%\n% If we require an even number of values, that's easy.\n%\n elseif ( mod ( x_hi_index - x_lo_index + 1, 2 ) == 0 )\n\n m = floor ( ( x_hi_index - x_lo_index + 1 ) / 2 );\n\n [ r, seed ] = r8vec_uniform_01 ( 2*m, seed );\n\n x(x_lo_index:2:x_hi_index-1) = ...\n sqrt ( -2.0 * log ( r(1:2:2*m-1) ) ) ...\n .* cos ( 2.0 * pi * r(2:2:2*m) );\n\n x(x_lo_index+1:2:x_hi_index) = ...\n sqrt ( -2.0 * log ( r(1:2:2*m-1) ) ) ...\n .* sin ( 2.0 * pi * r(2:2:2*m) );\n\n made = made + x_hi_index - x_lo_index + 1;\n%\n% If we require an odd number of values, we generate an even number,\n% and handle the last pair specially, storing one in X(N), and\n% saving the other for later.\n%\n else\n\n x_hi_index = x_hi_index - 1;\n\n m = floor ( ( x_hi_index - x_lo_index + 1 ) / 2 ) + 1;\n\n [ r, seed ] = r8vec_uniform_01 ( 2*m, seed );\n\n x(x_lo_index:2:x_hi_index-1) = ...\n sqrt ( -2.0 * log ( r(1:2:2*m-3) ) ) ...\n .* cos ( 2.0 * pi * r(2:2:2*m-2) );\n\n x(x_lo_index+1:2:x_hi_index) = ...\n sqrt ( -2.0 * log ( r(1:2:2*m-3) ) ) ...\n .* sin ( 2.0 * pi * r(2:2:2*m-2) );\n\n x(n) = sqrt ( -2.0 * log ( r(2*m-1) ) ) ...\n * cos ( 2.0 * pi * r(2*m) );\n\n y = sqrt ( -2.0 * log ( r(2*m-1) ) ) ...\n * sin ( 2.0 * pi * r(2*m) );\n\n saved = 1;\n\n made = made + x_hi_index - x_lo_index + 2;\n\n end\n\n return\nend\nfunction r8vec_print ( n, a, title )\n\n%*****************************************************************************80\n%\n%% R8VEC_PRINT prints a real vector.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 January 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the dimension of the vector.\n%\n% Input, real A(N), the vector to be printed.\n%\n% Input, string TITLE, a title.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, '%s\\n', title );\n fprintf ( 1, '\\n' );\n for i = 1 : n\n fprintf ( 1, '%6d %12f\\n', i, a(i) );\n end\n\n return\nend\nfunction [ r, seed ] = r8vec_uniform_01 ( n, seed )\n\n%*****************************************************************************80\n%\n%% R8VEC_UNIFORM_01 returns a unit pseudorandom R8VEC.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 21 September 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Paul Bratley, Bennett Fox, Linus Schrage,\n% A Guide to Simulation,\n% Second Edition,\n% Springer, 1987,\n% ISBN: 0387964673,\n% LC: QA76.9.C65.B73.\n%\n% Bennett Fox,\n% Algorithm 647:\n% Implementation and Relative Efficiency of Quasirandom\n% Sequence Generators,\n% ACM Transactions on Mathematical Software,\n% Volume 12, Number 4, December 1986, pages 362-376.\n%\n% Pierre L'Ecuyer,\n% Random Number Generation,\n% in Handbook of Simulation,\n% edited by Jerry Banks,\n% Wiley, 1998,\n% ISBN: 0471134031,\n% LC: T57.62.H37.\n%\n% Peter Lewis, Allen Goodman, James Miller,\n% A Pseudo-Random Number Generator for the System/360,\n% IBM Systems Journal,\n% Volume 8, Number 2, 1969, pages 136-143.\n%\n% Parameters:\n%\n% Input, integer N, the number of entries in the vector.\n%\n% Input, integer SEED, a seed for the random number generator.\n%\n% Output, real R(N), the vector of pseudorandom values.\n%\n% Output, integer SEED, an updated seed for the random number generator.\n%\n i4_huge = 2147483647;\n\n if ( seed == 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'R8VEC_UNIFORM_01 - Fatal error!\\n' );\n fprintf ( 1, ' Input SEED = 0!\\n' );\n error ( 'R8VEC_UNIFORM_01 - Fatal error!' );\n end\n\n r = zeros ( n, 1 );\n \n for i = 1 : n\n\n k = floor ( seed / 127773 );\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836;\n\n if ( seed < 0 )\n seed = seed + i4_huge;\n end\n\n r(i) = seed * 4.656612875E-10;\n\n end\n\n return\nend\nfunction timestamp ( )\n\n%*****************************************************************************80\n%\n%% TIMESTAMP prints the current YMDHMS date as a timestamp.\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 t = now;\n c = datevec ( t );\n s = datestr ( c, 0 );\n fprintf ( 1, '%s\\n', s );\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/normal_dataset/normal_dataset.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.949669373100424, "lm_q2_score": 0.8705972600147106, "lm_q1q2_score": 0.826779554141117}} {"text": "% IM = mkSine(SIZE, PERIOD, DIRECTION, AMPLITUDE, PHASE, ORIGIN)\n% or\n% IM = mkSine(SIZE, FREQ, AMPLITUDE, PHASE, ORIGIN)\n% \n% Compute a matrix of dimension SIZE (a [Y X] 2-vector, or a scalar)\n% containing samples of a 2D sinusoid, with given PERIOD (in pixels),\n% DIRECTION (radians, CW from X-axis, default = 0), AMPLITUDE (default\n% = 1), and PHASE (radians, relative to ORIGIN, default = 0). ORIGIN\n% defaults to the center of the image.\n% \n% In the second form, FREQ is a 2-vector of frequencies (radians/pixel).\n\n% Eero Simoncelli, 6/96.\n\nfunction [res] = mkSine(sz, per_freq, dir_amp, amp_phase, phase_orig, orig)\n\n%------------------------------------------------------------\n%% OPTIONAL ARGS:\n\nif (prod(size(per_freq)) == 2)\n frequency = norm(per_freq);\n direction = atan2(per_freq(1),per_freq(2));\n if (exist('dir_amp') == 1)\n amplitude = dir_amp;\n else\n amplitude = 1;\n end\n if (exist('amp_phase') == 1)\n phase = amp_phase;\n else\n phase = 0;\n end\n if (exist('phase_orig') == 1)\n origin = phase_orig;\n end\n if (exist('orig') == 1)\n error('Too many arguments for (second form) of mkSine');\n end\nelse\n frequency = 2*pi/per_freq;\n if (exist('dir_amp') == 1)\n direction = dir_amp;\n else\n direction = 0;\n end\n if (exist('amp_phase') == 1)\n amplitude = amp_phase;\n else\n amplitude = 1;\n end\n if (exist('phase_orig') == 1)\n phase = phase_orig;\n else\n phase = 0;\n end\n if (exist('orig') == 1)\n origin = orig;\n end\nend\n\n%------------------------------------------------------------\n \nif (exist('origin') == 1)\n res = amplitude*sin(mkRamp(sz, direction, frequency, phase, origin));\nelse\n res = amplitude*sin(mkRamp(sz, direction, frequency, phase));\nend\n", "meta": {"author": "jbhuang0604", "repo": "SelfExSR", "sha": "8f6dd8c1d20cb7e8792a7177b4f6fd677633f598", "save_path": "github-repos/MATLAB/jbhuang0604-SelfExSR", "path": "github-repos/MATLAB/jbhuang0604-SelfExSR/SelfExSR-8f6dd8c1d20cb7e8792a7177b4f6fd677633f598/quant_eval/ifcvec_release/matlabPyrTools/mkSine.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012655937034, "lm_q2_score": 0.8740772466456689, "lm_q1q2_score": 0.8267033661041332}} {"text": "% IM = mkAngle(SIZE, PHASE, ORIGIN)\n%\n% Compute a matrix of dimension SIZE (a [Y X] 2-vector, or a scalar)\n% containing samples of the polar angle (in radians, CW from the\n% X-axis, ranging from -pi to pi), relative to angle PHASE (default =\n% 0), about ORIGIN pixel (default = (size+1)/2).\n\n% Eero Simoncelli, 6/96.\n\nfunction [res] = mkAngle(sz, phase, origin)\n\nsz = sz(:);\nif (size(sz,1) == 1)\n sz = [sz,sz];\nend\n\n% -----------------------------------------------------------------\n% OPTIONAL args:\n\nif (exist('origin') ~= 1)\n origin = (sz+1)/2;\nend\n\n% -----------------------------------------------------------------\n\n[xramp,yramp] = meshgrid( [1:sz(2)]-origin(2), [1:sz(1)]-origin(1) );\n\nres = atan2(yramp,xramp);\n\nif (exist('phase') == 1)\n res = mod(res+(pi-phase),2*pi)-pi;\nend\n", "meta": {"author": "jbhuang0604", "repo": "SelfExSR", "sha": "8f6dd8c1d20cb7e8792a7177b4f6fd677633f598", "save_path": "github-repos/MATLAB/jbhuang0604-SelfExSR", "path": "github-repos/MATLAB/jbhuang0604-SelfExSR/SelfExSR-8f6dd8c1d20cb7e8792a7177b4f6fd677633f598/quant_eval/ifcvec_release/matlabPyrTools/mkAngle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9637799410139922, "lm_q2_score": 0.8577681031721324, "lm_q1q2_score": 0.8266996918789218}} {"text": "function center = polylineCentroid(varargin)\n%POLYLINECENTROID Computes the centroid of a curve defined by a series of points.\n%\n% PT = polylineCentroid(POINTS);\n% Computes center of mass of a polyline defined by POINTS. POINTS is a\n% N-by-D array of double, representing a set of N points in a\n% D-dimensional space.\n%\n% PT = polylineCentroid(PTX, PTY);\n% PT = polylineCentroid(PTX, PTY, PTZ);\n% Specifies points as separate column vectors\n%\n% PT = polylineCentroid(..., TYPE);\n% Specifies if the last point is connected to the first one. TYPE can be\n% either 'closed' or 'open'.\n%\n% Example\n% poly = [0 0;10 0;10 10;20 10];\n% polylineCentroid(poly)\n% ans = \n% [10 5]\n%\n% See also \n% polygons2d, centroid, polygonCentroid, polylineLength\n%\n\n% ------\n% Author: David Legland \n% E-mail: david.legland@inrae.fr\n% Created: 2006-05-22\n% Copyright 2006-2022 INRA - TPV URPOI - BIA IMASTE\n\n%% process input arguments\n\n% check whether the curve is closed\nclosed = false;\nvar = varargin{end};\nif ischar(var)\n if strcmpi(var, 'closed')\n closed = true;\n end\n % remove last argument\n varargin(end) = [];\nend\n\n% extract point coordinates\nif length(varargin)==1\n points = varargin{1};\nelseif length(varargin)==2\n points = [varargin{1} varargin{2}];\nend\n\n\n%% Main computation\n\n% compute centers and lengths composing the curve\nif closed\n centers = (points + points([2:end 1],:))/2;\n lengths = sqrt(sum(diff(points([1:end 1],:)).^2, 2));\nelse\n centers = (points(1:end-1,:) + points(2:end,:))/2;\n lengths = sqrt(sum(diff(points).^2, 2));\nend\n\n% centroid of edge centers weighted by edge length\n%weigths = repmat(lengths/sum(lengths), [1 size(points, 2)]); \ncenter = sum(centers .* repmat(lengths, [1 size(points, 2)]), 1) / sum(lengths);\n\n", "meta": {"author": "mattools", "repo": "matGeom", "sha": "1fd2c937064be1ee1f4fd09fbfdf96145ebe5271", "save_path": "github-repos/MATLAB/mattools-matGeom", "path": "github-repos/MATLAB/mattools-matGeom/matGeom-1fd2c937064be1ee1f4fd09fbfdf96145ebe5271/matGeom/polygons2d/polylineCentroid.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8856314662716159, "lm_q1q2_score": 0.8266756978351583}} {"text": "function cdf = sech_cdf ( x, a, b )\n\n%*****************************************************************************80\n%\n%% SECH_CDF evaluates the Hyperbolic Secant CDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 20 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the PDF.\n%\n% Input, real A, B, the parameter of the PDF.\n% 0.0 < B.\n%\n% Output, real CDF, the value of the CDF.\n%\n y = ( x - a ) / b;\n\n cdf = 2.0 * atan ( exp ( y ) ) / pi;\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/sech_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308091776495, "lm_q2_score": 0.885631466271616, "lm_q1q2_score": 0.8266756961951028}} {"text": "function [xn, xmean, xstd] = normdata(x,xmean,xstd)\n%NORMDATA Normalize input to zero mean and unit variance\n%\n% Description\n% [XN, XMEAN, XSTD] = NORMDATA(X) normalizes X to zero mean and\n% unit variance. Returns normalized XN, mean of X XMEAN and\n% standard deviance of X XSTD.\n% \n% XN = NORMDATA(X,XMEAN,XSTD) normalizes X using precomputed\n% XMEAN and XSTD.\n%\n% See also DENORMDATA\n%\n \n% Copyright (c) 2010 Aki Vehtari\n\n% This software is distributed under the GNU General Public \n% License (version 3 or later); please refer to the file \n% License.txt, included with the software, for details.\n\n if nargin<=1\n xmean=nanmean(x);\n xstd=nanstd(x);\n end\n xn=bsxfun(@rdivide,bsxfun(@minus,x,xmean),xstd);\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/dmlt/external/gpstuff/misc/normdata.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.8976953016868439, "lm_q1q2_score": 0.8265885619865051}} {"text": "function [FisoInd]=faceIsotropyIndex(F,V)\n%% function for computing triangular faces isotropy index. \n% This is an index of the \"regularity\" of the triangle. Equilateral triangle (perfectly regular) \n%\n% INPUTS:\n% * F: nFaces-by-3 array representing the list of vertices for triangular faces\n% * V: nVertices-by-3 array representing the 3d positions of the vertices of F in the reference positions\n%\n% OUTPUTS: \n% * FisoInd: isotropy index for each face. value of 1 means perfectly\n% equilateral. value of 0 means vertices are aligned (on a line)\n%\n%From the paper: Surface-Marker Cluster Design Criteria for 3-D Bone Movement Reconstruction (1997)\n% Aurelio Cappozzo, Angelo Cappello, Ugo Della Croce, and Francesco Pensalfini\n%%\n\nFisoInd=zeros(size(F,1),1);\nfor iface=1:size(F,1)\n \n x1=V(F(iface,1),:)';\n x2=V(F(iface,2),:)';\n x3=V(F(iface,3),:)';\n \n if any(any(isnan([x1 x2 x3]))) % if any nan, iso index=nan\n FisoInd(iface)=NaN;\n else\n xa=(x1+x2+x3)/3;\n X=[x1-xa,x2-xa,x3-xa]; %cluster position model\n K=X*X'/3;\n Keig=real(eig(K)); %eigenvalues of X\n FisoInd(iface)=2*Keig(2)/(Keig(2)+Keig(3)); % isotropy index\n end\nend\n\nend\n\n \n%% \n% MultiDIC: a MATLAB Toolbox for Multi-View 3D Digital Image Correlation\n% \n% License: \n% \n% Copyright (C) 2018 Dana Solav\n% \n% If you use the toolbox/function for your research, please cite our paper:\n% ", "meta": {"author": "MultiDIC", "repo": "MultiDIC", "sha": "d363c3ea74673e58df275d4a4c8e528ef5472acb", "save_path": "github-repos/MATLAB/MultiDIC-MultiDIC", "path": "github-repos/MATLAB/MultiDIC-MultiDIC/MultiDIC-d363c3ea74673e58df275d4a4c8e528ef5472acb/lib_MultiDIC/faceIsotropyIndex.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191284552529, "lm_q2_score": 0.8652240895276223, "lm_q1q2_score": 0.8265651231260178}} {"text": "% Find the Least Root Mean Square distance \n% between two sets of N points in D dimensions\n% and the rigid transformation (i.e. translation and rotation) \n% to employ in order to bring one set that close to the other,\n% Using the Kabsch (1976) algorithm.\n% Note that the points are paired, i.e. we know which point in one set \n% should be compared to a given point in the other set.\n% \n% References:\n% 1) Kabsch W. A solution for the best rotation to relate two sets of vectors. Acta Cryst A 1976;32:9223.\n% 2) Kabsch W. A discussion of the solution for the best rotation to relate two sets of vectors. Acta Cryst A 1978;34:8278.\n% 3) http://cnx.org/content/m11608/latest/\n% 4) http://en.wikipedia.org/wiki/Kabsch_algorithm\n%\n% We slightly generalize, allowing weights given to the points.\n% Those weights are determined a priori and do not depend on the distances.\n%\n% We work in the convention that points are column vectors; \n% some use the convention where they are row vectors instead. \n%\n% Input variables:\n% P : a D*N matrix where P(a,i) is the a-th coordinate of the i-th point \n% in the 1st representation\n% Q : a D*N matrix where Q(a,i) is the a-th coordinate of the i-th point \n% in the 2nd representation\n% m : (Optional) a row vector of length N giving the weights, i.e. m(i) is \n% the weight to be assigned to the deviation of the i-th point.\n% If not supplied, we take by default the unweighted (or equal weighted)\n% m(i) = 1/N.\n% The weights do not have to be normalized; \n% we divide by the sum to ensure sum_{i=1}^N m(i) = 1.\n% The weights must be non-negative with at least one positive entry.\n% Output variables:\n% U : a proper orthogonal D*D matrix, representing the rotation\n% r : a D-dimensional column vector, representing the translation\n% lrms: the Least Root Mean Square\n%\n% Details:\n% If p_i, q_i are the i-th point (as a D-dimensional column vector) \n% in the two representations, i.e. p_i = P(:,i) etc., and for \n% p_i' = U p_i + r (' does not stand for transpose!)\n% we have p_i' ~ q_i, that is, \n% lrms = sqrt(sum_{i=1}^N m(i) (p_i' - q_i)^2)\n% is the minimal rms when going over the possible U and r.\n% (assuming the weights are already normalized).\n%\nfunction[U, r, lrms] = Kabsch(P, Q, m)\n\tsz1 = size(P) ;\n\tsz2 = size(Q) ;\n\tif (length(sz1) ~= 2 || length(sz2) ~= 2)\n\t\terror 'P and Q must be matrices' ;\n\tend\n\tif (any(sz1 ~= sz2))\n\t\terror 'P and Q must be of same size' ;\n\tend\n\tD = sz1(1) ; % dimension of space\n\tN = sz1(2) ; % number of points\n\tif (nargin >= 3)\n\t\tif (~isvector(m) || any(size(m) ~= [1 N]))\n\t\t\terror 'm must be a row vector of length N' ;\n\t\tend \n\t\tif (any(m < 0))\n\t\t\terror 'm must have non-negative entries' ;\n\t\tend\n\t\tmsum = sum(m) ;\n\t\tif (msum == 0)\n\t\t\terror 'm must contain some positive entry' ;\n\t\tend\n\t\tm = m / msum ; % normalize so that weights sum to 1\n\telse % m not supplied - use default\n\t\tm = ones(1,N)/N ;\n\tend\n\n\tp0 = P*m' ; % the centroid of P\n\tq0 = Q*m' ; % the centroid of Q\n\tv1 = ones(1,N) ; % row vector of N ones\n\tP = P - p0*v1 ; % translating P to center the origin\n\tQ = Q - q0*v1 ; % translating Q to center the origin\n\n\t% C is a covariance matrix of the coordinates\n\t% C = P*diag(m)*Q' \n\t% but this is inefficient, involving an N*N matrix, while typically D << N.\n\t% so we use another way to compute Pdm = P*diag(m),\n\t% which is equivalent to, but more efficient than,\n\t% Pdm = zeros(D,N) ;\n\t% for i=1:N\n\t% \tPdm(:,i) = m(i)*P(:,i) ;\n\t% end\n\tPdm = bsxfun(@times,m,P) ;\n\tC = Pdm*Q' ; \t\n%\tC = P*Q' / N ; % (for the non-weighted case) \n\t[V,S,W] = svd(C) ; % singular value decomposition\n\tI = eye(D) ;\n\tif (det(V*W') < 0) % more numerically stable than using (det(C) < 0)\n\t\tI(D,D) = -1 ;\n\tend\n\tU = W*I*V' ;\n\n\tr = q0 - U*p0 ;\n\n\tDiff = U*P - Q ; % P, Q already centered\n%\tlrms = sqrt(sum(sum(Diff.*Diff))/N) ; % (for the non-weighted case)\n\t% to compute the lrms, we employ an efficient method, equivalent to: \n\t% lrms = 0 ;\n\t% for i=1:N\n\t% \tlrms = lrms + m(i)*Diff(:,i)'*Diff(:,i) ;\n\t% end\n\t% lrms = sqrt(lrms) ;\n\tlrms = sqrt(sum(sum(bsxfun(@times,m,Diff).*Diff))) ; \nend\n", "meta": {"author": "intellhave", "repo": "SDRSAC", "sha": "b081721e9dfd7843d75aa12f30025b2bd7c8f024", "save_path": "github-repos/MATLAB/intellhave-SDRSAC", "path": "github-repos/MATLAB/intellhave-SDRSAC/SDRSAC-b081721e9dfd7843d75aa12f30025b2bd7c8f024/utils/Kabsch.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750440288019, "lm_q2_score": 0.8670357718273068, "lm_q1q2_score": 0.8265235635632222}} {"text": "function [J, grad] = costFunction(theta, X, y)\n%COSTFUNCTION Compute cost and gradient for logistic regression\n% J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the\n% parameter for logistic regression and the gradient of the cost\n% w.r.t. to the parameters.\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n% Note: grad should have the same dimensions as theta\n%\nh_theta = sigmoid(X*theta);\nJ = (1 / m) * ((-y' * log(h_theta)) - (1 - y)' * log(1 - h_theta));\n\ngrad = (1 / m) * (h_theta - y)' * X;\n\n\n\n\n\n% =============================================================\n\nend\n", "meta": {"author": "atinesh-s", "repo": "Coursera-Machine-Learning-Stanford", "sha": "4d128c09373e5513505734ed05c2f13c3fd0f05e", "save_path": "github-repos/MATLAB/atinesh-s-Coursera-Machine-Learning-Stanford", "path": "github-repos/MATLAB/atinesh-s-Coursera-Machine-Learning-Stanford/Coursera-Machine-Learning-Stanford-4d128c09373e5513505734ed05c2f13c3fd0f05e/Week 3/Programming Assignment/machine-learning-ex2/ex2/costFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572777987970315, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.826505616530617}} {"text": "% gerschdisc.m\n% \n% This function plots the Gershgorin Discs for the matrix A passed as an argument.\n% It will also plot the centers of such discs, and the actual eigenvalues\n% of the matrix.\n\nfunction gershdisc(A)\n\nerror(nargchk(nargin,1,1));\nif size(A,1) ~= size(A,2)\n error('Matrix should be square');\n return;\nend\n\n% For each row, we say:\nfor i=1:size(A,1)\n % The circle has center in (h,k) where h is the real part of A(i,i) and\n % k is the imaginary part of A(i,i) :\n h=real(A(i,i)); k=imag(A(i,i)); \n \n\n % Now we try to compute the radius of the circle, which is nothing more\n % than the sum of norm of the elements in the row where i != j\n r=0;\n for j=1:size(A,1)\n if i ~= j \n r=r+(norm(A(i,j)));\n end \n end \n \n % We try to make a vector of points for the circle:\n N=256;\n t=(0:N)*2*pi/N;\n \n % Now we're able to map each of the elements of this vector into a\n % circle:\n plot( r*cos(t)+h, r*sin(t)+k ,'-');\n\n % We also plot the center of the circle for better undesrtanding:\n hold on;\n plot( h, k,'+');\nend\n\n% For the circles to be better graphed, we would like to have equal axis:\naxis equal;\n\n% Now we plot the actual eigenvalues of the matrix:\nev=eig(A);\nfor i=1:size(ev)\n rev=plot(real(ev(i)),imag(ev(i)),'ro');\nend\nhold off;\nlegend(rev,'Actual Eigenvalues');\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/13989-gershgorin-discs-plot/gershdisc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809827, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.8264453647029657}} {"text": "function chi2 = chi_squared(y,fit,P,eb)\n\n% returns *reduced* chi^2 value for use in data modelling\n% \"y\" is a vector of data, \"fit\" is a vector of model values (size(fit)=size(y)), P is the number of\n% parameters fit in the model, and eb is a vector of error bars (1-to-1 correspondnce with y)\n% Ref: John R. Taylor, \"An Introduction to Error Analysis\", (2nd ed., 1997)\n% 11/11/01 Mike Scarpulla. Please direct questions or comments to scarps@uclink.berkeley.edu\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nif nargin<3\n error('Wrong number of arguments passed to \"chi_squared\"')\nend\n\n% if error bars are not availible, evaluate chi^2 by normalizing deviation^2 by magnitude of data.\n% This assumes that the STDEV of a value scales as SQRT(value). USE WITH THIS CAVEAT IN MIND\nif nargin==3\n N = max(size(y));\n terms = ((y-fit).^2)./abs(y);\n chi2 = 1/(N-P)*sum(terms);\nend\n\n%if error bars are availible, normalize the deviation to the expectred error\nif nargin==4\n N = max(size(y));\n terms = ((y-fit)./eb).^2;\n chi2 = 1/(N-P)*sum(terms);\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/1049-chisquared-m/chi_squared.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542840900507, "lm_q2_score": 0.8615382165412808, "lm_q1q2_score": 0.8263480713028712}} {"text": "function y = r8vec_sqctf ( n, x )\n\n%*****************************************************************************80\n%\n%% R8VEC_SQCTF computes a \"slow\" quarter cosine transform forward 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% For 0 <= I <= N-1,\n%\n% Y(I) = (1/N) Sum ( 0 <= J <= N-1 ) X(J) * cos ( PI * I * (J+1/2) / N )\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% Reference:\n%\n% William Briggs, Van Emden Henson,\n% The Discrete Fourier Transform,\n% SIAM, 1995,\n% QA403.5 B75\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 y(1:n) = 0.0;\n\n for i = 1 : n\n for j = 1 : n\n theta = 0.5 * pi * ( i - 1 ) * ( 2 * j - 1 ) / n;\n y(i) = y(i) + x(j) * cos ( theta );\n end\n end\n\n y(1:n) = y(1:n) / 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/sftpack/r8vec_sqctf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.8791467627598857, "lm_q1q2_score": 0.8263217758148964}} {"text": "function [ x, seed ] = log_series_sample ( a, seed )\n\n%*****************************************************************************80\n%\n%% LOG_SERIES_SAMPLE samples the Logarithmic Series PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 06 March 1999\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Luc Devroye,\n% Non-Uniform Random Variate Generation,\n% Springer-Verlag, New York, 1986, page 547.\n%\n% Parameters:\n%\n% Input, real A, the parameter of the PDF.\n% 0.0 < A < 1.0.\n%\n% Input, integer SEED, a seed for the random number generator.\n%\n% Output, integer X, a sample of the PDF.\n%\n% Output, integer SEED, an updated seed for the random number generator.\n%\n [ u, seed ] = r8_uniform_01 ( seed );\n [ v, seed ] = r8_uniform_01 ( seed );\n\n x = floor ( 1.0 + log ( v ) / ( log ( 1.0 - ( 1.0 - a )^u ) ) );\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/log_series_sample.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9381240211961401, "lm_q2_score": 0.8807970842359877, "lm_q1q2_score": 0.8262969025213002}} {"text": "%DECOMPOSEHOMOGRAPHYMAT Decompose a homography matrix to rotation(s), translation(s) and plane normal(s)\n%\n% [motions, nsols] = cv.decomposeHomographyMat(H, K)\n%\n% ## Input\n% * __H__ The input homography matrix between two images, 3x3.\n% * __K__ The input intrinsic camera calibration matrix, 3x3.\n%\n% ## Output\n% * __motions__ Decomposed `H`. A scalar struct with the following fields:\n% * __R__ Array of rotation matrices. Cell array of 3x3 rotations.\n% * __t__ Array of translation matrices. Cell array of 3x1 translations.\n% * __n__ Array of plane normal matrices. Cell array of 3x1 normals.\n% * __nsols__ number of solutions.\n%\n% This function extracts relative camera motion between two views observing a\n% planar object from the homography `H` induced by the plane. The intrinsic\n% camera matrix `K` must also be provided. The function may return up to four\n% mathematical solution sets. At least two of the solutions may further be\n% invalidated if point correspondences are available by applying positive\n% depth constraint (all points must be in front of the camera). The\n% decomposition method is described in detail in [Malis]:\n%\n% H = s * K * (R{i} + t{i} * n{i}') * inv(K), for i=1:nsols\n%\n% `s` is a scaling factor approximated as:\n%\n% s = median(svd(inv(K) * H * K))\n%\n% ## References\n% [Malis]:\n% > Ezio Malis, Manuel Vargas, and others. \"Deeper understanding of the\n% > homography decomposition for vision-based control\". 2007.\n%\n% See also: cv.findHomography, cv.decomposeEssentialMat\n%\n", "meta": {"author": "kyamagu", "repo": "mexopencv", "sha": "d29007b2a484d0fd92e6e941dc5fd4750014fa6a", "save_path": "github-repos/MATLAB/kyamagu-mexopencv", "path": "github-repos/MATLAB/kyamagu-mexopencv/mexopencv-d29007b2a484d0fd92e6e941dc5fd4750014fa6a/+cv/decomposeHomographyMat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541610257062, "lm_q2_score": 0.8774767938900121, "lm_q1q2_score": 0.8262796741700259}} {"text": "function [U S] = performPCA(X)\n\n% This function calculates the covariance matrix (Sigma) and then performs \n% svd on it to get the eigen vectors and eigen values\n\n[m n] = size(X); % m - no of egs; n - no of features\n\nSigma = (1/m)*(X')*(X); % Covariance matrix\n\n[U S V] = svd(Sigma); % Perform Singular Value Decomposition", "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/42847-principal-component-analysis-pca/PCA/performPCA.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.960951703918909, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.8260953406672994}} {"text": "function [x,y] = intline(x1,x2,y1,y2)\n%INTLINE Integer-coordinate line drawing algorithm.\n% [X,Y] = INTLINE(X1,X2,Y1,Y2) computes an approximation to the line\n% segment joining (X1,Y1) and (X2,Y2) with integer coordinates. X1,\n% X2, Y1, and Y2 should be integers. INTLINE is reversible; that is,\n% INTLINE(X1,X2,Y1,Y2) produces the same results as\n% FLIPUD(INTLINE(X2,X1,Y2,Y1)).\n\n% Copyright 1993-2019 The MathWorks, Inc.\n% License: https://github.com/mathworks/matlab-color-tools/blob/master/license.txt\n\ndx = abs(x2 - x1);\ndy = abs(y2 - y1);\n\n% Check for degenerate case.\nif ((dx == 0) && (dy == 0))\n x = x1;\n y = y1;\n return;\nend\n\nflip = 0;\nif (dx >= dy)\n if (x1 > x2)\n % Always \"draw\" from left to right.\n t = x1; x1 = x2; x2 = t;\n t = y1; y1 = y2; y2 = t;\n flip = 1;\n end\n m = (y2 - y1)/(x2 - x1);\n x = (x1:x2).';\n y = round(y1 + m*(x - x1));\nelse\n if (y1 > y2)\n % Always \"draw\" from bottom to top.\n t = x1; x1 = x2; x2 = t;\n t = y1; y1 = y2; y2 = t;\n flip = 1;\n end\n m = (x2 - x1)/(y2 - y1);\n y = (y1:y2).';\n x = round(x1 + m*(y - y1));\nend\n \nif (flip)\n x = flipud(x);\n y = flipud(y);\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/intline.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.891811053345418, "lm_q1q2_score": 0.8260879090599456}} {"text": "function p = prime_ge ( n )\n\n%*****************************************************************************80\n%\n%% PRIME_GE returns the smallest prime greater than or equal to N.\n%\n% Discussion:\n%\n% The MATLAB version of this program is made much simpler\n% because of the availability of the IS_PRIME logical function.\n%\n% Example:\n%\n% N PRIME_GE\n%\n% -10 2\n% 1 2\n% 2 2\n% 3 3\n% 4 5\n% 5 5\n% 6 7\n% 7 7\n% 8 11\n% 9 11\n% 10 11\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 March 2003\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number to be bounded.\n%\n% Output, integer P, the smallest prime number that is greater\n% than or equal to N. \n%\n p = max ( ceil ( n ), 2 );\n \n while ( ~ isprime ( p ) )\n p = 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/subpak/prime_ge.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140233, "lm_q2_score": 0.8840392848011834, "lm_q1q2_score": 0.8260420295993119}} {"text": "function intVal=monomialIntCrossPolytope(alpha)\n%%MONOMIALINTCROSSPOLYTOPE Evaluate the integral of\n% prod_{i=1}^N x(i)^alpha(i) over the space defined by\n% sum(abs(x))=1. That is, this function gives the value of the\n% desired monomial integral taken over an N-dimensional cross\n% polytope. The region is designated as G_n in [1]. In two\n% dimensions, this shape is a square, in three an octohedron, in\n% N, a cross polytope (or N-dimensional hyperoctahedron).\n%\n%INPUTS: alpha An NX1 or 1XN vector of the integer exponents of the\n% monomial term. All elements must be >=0.\n%\n%OUTPUTS: intVal The value of the specified integral.\n%\n%The formula is taken from Chapter 7.7 of [1]. These types of explicit\n%moment formulae are useful for testing cubature integration points.\n%\n%EXAMPLE:\n%Here we verify that the moment value produced here equals that obtained\n%using cubature points of an appropriate order.\n% [xi,w]=fifthOrderCrossPolyCubPoints(3);\n% alpha=[0;2;2];\n% theMoment=findMomentFromSamp(alpha,xi,w)\n% intVal=monomialIntCrossPolytope(alpha)\n%One will find that theMoment and intVal are both near 0.0063.\n%\n%REFERENCES:\n%[1] A.H. Stroud, Approximate Calculation of Multiple Integrals. Cliffs,\n% NJ: Prentice-Hall, Inc., 1971.\n%\n%February 2017 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(all(mod(alpha,2)==0))\n n=length(alpha);\n\n intVal=exp(n*log(2)+sum(gammaln(alpha+1))-gammaln(n+sum(alpha)+1));\nelse\n intVal=0;\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/Specific_Integrals/Monomial_Integrals/monomialIntCrossPolytope.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.8840392756357327, "lm_q1q2_score": 0.8260420274953908}} {"text": "function mask = maskEllipse( mRows, nCols, varargin )\n% Creates a binary image of an ellipse.\n%\n% Creates a binary image of size (mRows x nCols), with all pixels set to 0\n% outside the ellipse and 1 inside. The ellipse is given by 5 parameters,\n% a semimajor axis of ra, a semminor axis of radius rb, angle phi (in\n% radians), and center (cRow,cCol). An alternative method of specifying the\n% ellipse parameters is in terms of a 2D Gaussian. For more info on how a\n% Gaussian relates to an ellipse see gauss2ellipse.\n%\n% USAGE\n% mask = maskEllipse( mRows, nCols, cRow, cCol, ra, rb, phi )\n% mask = maskEllipse( mRows, nCols, mu, C, [rad] )\n%\n% INPUTS [version 1]\n% mRows - number of rows in mask\n% nCols - number of columns in mask\n% cRow - the row location of the center of the ellipse\n% cCol - the column location of the center of the ellipse\n% ra - semi-major axis length (in pixels) of the ellipse\n% rb - semi-minor axis length (in pixels) of the ellipse\n% phi - rotation angle (in radians) of semimajor axis to x-axis\n%\n% INPUTS [version 2]\n% mRows - number of rows in mask\n% nCols - number of columns in mask\n% mu - 1x2 vector representing the center of the ellipse\n% C - 2x2 cov matrix\n% rad - [2] Number of std to create the ellipse to\n%\n% OUTPUTS\n% mask - created image mask\n%\n% EXAMPLE\n% mask = maskEllipse( 200, 200, 40, 100, 20, 15, pi/4 );\n% figure(1); im(mask); [mu,C] = imMlGauss( mask, 0, 2 );\n%\n% See also PLOTELLIPSE, GAUSS2ELLIPSE, MASKCIRCLE, MASKGAUSSIANS, IMMLGAUSS\n%\n% Piotr's Computer Vision Matlab Toolbox Version 2.40\n% Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com]\n% Licensed under the Simplified BSD License [see external/bsd.txt]\n\nif( nargin==7 )\n [cRow, cCol, ra, rb, phi] = deal( varargin{:} );\nelseif( nargin==4 )\n [mu, C] = deal( varargin{:} );\n [cRow, cCol, ra, rb, phi] = gauss2ellipse( mu, C );\nelseif( nargin==5 )\n [mu, C, rad] = deal( varargin{:} );\n [cRow, cCol, ra, rb, phi] = gauss2ellipse( mu, C, rad );\nelse\n error( ['Incorrect number of input arguments: ' int2str(nargin)] );\nend;\n\n% compute the leftmost and rightmost points of the ellipse\nraCos=ra*cos(pi-phi); rbCos=rb*cos(pi-phi);\nraSin=ra*sin(pi-phi); rbSin=rb*sin(pi-phi);\nd = sqrt(raCos*raCos + rbSin*rbSin);\ncRad = abs(raCos*raCos/d + rbSin*rbSin/d);\nc0 = max( ceil(cCol-cRad), 1 );\nc1 = min( floor(cCol+cRad), nCols );\nB = rbSin / raCos; B2=B*B;\n\n% compute and add the top/bottom points for each c\nmask = zeros( mRows, nCols );\nfor c=c0:c1\n A=(c-cCol)/raCos; C=sqrt(max(0,B2-A*A+1));\n r0 = cRow - raSin*(A-B*C)/(B2+1) + rbCos*(A*B+C)/(B2+1);\n r1 = cRow - raSin*(A+B*C)/(B2+1) + rbCos*(A*B-C)/(B2+1);\n if(r0>r1), tmp=r0; r0=r1; r1=tmp; end\n r0 = max( ceil(r0-.0001), 1 );\n r1 = min( floor(r1+.0001), mRows );\n mask( r0:r1, c ) = 1;\nend\n", "meta": {"author": "pdollar", "repo": "toolbox", "sha": "e87332637bbe8e8b92dd487c87567d9628404523", "save_path": "github-repos/MATLAB/pdollar-toolbox", "path": "github-repos/MATLAB/pdollar-toolbox/toolbox-e87332637bbe8e8b92dd487c87567d9628404523/images/maskEllipse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947148047777, "lm_q2_score": 0.8740772450055545, "lm_q1q2_score": 0.8259983768613698}} {"text": "function [out] = meanangle(in,dim,sens);\n\n% MEANANGLE will calculate the mean of a set of angles (in degrees) based\n% on polar considerations.\n%\n% Usage: [out] = meanangle(in,dim)\n%\n% in is a vector or matrix of angles (in degrees)\n% out is the mean of these angles along the dimension dim\n%\n% If dim is not specified, the first non-singleton dimension is used.\n%\n% A sensitivity factor is used to determine oppositeness, and is how close\n% the mean of the complex representations of the angles can be to zero\n% before being called zero. For nearly all cases, this parameter is fine\n% at its default (1e-12), but it can be readjusted as a third parameter if\n% necessary:\n%\n% [out] = meanangle(in,dim,sensitivity)\n%\n% Written by J.A. Dunne, 10-20-05\n%\n\nif nargin<3\n sens = 1e-12;\nend\n\nif nargin<2\n ind = min(find(size(in)>1));\n if isempty(ind)\n %This is a scalar\n out = in;\n return\n end\n dim = ind;\nend\n\nin = in * pi/180;\n\nin = exp(i*in);\nmid = mean(in,dim);\nout = atan2(imag(mid),real(mid))*180/pi;\nout(abs(mid)=0.\n%\n%OUTPUTS: val The value of the nth derivative of the secant function taken\n% at all of the points in z. val has the same dimensions as z.\n%\n%This function implements the algorithm of [1].\n%\n%REFERENCES:\n%[1] M. E. Hoffman, \"Derivative polynomials for tangent and secant,\" The\n% American Mathematical Monthly, vol. 102, no. 1, pp. 23-30, Jan. 1995.\n%\n%October 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nnumEls=numel(z);\n\nval=zeros(size(z));\nfor curEl=1:numEls\n x=z(curEl);\n u=tan(x);\n\n P=zeros(n+1,1);\n Q=zeros(n+1,1);\n P(1)=u;\n Q(1)=1;\n \n for k=1:n\n %The loop implements Equation 5.\n sumValP=0;\n sumValQ=0;\n for i=0:(k-1)\n binomVal=binomial(k-1,i);\n sumValP=sumValP+binomVal*P(i+1)*P(k-1-i+1);\n sumValQ=sumValQ+binomVal*P(i+1)*Q(k-1-i+1);\n end\n if(k==1)\n sumValP=sumValP+1;\n end\n P(k+1)=sumValP;\n Q(k+1)=sumValQ;\n end\n val(curEl)=Q(end)*sec(x);\nend\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/Specific_Derivatives/secDerivVal.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.8991213718636754, "lm_q1q2_score": 0.8258252150313697}} {"text": "function pdf = geometric_pdf ( x, a )\n\n%*****************************************************************************80\n%\n%% GEOMETRIC_PDF evaluates the Geometric PDF.\n%\n% Discussion:\n%\n% PDF(X)(A) = A * ( 1 - A )**(X-1)\n%\n% PDF(X)(A) is the probability that exactly X Bernoulli trials, each\n% with probability of success A, will be required to achieve\n% a single success.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer X, the number of trials.\n% 0 < X\n%\n% Input, real A, the probability of success on one trial.\n% 0.0 <= A <= 1.0.\n%\n% Output, real PDF, the value of the PDF.\n%\n\n%\n% Special cases.\n%\n if ( x < 1 )\n\n pdf = 0.0;\n\n elseif ( a == 0.0 )\n\n pdf = 0.0;\n\n elseif ( a == 1.0 )\n\n if ( x == 1 )\n pdf = 1.0;\n else\n pdf = 0.0;\n end\n\n else\n\n pdf = a * ( 1.0 - a )^( x - 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/prob/geometric_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.8856314692902446, "lm_q1q2_score": 0.8258099972953512}} {"text": "function glopts = loc2glob_3d ( cospitch, cosroll, cosyaw, sinpitch, sinroll, ...\n sinyaw, globas, locpts )\n\n%*****************************************************************************80\n%\n%% LOC2GLOB_3D converts from a local to global coordinate system in 3D.\n%\n% Discussion:\n%\n% A global coordinate system is given.\n%\n% A local coordinate system has been translated to the point with\n% global coordinates GLOBAS, and rotated through a yaw, a pitch, and\n% a roll.\n%\n% A point has local coordinates LOCPTS, and it is desired to know\n% the point's global coordinates GLOPTS.\n%\n% The transformation may be written as\n%\n% GLOB = GLOBAS + N_YAW * N_PITCH * N_ROLL * LOC\n%\n% where\n%\n% ( cos(Yaw) -sin(Yaw) 0 )\n% N_YAW = ( sin(Yaw) cos(Yaw) 0 )\n% ( 0 0 1 )\n%\n% ( cos(Pitch) 0 sin(Pitch) )\n% N_PITCH = ( 0 1 0 )\n% ( -sin(Pitch) 0 cos(Pitch) )\n%\n% ( 1 0 0 )\n% N_ROLL = ( 0 cos(Roll) -sin(Roll) )\n% ( 0 sin(Roll) cos(Roll) )\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% Parameters:\n%\n% Input, real COSPITCH, COSROLL, COSYAW, the cosines of the\n% pitch, roll and yaw angles.\n%\n% Input, real SINPITCH, SINROLL, SINYAW, the sines of the pitch,\n% roll and yaw angles.\n%\n% Input, real GLOBAS(3,1), the global coordinates of the base\n% vector.\n%\n% Input, real LOCPTS(3,1), the local coordinates of the point.\n%\n% Output, real GLOPTS(3,1), the global coordinates of the point.\n%\n glopts(1,1) = globas(1,1) + ( cosyaw * cospitch ) * locpts(1,1) ...\n + ( cosyaw * sinpitch * sinroll - sinyaw * cosroll ) * locpts(2,1) ...\n + ( cosyaw * sinpitch * cosroll + sinyaw * sinroll ) * locpts(3,1);\n\n glopts(2,1) = globas(2,1) + ( sinyaw * cospitch ) * locpts(1,1) ...\n + ( sinyaw * sinpitch * sinroll + cosyaw * cosroll ) * locpts(2,1) ...\n + ( sinyaw * sinpitch * cosroll - cosyaw * sinroll ) * locpts(3,1);\n\n glopts(3,1) = globas(3,1) + ( -sinpitch ) * locpts(1,1) ...\n + ( cospitch * sinroll ) * locpts(2,1) ...\n + ( cospitch * cosroll ) * locpts(3,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/geometry/loc2glob_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533013520765, "lm_q2_score": 0.8856314723088733, "lm_q1q2_score": 0.825809990135709}} {"text": "function [p alpha] = circ_vmpdf(alpha, thetahat, kappa)\n\n% [p alpha] = circ_vmpdf(alpha, w, p)\n% Computes the circular von Mises pdf with preferred direction thetahat \n% and concentration kappa at each of the angles in alpha\n%\n% The vmpdf is given by f(phi) =\n% (1/(2pi*I0(kappa))*exp(kappa*cos(phi-thetahat)\n%\n% Input:\n% alpha angles to evaluate pdf at, if empty alphas are chosen to\n% 100 uniformly spaced points around the circle\n% [thetahat preferred direction, default is 0]\n% [kappa concentration parameter, default is 1]\n%\n% Output:\n% p von Mises pdf evaluated at alpha\n% alpha angles at which pdf was evaluated\n%\n%\n% References:\n% Statistical analysis of circular data, Fisher\n%\n% Circular Statistics Toolbox for Matlab\n\n% By Philipp Berens and Marc J. Velasco, 2009\n% velasco@ccs.fau.edu\n\n% if no angles are supplied, 100 evenly spaced points around the circle are\n% chosen\nif nargin < 1 || isempty(alpha)\n alpha = linspace(0, 2*pi, 101)';\n alpha = alpha(1:end-1);\nend\nif nargin < 3\n kappa = 1;\nend\nif nargin < 2\n thetahat = 0;\nend\n\nalpha = alpha(:);\n\n% evaluate pdf\nC = 1/(2*pi*besseli(0,kappa));\np = C * exp(kappa*cos(alpha-thetahat));\n", "meta": {"author": "buzsakilab", "repo": "buzcode", "sha": "2d700a38b3c2a860ad1333be90f14d7a37a72815", "save_path": "github-repos/MATLAB/buzsakilab-buzcode", "path": "github-repos/MATLAB/buzsakilab-buzcode/buzcode-2d700a38b3c2a860ad1333be90f14d7a37a72815/externalPackages/CircularStats/circ_vmpdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109742068041, "lm_q2_score": 0.8688267660487573, "lm_q1q2_score": 0.8257424931373465}} {"text": "function p = he_polynomial_value ( m, n, x )\n\n%*****************************************************************************80\n%\n%% HE_POLYNOMIAL_VALUE evaluates He(i,x).\n%\n% Discussion:\n%\n% He(i,x) represents the probabilist's Hermite polynomial.\n%\n% Differential equation:\n%\n% ( exp ( - 0.5 * x^2 ) * He(n,x)' )' + n * exp ( - 0.5 * x^2 ) * He(n,x) = 0\n%\n% First terms:\n%\n% 1\n% X\n% X^2 - 1\n% X^3 - 3 X\n% X^4 - 6 X^2 + 3\n% X^5 - 10 X^3 + 15 X\n% X^6 - 15 X^4 + 45 X^2 - 15\n% X^7 - 21 X^5 + 105 X^3 - 105 X\n% X^8 - 28 X^6 + 210 X^4 - 420 X^2 + 105\n% X^9 - 36 X^7 + 378 X^5 - 1260 X^3 + 945 X\n% X^10 - 45 X^8 + 630 X^6 - 3150 X^4 + 4725 X^2 - 945\n%\n% Recursion:\n%\n% He(0,X) = 1,\n% He(1,X) = X,\n% He(N,X) = X * He(N-1,X) - (N-1) * He(N-2,X)\n%\n% Orthogonality:\n%\n% Integral ( -oo < X < +oo ) exp ( - 0.5 * X^2 ) * He(M,X) He(N,X) dX \n% = sqrt ( 2 * pi ) * N! * delta ( N, M )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 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 probabilist's Hermite polynomials \n% 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 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/he_polynomial_value.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897426182322, "lm_q2_score": 0.8774767890838837, "lm_q1q2_score": 0.8255211625556999}} {"text": "function value = angle_rad_2d ( p1, p2, p3 )\n\n%*****************************************************************************80\n%\n%% ANGLE_RAD_2D returns the angle swept out between two rays in 2D.\n%\n% Discussion:\n%\n% Except for the zero angle case, it should be true that\n%\n% ANGLE_RAD_2D(P1,P2,P3) + ANGLE_RAD_2D(P3,P2,P1) = 2 * PI\n%\n% P1\n% /\n% / \n% / \n% / \n% P2--------->P3\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 P1(2), P2(2), P3(2), define the rays\n% P1 - P2 and P3 - P2 which in turn define the angle.\n%\n% Output, real VALUE, the angle swept out by the rays, measured\n% in radians. 0 <= VALUE < 2*PI. If either ray has zero length,\n% then VALUE is set to 0.\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 value = 0.0;\n return\n end\n\n value = atan2 ( p(2), p(1) );\n\n if ( value < 0.0 )\n value = value + 2.0 * pi;\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_triangulation/angle_rad_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582477806522, "lm_q2_score": 0.8872045996818986, "lm_q1q2_score": 0.8255068372429544}} {"text": "function pdf = semicircular_pdf ( x, a, b )\n\n%*****************************************************************************80\n%\n%% SEMICIRCULAR_PDF evaluates the Semicircular PDF.\n%\n% Formula:\n%\n% PDF(X)(A,B) = ( 2 / ( B * PI ) ) * SQRT ( 1 - ( ( X - A ) / B )**2 )\n% for A - B <= X <= A + B\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 20 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the PDF.\n%\n% Input, real A, B, the parameters of the PDF.\n% 0.0 < B.\n%\n% Output, real PDF, the value of the PDF.\n%\n if ( x < a - b )\n\n pdf = 0.0;\n\n elseif ( x <= a + b )\n\n y = ( x - a ) / b;\n\n pdf = 2.0 / ( b * pi ) * sqrt ( 1.0 - y * y );\n\n elseif ( a + b < x )\n\n pdf = 0.0;\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/prob/semicircular_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.935346511643776, "lm_q2_score": 0.8824278695464501, "lm_q1q2_score": 0.8253758295575212}} {"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n%\n% \n% Partial fraction expansion of a rational function\n%\n% \n\n\n\n% s^2+3s+1\n% X(s)=----------------\n% s^3+5s^2+2s-8\n \nA=[1 5 2 -8];\nrt=roots(A)\nsyms s\nX=(s^2+3*s+1)/(s^3+5*s^2+2*s-8);\n\nc1=limit((s-rt(1))*X,s,rt(1))\nc2=limit( (s-rt(2))*X,s,rt(2))\nc3=limit( (s-rt(3))*X,s,rt(3))\n\nX1=simplify( (s-rt(1))*X );\nX2=simplify( (s-rt(2))*X );\nX3=simplify( (s-rt(3))*X );\nc1=subs(X1,s,rt(1))\nc2=subs(X2,s,rt(2))\nc3=subs(X3,s,rt(3))\n\n%alternative conversion\nnum=[ 1 3 1];\nden=[ 1 5 2 -8];\n[R,P,K]=residue(num,den)\nsyms s\nX=R(1)/(s-P(1))+R(2)/(s-P(2))+R(3)/(s-P(3))\npretty(X)\n\n\n\n\n\n% \n% s^2+3s+1\n% X(s)=------------\n% s^3-3s+2\n\n\nA=[1 0 -3 2];\nrt=roots(A)\nsyms s\nX=(s^2+3*s+1)/(s^3-3*s+2);\n\nc1=limit((s-rt(1))*X,s,rt(1))\n\nr=2;\ni=1;\nf= ((s-1)^r )*X;\nd=diff(f,s,r-i);\nfact=1/factorial(r-i);\nc2=limit(fact*d,s,1)\n\ni=2;\nd=diff(f,s,r-i);\nfact=1/factorial(r-i);\nc3=limit(fact*d,s,1)\n\n%alternative conversion\nnum=[ 1 3 1];\nden=[1 0 -3 2];\n[R,P,K]=residue(num,den)\n\n\n\n\n\n\n\n% \n% s^2-12s+11\n% X(s)=------------\n% s^2+4s+3\n\n\n\nnum=[1 -12 11];\nden=[ 1 4 3];\n[k,g]=deconv(num,den)\nrt=roots(den)\n\nsyms s\nGA=(-16*s+8)/(s^2+4*s+3);\nc1=limit((s-rt(1))*GA,s,rt(1))\nc2=limit((s-rt(2))*GA,s,rt(2))\n\n%alternative conversion\nnum=[ 1 -12 11];\nden=[ 1 4 3];\n[R,P,K]=residue(num,den)\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/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/9/c96.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465134460244, "lm_q2_score": 0.8824278587245936, "lm_q1q2_score": 0.8253758210256896}} {"text": "function [ G ] = gsp_erdos_renyi( N,p,param )\n%GSP_ERDOS_RENYI Create a random Erdos Renyi graph\n% Usage: G = gsp_erdos_renyi( N,p,param );\n% G = gsp_erdos_renyi( N,p );\n%\n% Input parameters:\n% N : Number of nodes\n% p : Probability of connection of a node with another\n% param : Structure of optional parameter\n% Output parameters:\n% G : Graph structure.\n%\n% 'gsp_erdos_renyi( N,p,param )' initializes create a graph structure\n% containing the weighted adjacency matrix (G.W), the number of vertices\n% (G.N) for an Erdos Renyi graph. All edge weights are equal to 1. \n% \n% The Erdos Renyi graph is constructed by connecting nodes randomly. Each \n% edge is included in the graph with probability p independent from every\n% other edge. \n%\n% *param* a Matlab structure containing the following fields:\n%\n% * *param.connected* : flag to force the graph to be connected. By\n% default, it is 0.\n%\n% * *param.maxit* : is the maximum number of try to connect the graph. \n% By default, it is 10.\n% \n% * *param.verbose* : 0 no log, 1 print main steps, 2 print all steps.\n% By default, it is 1.\n%\n% Example::\n%\n% G = gsp_erdos_renyi(100,0.05)\n\n% Author : Nathanael Perraudin\n \n\n% Optional input arguments\nif nargin<3, param=struct; end\n\nif ~isfield(param, 'connected'), param.connected=0; end\nif ~isfield(param, 'maxit'), param.maxit=10; end\nif ~isfield(param, 'verbose'), param.verbose=1 ; end\n\n\n% Check if the user didn't put silly parameter\nif param.connected\n if N*p<3\n if param.verbose\n fprintf(['The model has very low chance to create a '...\n ,'connected graph. Increase N, p or disable '...\n ,'param.connected \\n']);\n end\n end\nend\n\nif p>1\n error('The probability p cannot be above 1'); \nend\n\nif p<0\n error('The probability p cannot be negative');\nend\n\n\n\n% Create the graph structure\nG=struct;\nG.graph_type='erdos_renyi';\nG.connected=param.connected;\n\n% Create the graph\nif param.connected\n bool=0;\n iter=1;\n if param.verbose>1\n fprintf('Entering the iteration process\\n')\n end\n while ~bool\n \n G.W = sprandsym(N, p)>0;\n G.W(1:N+1:end) = 0;\n\n bool=gsp_check_connectivity(G.W);\n if iter==param.maxit\n warning('The graph is not strongly connected.');\n break;\n elseif ~bool\n if param.verbose>1\n fprintf('Iteration %i failed. Trying again \\n',iter)\n end\n iter=iter+1;\n end\n end\n if param.verbose>1\n if bool\n fprintf('A connected graph has been created in %i iteration\\n',iter);\n else\n fprintf('The iterative process has failed.\\n');\n end\n end\nelse\n G.W = sprandsym(N,p)>0;\n G.W(1:N+1:end) = 0;\nend\n \n\n% try to create point to be associated with the points of the graph\n\n% [x, y] = draw_dot(G.W);\n% \n% \n% G.coords=[x',y'];\n% G.limits=[-1e-4,1.01*max(x),-1e-4,1.01*max(y)];\n\nG.type = 'erdos_renyi';\n\nG = gsp_graph_default_parameters(G);\n\nend\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/graphs/gsp_erdos_renyi.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768651485396, "lm_q2_score": 0.8740772351648677, "lm_q1q2_score": 0.8252835037956676}} {"text": "function p = gam_cdf(x,a,b)\n%GAM_CDF Cumulative of Gamma probability density function (cdf).\n%\n% P = GAM_CDF(X,A,B) Returns the gamma cdf with\n% shape A and inverse scale B, at the values in X.\n%\n% The size of X is the common size of the input arguments. A\n% scalar input functions as a constant matrix of the same size as\n% the other inputs.\n%\n% The parameterization is as in Gelman et al. (2004). Bayesian Data\n% Analysis (second edition)\n\n% Copyright (c) 1998-2004 Aki Vehtari\n\n% This software is distributed under the GNU General Public \n% License (version 3 or later); please refer to the file \n% License.txt, included with the software, for details.\n\nif nargin < 3, \n error('Requires three input arguments.');\nend\n\np=gammainc(b*x,a);\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/dmlt/external/gpstuff/dist/gam_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9621075722839015, "lm_q2_score": 0.8577681122619885, "lm_q1q2_score": 0.8252651960709269}} {"text": "function a = rectangle_adj ( row_num, col_num, n )\n\n%*****************************************************************************80\n%\n%% RECTANGLE_ADJ returns the RECTANGLE_ADJ matrix.\n%\n% Discussion:\n%\n% This is the adjacency matrix for a set of points arranged in\n% a ROW_NUM by COL_NUM grid.\n%\n% Diagram:\n%\n% 1---5---9\n% | | |\n% 2---6--10\n% | | |\n% 3---7--11\n% | | |\n% 4---8--12\n%\n% Example:\n%\n% ROW_NUM = 4\n% COL_NUM = 3\n%\n% 0 1 0 0 1 0 0 0 0 0 0 0\n% 1 0 1 0 0 1 0 0 0 0 0 0\n% 0 1 0 1 0 0 1 0 0 0 0 0\n% 0 0 1 0 1 0 0 1 0 0 0 0\n%\n% 1 0 0 0 0 1 0 0 1 0 0 0\n% 0 1 0 0 1 0 1 0 0 1 0 0\n% 0 0 1 0 0 1 0 1 0 0 1 0\n% 0 0 0 1 0 0 1 0 0 0 0 1\n%\n% 0 0 0 0 1 0 0 0 0 1 0 0\n% 0 0 0 0 0 1 0 0 1 0 1 0\n% 0 0 0 0 0 0 1 0 0 1 0 1\n% 0 0 0 0 0 0 0 1 0 0 1 0\n%\n% Properties:\n%\n% A is integral, therefore det ( A ) is integral, and \n% det ( A ) * inverse ( A ) is integral.\n%\n% A is a zero/one matrix.\n%\n% A is block tridiagonal.\n%\n% A is an adjacency matrix.\n%\n% A is related to the \"LIGHTS_OUT\" matrix.\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% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 July 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer ROW_NUM, COL_NUM, the number of rows and \n% columns in the rectangle.\n%\n% Input, integer N, the order of A.\n%\n% Output, real A(N,N), the matrix.\n%\n a = zeros ( n, n );\n\n for j_block = 1 : col_num\n\n j = ( j_block - 1 ) * row_num + 1;\n\n for i_block = 1 : col_num\n\n i = ( i_block - 1 ) * row_num + 1;\n\n if ( j_block == i_block )\n a(i:i+row_num-1,j:j+row_num-1) = line_adj ( row_num );\n elseif ( abs ( j_block - i_block ) == 1 )\n a(i:i+row_num-1,j:j+row_num-1) = identity ( row_num, row_num );\n else\n a(i:i+row_num-1,j:j+row_num-1) = zero ( row_num, row_num );\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/rectangle_adj.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308091776496, "lm_q2_score": 0.884039278690883, "lm_q1q2_score": 0.8251894992532566}} {"text": "function a = tri_upper_inverse ( alpha, n )\n\n%*****************************************************************************80\n%\n%% TRI_UPPER_INVERSE returns the inverse of the TRI_UPPER matrix.\n%\n% Formula:\n%\n% if ( I = J )\n% A(I,J) = 1\n% elseif ( I = J - 1 )\n% A(I,J) = -ALPHA\n% elseif ( I < J )\n% A(I,J) = - ALPHA * ( 1-ALPHA)^(J-I-1)\n% else\n% A(I,J) = 0\n%\n% Example:\n%\n% ALPHA = 3, N = 5\n%\n% 1 -3 6 -12 24\n% 0 1 -3 6 -12\n% 0 0 1 -3 6\n% 0 0 0 1 -3\n% 0 0 0 0 1\n%\n% Properties:\n%\n% A is generally not symmetric: A' /= A.\n%\n% A is nonsingular.\n%\n% A is upper triangular.\n%\n% A is Toeplitz: constant along diagonals.\n%\n% A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\n%\n% det ( A ) = 1.\n%\n% A is unimodular.\n%\n% LAMBDA(1:N) = 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real ALPHA, value used on the superdiagonals.\n%\n% Input, integer N, the order of A.\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 )\n a(i,j) = 1.0;\n elseif ( i == j - 1 )\n a(i,j) = - alpha;\n elseif ( i < j )\n a(i,j) = - alpha * ( 1.0 - alpha )^(j-i-1);\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/tri_upper_inverse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.8918110475945175, "lm_q1q2_score": 0.8251302917841159}} {"text": "function [ u, nullty, ifault ] = cholesky ( a, n, nn )\n\n%*****************************************************************************80\n%\n%% CHOLESKY computes the Cholesky factorization of a PDS matrix.\n%\n% Discussion:\n%\n% For a positive definite symmetric matrix A, the Cholesky factor U\n% is an upper triangular matrix such that A = U' * U.\n%\n% This routine was originally named \"CHOL\", but that conflicts with\n% the name of a built in MATLAB routine.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 February 2008\n%\n% Author:\n%\n% Original FORTRAN77 version by Michael Healy.\n% Modifications by AJ Miller.\n% MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Michael Healy,\n% Algorithm AS 6:\n% Triangular decomposition of a symmetric matrix,\n% Applied Statistics,\n% Volume 17, Number 2, 1968, pages 195-197.\n%\n% Parameters:\n%\n% Input, real A((N*(N+1))/2), a positive definite matrix\n% stored by rows in lower triangular form as a one dimensional array,\n% in the sequence\n% A(1,1),\n% A(2,1), A(2,2),\n% A(3,1), A(3,2), A(3,3), and so on.\n%\n% Input, integer N, the order of A.\n%\n% Input, integer NN, the dimension of the array used to store A, \n% which should be at least (N*(N+1))/2.\n%\n% Output, real U((N*(N+1))/2), an upper triangular matrix,\n% stored by columns, which is the Cholesky factor of A. \n%\n% Output, integer NULLTY, the rank deficiency of A. If NULLTY is zero,\n% the matrix is judged to have full rank.\n%\n% Output, integer IFAULT, an error indicator.\n% 0, no error was detected;\n% 1, if N < 1;\n% 2, if A is not positive semi-definite.\n% 3, if NN < (N*(N+1))/2.\n%\n% Local Parameters:\n%\n% Local, real ETA, should be set equal to the smallest positive\n% value such that 1.0 + ETA is calculated as being greater than 1.0 in the\n% accuracy being used.\n%\n\n%\n% Initialize output.\n%\n u = [];\n nullty = 0;\n ifault = 0;\n\n eta = 1.0E-09;\n\n if ( n <= 0 )\n ifault = 1;\n return\n end\n\n if ( nn < floor ( ( n * ( n + 1 ) ) / 2 ) )\n ifault = 3;\n return\n end\n\n u(1:nn) = 0.0;\n j = 1;\n k = 0;\n ii = 0;\n%\n% Factorize column by column, ICOL = column number.\n%\n for icol = 1 : n\n\n ii = ii + icol;\n x = eta * eta * a(ii);\n l = 0;\n kk = 0;\n%\n% IROW = row number within column ICOL.\n%\n for irow = 1 : icol\n\n kk = kk + irow;\n k = k + 1;\n w = a(k);\n m = j;\n\n for i = 1 : irow - 1\n l = l + 1;\n w = w - u(l) * u(m);\n m = m + 1;\n end\n\n l = l + 1;\n\n if ( irow == icol )\n break\n end\n\n if ( u(l) ~= 0.0 )\n\n u(k) = w / u(l);\n\n else\n\n u(k) = 0.0;\n\n if ( abs ( x * a(k) ) < w * w )\n ifault = 2;\n return\n end\n\n end\n\n end\n%\n% End of row, estimate relative accuracy of diagonal element.\n%\n if ( abs ( w ) <= abs ( eta * a(k) ) )\n\n u(k) = 0.0;\n nullty = nullty + 1;\n\n else\n\n if ( w < 0.0 )\n ifault = 2;\n return\n end\n\n u(k) = sqrt ( w );\n\n end\n\n j = j + icol;\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/asa007/cholesky.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299529686199, "lm_q2_score": 0.8918110425624792, "lm_q1q2_score": 0.8251302889669785}} {"text": "% Gauss-Seidel 迭代法(分量形式)求解方程组\nclear;\n% 输入值\nA = [10, -1, -2; -1, 10, -2; -1, -1, 5];\nb = [7.2; 8.3; 4.2];\ntol = 1e-5;\nN = 100;\nx = [0; 0; 0];\nx_backup = [0; 0; 0]; \ny = [0; 0; 0];\n%\nA_ = A;\nfor i = 1 : length(A)\n A_(i,i) = 0;\nend\n\nfor i = 0 : N\n for j = 1 : length(A)\n y(j,1) = (b(j) - A_(j,:) * x) / A(j,j);\n x_backup(j) = x(j); % 备份“老值”\n x(j) = y(j); % “新值” 替换 “老值”\n end\n if (max(abs(x_backup - y)) < tol)\n fprintf('迭代次数: %d\\n', i);\n fprintf('方程组的根: %10.8f\\n', y);\n break;\n end\nend\nif i == N\n fprintf('迭代方法失败\\n');\nend", "meta": {"author": "qxr777", "repo": "NumericalAnalysis", "sha": "145e47521459defdcfd6a929702651abe29ba6de", "save_path": "github-repos/MATLAB/qxr777-NumericalAnalysis", "path": "github-repos/MATLAB/qxr777-NumericalAnalysis/NumericalAnalysis-145e47521459defdcfd6a929702651abe29ba6de/第七章 线性方程组的迭代法/example_5_2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012686491108, "lm_q2_score": 0.8723473663814338, "lm_q1q2_score": 0.8250672458262709}} {"text": "function [ fmin, a, b ] = p00_fmin ( a, b, problem, tol )\n\n%*****************************************************************************80\n%\n%% P00_FMIN seeks a minimizer of a scalar function of a scalar variable.\n%\n% Discussion:\n%\n% FMIN seeks an approximation to the point where F attains a minimum on\n% the interval (A,B).\n%\n% The method used is a combination of golden section search and\n% successive parabolic interpolation. Convergence is never much\n% slower than that for a Fibonacci search. If F has a continuous\n% second derivative which is positive at the minimum (which is not\n% at A or B), then convergence is superlinear, and usually of the\n% order of about 1.324....\n%\n% The function F is never evaluated at two points closer together\n% than EPS * ABS ( FMIN ) + (TOL/3), where EPS is approximately the\n% square root of the relative machine precision. If F is a unimodal\n% function and the computed values of F are always unimodal when\n% separated by at least EPS * ABS ( XSTAR ) + (TOL/3), then FMIN\n% approximates the abcissa of the global minimum of F on the\n% interval [A, B] with an error less than 3 * EPS * ABS ( FMIN ) + TOL.\n% If F is not unimodal, then FMIN may approximate a local, but\n% perhaps non-global, minimum to the same accuracy.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 09 February 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Richard Brent,\n% Algorithms for Minimization without Derivatives,\n% Prentice Hall, 1973.\n%\n% David Kahaner, Cleve Moler, Steven Nash,\n% Numerical Methods and Software,\n% Prentice Hall, 1988.\n%\n% Parameters\n%\n% Input, real A, B, the left and right endpoints of the initial interval. \n%\n% Input, integer PROBLEM, the index of a problem.\n%\n% Input, real TOL, the desired length of the interval of\n% uncertainty of the final result. TOL must not be negative.\n%\n% Output, real FMIN, the abcissa approximating the\n% minimizer of f.\n%\n% Output, real A, B, the lower and upper bounds for the minimizer.\n%\n c = 0.5 * ( 3.0 - sqrt ( 5.0 ) );\n%\n% C is the squared inverse of the golden ratio.\n%\n% EPSILON is the square root of the relative machine precision.\n%\n epsilon = sqrt ( eps );\n%\n% Initialization.\n%\n v = a + c * ( b - a );\n w = v;\n x = v;\n e = 0.0;\n fx = p00_f ( problem, x );\n fv = fx;\n fw = fx;\n%\n% The main loop starts here.\n%\n while ( 1 )\n\n midpoint = 0.5 * ( a + b );\n tol1 = epsilon * abs ( x ) + tol / 3.0;\n tol2 = 2.0 * tol1;\n%\n% Check the stopping criterion.\n%\n if ( abs ( x - midpoint ) <= ( tol2 - 0.5 * ( b - a ) ) )\n break\n end\n%\n% Is golden-section necessary?\n%\n if ( abs ( e ) <= tol1 )\n if ( midpoint <= x )\n e = a - x;\n else\n e = b - x;\n end\n\n d = c * e;\n%\n% Consider fitting a parabola.\n%\n else\n\n r = ( x - w ) * ( fx - fv );\n q = ( x - v ) * ( fx - fw );\n p = ( x - v ) * q - ( x - w ) * r;\n q = 2.0 * ( q - r );\n if ( 0.0 < q )\n p = -p;\n end\n q = abs ( q );\n r = e;\n e = d;\n%\n% Choose a golden-section step if the parabola is not advised.\n%\n if ( ...\n ( abs ( 0.5 * q * r ) <= abs ( p ) ) | ...\n ( p <= q * ( a - x ) ) | ...\n ( q * ( b - x ) <= p ) )\n\n if ( midpoint <= x )\n e = a - x;\n else\n e = b - x;\n end\n\n d = c * e;\n%\n% Choose a parabolic interpolation step.\n%\n else\n\n d = p / q;\n u = x + d;\n\n if ( ( u - a ) < tol2 )\n d = abs ( tol1 ) * r8_sign ( midpoint - x );\n end\n\n if ( ( b - u ) < tol2 )\n d = abs ( tol1 ) * r8_sign ( midpoint - x );\n end\n\n end\n\n end\n%\n% F must not be evaluated too close to X.\n%\n if ( tol1 <= abs ( d ) )\n u = x + d;\n end\n\n if ( abs ( d ) < tol1 )\n u = x + abs ( tol1 ) * r8_sign ( d );\n end\n\n fu = p00_f ( problem, u );\n%\n% Update the data.\n%\n if ( fu <= fx )\n\n if ( x <= u )\n a = x;\n else\n b = x;\n end\n\n v = w;\n fv = fw;\n w = x;\n fw = fx;\n x = u;\n fx = fu;\n continue\n\n end\n\n if ( u < x )\n a = u;\n else\n b = u;\n end\n\n if ( fu <= fw | w == x )\n v = w;\n fv = fw;\n w = u;\n fw = fu;\n elseif ( fu <= fv | v == x | v == w )\n v = u;\n fv = fu;\n end\n\n end\n\n fmin = x;\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_min/p00_fmin.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.8856314753275019, "lm_q1q2_score": 0.8249325125733442}} {"text": "function circVar=findCircVar(x,w)\n%%FINDCIRCVAR Given a set of samples of a circular distribution, determine\n% the circular variance. As in Chapter 2.3.1 of [1], this is\n% just 1 minus the resultant length of the first trigonometric\n% moment.\n%INPUTS: x The 1XN or NX1 vector of possibly weighted samples.\n% w The NX1 weights associated with the samples. If this parameter\n% is omitted or an empty matrix is passed, then the samples are\n% uniformly weighted.\n%\n%OUTPUTS: circVar The circular variance of the measurements.\n%\n%The mean resultant length is found using findTrigMomentFromSamp and is\n%then subtracted from 1.\n%\n%REFERENCES\n%[1] K. V. Mardia and P. E. Jupp, Directional Statistics. Chichester: John\n% Wiley and Sons, 2000.\n%\n%April 2018 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<2)\n w=[];\nend\n\n[~,~,RS]=findTrigMomentFromSamp(1,x,w);\ncircVar=1-RS;\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/Statistics/findCircVar.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625107731765, "lm_q2_score": 0.8856314692902446, "lm_q1q2_score": 0.8249325120048286}} {"text": "function FR = factorialratio(A,B) \n% FACTORIALRATIO - ratio of factorial numbers\n%\n% FR = FACTORIALRATIO (A,B) calculates the ratio between products of\n% factorials specified by A and B. A and B are lists of positive\n% integers, with N and M elements, respectively. The number of values in\n% each list may differ. The factorial ratio is based on the following formula:\n%\n% (A1! * A2! * ... * AN!)\n% FR = -------------------------\n% (B1! * B2! * ... * BM!)\n%\n% However, an approach is taken that increases the accuracy when A or B\n% contain larger values, as mentioned in the help of FACTORIAL. \n%\n% Examples: \n%\n% f1 = factorialratio([10 8 6],[9 6 5]) ;\n% f2 = 10 * 8 * 7 * 6 ; % by hand\n% f3 = (factorial(10) * factorial(8) * factorial(6)) ./ ...\n% (factorial(9) * factorial(6) * factorial(5)) ;\n% disp('f1, f2, f3 = ') ; disp([f1 f2 f3])\n%\n%\n% % Also for larger values FACTORIALRATIO works correctly\n% f1 = factorialratio(150,143) ;\n% f2 = prod(144:150) ; % by hand\n% % where FACTORIAL lacks precision\n% f3 = factorial(150) ./ factorial(143) ;\n% disp('f1, f2, f3 = ') ; disp([f1 f2 f3])\n% disp(' Differences with f2 = ') ; disp([f1-f2 f2-f2 f3-f2])\n%\n% % and even for extreme numbers things turn out well\n% f1 = factorialratio(30000,29998) ; \n% f2 = (30000 * 29999) ; % by hand\n% % whereas calls to FACTORIAL fail miserably ...\n% f3 = factorial(30000) ./ factorial(29998) ;\n% disp('f1, f2, f3 = ') ; disp([f1 f2 f3])\n%\n% Note that, for instance, factorialratio(200,1) also fails, of course.\n% For such occasions other engines have to be used.\n% \n% See also PROD, FACTORIAL, GAMMALN\n\n% for Matlab R13 and up\n% version 2.0 (oct 2012)\n% (c) Jos van der Geest\n% email: jos@jasen.nl\n\n% History\n% 1.0 (feb 2009) - created for (later) use in a statistical test\n% 1.1 (feb 2009) - fixed minor bug in error checking\n% 2.0 (oct 2012) - fixed bug \"maxE > 1\" which should be \"maxE > 0\". Thanks\n% to 'Charles' for pointing this out.\n\n% check the input arguments\nerror(nargchk(2,2,nargin)) ;\nif isempty(A) || isempty(B) || ...\n ~isnumeric(A) || ~isnumeric(B) || ...\n any(A(:)<0) || any(fix(A(:)) ~= A(:)) || ...\n any(B(:)<0) || any(fix(B(:)) ~= B(:))\n error('Inputs should be numerical arrays with positive integers.')\nend\n\n% Example for terminology used in comments:\n% FR = factorialratio([6 4],[3 2 1]) call\n% = (6! * 4!) / (3! * 2!) numerators / denominators (ignoring ones)\n% = 6*5*4*3*2*4*3*2 / 3*2*2 expanded factorial (showing all factors > 1)\n% [6 5 4 3 2] .^ [1 1 1 2 2] \n% = ---------------------------- as powers (factors and exponents)\n% [6 5 4 3 2] .^ [0 0 0 1 2]\n%\n% = [6 5 4 3 2] .^ [1 1 1 1 0] rewritten\n\n% only values larger than 2 have an effect as both 1! and 0! equal 1\n% we can subtract 1 if we do not forget to add 1 later\nA = A(A>1) - 1 ;\nB = B(B>1) - 1 ;\n\n% what is the largest element?\nmaxE = max([A(:) ; B(:) ; 0]) ;\n\nif maxE > 0 && ~isequal(A,B),\n % Create a 2 by m array holding the elements of A and B:\n % - the first column refers to the numerators of the ratio (A)\n % - the second column refers to the denominators of the ratio (B)\n R = sparse(A,1,1,maxE,2) + sparse(B,2,1,maxE,2) ;\n \n % By flipping, cumsumming (over columns) and flipping again ...\n R = flipud(cumsum(flipud(R))) ; \n % ... we get numbers that indicate how many times a factor is present in\n % the expanded ratio. R(X,1) indicates the number of times (X+1) is present in\n % the numerator in the expanded ratio, and R(X,2) the number of times\n % (X+1) is present in the denominator. The difference will give us the\n % exponent for taking the power of the value (X+1).\n R = (R(:,1) - R(:,2)).' ; % exponents\n X = 2:(maxE+1) ; % base numbers (we now do need to add the 1)\n \n % We only used the nonzero entries, since X^0 = 1, and this may affect\n % the time used for ...\n q = find(R) ; \n % ... getting the total product\n FR = prod(X(q).^R(q)) ; % \nelse \n % All elements were less than 2, or A equals B\n FR = 1 ;\nend\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/23018-factorialratio/factorialratio.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193595, "lm_q2_score": 0.8947894682067639, "lm_q1q2_score": 0.8249259425795661}} {"text": "function e = line_cvt_energy ( n, a, b, x )\n\n%*****************************************************************************80\n%\n%% LINE_CVT_ENERGY computes the CVT energy for a given set of generators.\n%\n% Discussion:\n%\n% Given a set of generators G over the line [A,B], then the energy\n% is defined as\n% E = integral ( a <= x <= b ) ( x - g(x) )^2 dx\n% where g(x) is the nearest generator to the point x.\n%\n% For the 1D case, this integral can be evaluated exactly as the\n% sum of integrals over each subinterval:\n%\n% E(i) = integral ( xl <= x <= xr ) ( x - x(i) )^2 dx\n% = ( ( x(i) - xl )^3 + ( xr - x(i) )^3 ) / 3\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 July 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of generators.\n%\n% Input, real A, B, the left and right endpoints.\n%\n% Input, real X(N), the generator locations.\n%\n% Output, real E, the energy of the generator distribution.\n%\n e = 0.0;\n\n for j = 1 : n\n\n if ( j == 1 )\n xl = a;\n else\n xl = ( x(j-1) + x(j) ) / 2.0;\n end\n\n if ( j == n )\n xr = b;\n else\n xr = ( x(j) + x(j+1) ) / 2.0;\n end\n\n e = e + ( ( x(j) - xl )^3 + ( xr - x(j) )^3 ) / 3.0;\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/line_cvt_lloyd/line_cvt_energy.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428691, "lm_q2_score": 0.8774767874818408, "lm_q1q2_score": 0.8247521452397057}} {"text": "function [ x, seed ] = normal_01_sample ( seed )\n\n%*****************************************************************************80\n%\n%% NORMAL_01_SAMPLE samples the standard normal probability distribution.\n%\n% Discussion:\n%\n% The standard normal probability distribution function (PDF) has\n% mean 0 and standard deviation 1.\n%\n% The Box-Muller method is used.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 26 August 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer SEED, a seed for the random number generator.\n%\n% Output, X, a sample of the standard normal PDF.\n%\n% Output, integer SEED, an updated seed for the random number generator.\n%\n [ r1, seed ] = r8_uniform_01 ( seed );\n [ r2, seed ] = r8_uniform_01 ( seed );\n x = sqrt ( -2.0 * log ( r1 ) ) * cos ( 2.0 * pi * 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/prob/normal_01_sample.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9511422186079557, "lm_q2_score": 0.8670357512127873, "lm_q1q2_score": 0.824674308020946}} {"text": "function value = ball_unit_volume_3d ( )\n\n%*****************************************************************************80\n%\n%% BALL_UNIT_VOLUME_3D computes the volume of a unit ball in 3D.\n%\n% Integration region:\n%\n% Points (X,Y,Z) such that\n%\n% X**2 + Y**2 + Z**2 <= 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 26 May 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Output, real BALL_UNIT_VOLUME_3D, the volume of the ball.\n%\n value = ( 4.0E+00 / 3.0E+00 ) * pi;\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/stroud/ball_unit_volume_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802350995703, "lm_q2_score": 0.8976952968970956, "lm_q1q2_score": 0.824515387341823}} {"text": "function lambda = lambda_measure ( dim_num, n, z )\n\n%*****************************************************************************80\n%\n%% LAMBDA_MEASURE determines the pointset quality measure LAMBDA.\n%\n% Discussion:\n%\n% The LAMBDA measure of point distribution quality for a set Z of\n% N points in an DIM_NUM-dimensional region is defined as follows:\n%\n% Let\n%\n% GAMMA(I) = minimum ( 1 <= J <= N, I /= J ) distance ( Z(I), Z(J) )\n%\n% and let\n%\n% GAMMA_AVE = sum ( 1 <= I <= N ) GAMMA(I) / N\n%\n% then\n%\n% LAMBDA = sqrt ( sum ( 1 <= I <= N ) ( GAMMA(I) - GAMMA_AVE )**2 / N )\n% / GAMMA_AVE\n%\n% An ideally regular mesh would have GAMMA(I) = GAMMA_AVE for all I,\n% so that LAMBDA would be 0. Under this measure, the mesh with the\n% smaller value of LAMBDA is to be preferred.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 November 2004\n%\n% Author:\n%\n% Max Gunzburger\n% John Burkardt\n%\n% Reference:\n%\n% Max Gunzburger and John Burkardt,\n% Uniformity Measures for Point Samples in Hypercubes.\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the spatial dimension.\n%\n% Input, integer N, the number of points.\n%\n% Input, real Z(DIM_NUM,N), the points.\n%\n% Output, real LAMBDA, the LAMBDA quality measure.\n%\n% Local parameters:\n%\n% Local, real GAMMA_MAX, the maximum, over all points,\n% of the minimum distance to a distinct point.\n%\n% Local, real GAMMA_MIN, the minimum, over all points,\n% of the minimum distance to a distinct point.\n%\n\n%\n% Take care of ridiculous cases.\n%\n if ( n <= 1 )\n lambda = 0.0;\n return\n end\n%\n% Compute the minimum spacing between distinct points of the set.\n%\n gamma = pointset_spacing ( dim_num, n, z );\n%\n% Average the minimum spacing.\n%\n gamma_ave = sum ( gamma(1:n) ) / n;\n%\n% Compute a weighted variance.\n%\n if ( gamma_ave <= 0.0 )\n lambda = r8_huge ( );\n else\n lambda = sqrt ( sum ( ( gamma(1:n) - gamma_ave ).^2 ) / n ) / gamma_ave;\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/quality/lambda_measure.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172615983309, "lm_q2_score": 0.868826784729373, "lm_q1q2_score": 0.8244447333686792}} {"text": "function Adj = polygon(N, d, rad)\n% Adj = polygon(N, d, rad)\n% Plots the regular polygon {N/d} with vertices on a circle of radius\n% 'rad'. The output 'Adj' is the adjacency matrix of the corresponding\n% graph. \n%\n% Description:\n% ------------\n% Let d < N be a positive integer and define p = N/d.\n% Let y_{1} be a point on the unit circle. Let R be clockwise\n% rotation by the angle t = 2*pi/p. The generalized regular\n% polygon {p} is given by the points y_{i+1} = R * y_{i}, and edges\n% between points i and i+1.\n%\n% Example: \n% --------\n% polygon(9, 4, 1);\n% \n% \n% Nima Moshtagh (nima@seas.upenn.edu)\n% University of Pennsylvania\n%\n% Sept. 2007\n%\n\n\n% check the values of 'd' and 'N'. They must be integers.\nif (d - round(d)) ~= 0 || (N - round(N)) ~= 0 \n display('error: Input parameters N and d must be integers!');\n return;\nelseif d > N,\n display('error: d must be less than or equal to N.');\n return\nelse\n p = N/d;\n t = 2*pi/p;\nend\n\n% generate the vertices.\n%theta = [pi/N : 2*pi/N : 2*pi];\ntheta = [0 : 2*pi/N : 2*pi]\nPos = rad * exp(i*theta);\n\nX = real(Pos);\nY = imag(Pos);\n\n% plot the vertices on a circle\nplot(X,Y,'o');\naxis([-2*rad 2*rad -2*rad 2*rad]);\n\nA = zeros(N);\nfor j = 1:N,\n % compute the position of the neighboring vertix\n node = exp(i*t) *Pos(j);\n xx = real(node);\n yy = imag(node);\n \n % find the index of the neighboring vertix\n indx = mod(j+d,N);\n if indx == 0,\n indx = N;\n end\n A(j,indx) = 1;\n % connect the vertices\n line([X(j) xx], [Y(j) yy]);\nend\naxis equal\n% the Adjacency matrix \nAdj = A + A';\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/16608-regular-polygons/polygon.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172572644806, "lm_q2_score": 0.8688267728417087, "lm_q1q2_score": 0.8244447183229042}} {"text": "function fx = p10_fun ( n, x )\n\n%*****************************************************************************80\n%\n%% P10_FUN evaluates the integrand for problem 10.\n%\n% Interval:\n%\n% 0 <= x <= 1\n%\n% Integrand:\n%\n% 1 / ( 1 + x )\n%\n% Antiderivative:\n%\n% ln ( 1 + x )\n%\n% Exact Integral:\n%\n% ln ( 2 )\n%\n% Approximate Integral (25 digits):\n%\n% 0.6931471805599453094172321...\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 November 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% David Kahaner,\n% Comparison of Numerical Quadrature Formulas,\n% in Mathematical Software, edited by John R Rice,\n% Academic Press, 1971.\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 = 1.0 ./ ( 1.0 + x );\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/p10_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122113355091, "lm_q2_score": 0.9086178913651383, "lm_q1q2_score": 0.824400108273511}} {"text": "function root = newton(f,g,xo,epsilon)\n% Program : newton.m\n%\n% Purpose : find the root of a given single variable function within the\n% given interval\n%\n% Author : Aamir Alaud Din\n% Date : 20.09.2013\n%\n% Inputs : At least three input arguments are required viz., function,\n% derivative of the function, and initial guess\n%\n% Syntax : root = newton(f,g,xo)\n% where f is an inline function and is continuous in the given\n% interval\n% e.g., f = inline('sin(x)','x');\n% g is the first derivative of f in the form of inline function\n% and is continuous in the given interval\n% e.g., g = inline('cos(x)','x'); \n% xo is the initial guess which lies in the given interval\n%\n% Example: root = newton(f,g,5)\n% The fourth input argument is the stopping criteria\n% If the function value deceeds epsilon, the loop terminates\n% giving the root. Default is 1e-6.\n%\n% Syntax : root = newton(f,g,xo,epsilon)\n% where f, g, xo, and epsilon are explained above.\n%\n% Example: root = bisection(f,g,-2,1e-9)\n\nif (nargin < 3)\n error('Less input arguments provided.');\n \nelseif (nargin == 3)\n epsilon = 1e-6;\n Iter = 0;\n fprintf('Iteration\\t\\t xo\\t\\t x1\\t\\t\\tf(x)\\t\\t\\tg(x)\\n');\n fprintf('=========\\t\\t ======\\t\\t ======\\t\\t===========\\t\\t===========\\t\\t\\n');\n while (abs(f(xo)) >= epsilon)\n Iter = Iter + 1;\n if (g(xo) == 0)\n fprintf('g(xo) is zero on iteration number %d',Iter);\n fprintf('\\n');\n disp('We can''t compute the root');\n return;\n end\n x1 = xo - (f(xo)/g(xo));\n fprintf('%3d',Iter);\n fprintf('%20.4f',xo);\n fprintf('%12.4f',x1);\n fprintf('%16.4f',f(xo));\n fprintf('%16.4f',g(xo));\n fprintf('\\n');\n xo = x1;\n end\n root = xo;\nelseif (nargin == 4)\n Iter = 0;\n fprintf('Iteration\\t\\t xo\\t\\t x1\\t\\t\\tf(x)\\t\\t\\tg(x)\\n');\n fprintf('=========\\t\\t ======\\t\\t ======\\t\\t===========\\t\\t===========\\t\\t\\n');\n while (abs(f(xo)) >= epsilon)\n Iter = Iter + 1;\n if (g(xo) == 0)\n fprintf('g(xo) is zero on iteration number %d',Iter);\n fprintf('\\n');\n disp('We can''t compute the root');\n return;\n end\n x1 = xo - (f(xo)/g(xo));\n fprintf('%3d',Iter);\n fprintf('%20.4f',xo);\n fprintf('%12.4f',x1);\n fprintf('%16.4f',f(xo));\n fprintf('%16.4f',g(xo));\n fprintf('\\n');\n xo = x1;\n end\n root = xo;\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/43575-newton-m/newton.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.9099070023734244, "lm_q1q2_score": 0.8243664724073396}} {"text": "%% Ex. 11 Another example for the usage of index for a matrix\n\n\nA = [3 5; 2 4];\nnorm1 = 0;\nfor m = 1:2\nfor n = 1:2\n norm1 = norm1+A(m,n)^2;\nend\nend\nnorm1 = sqrt(norm1)\n\n\n%Output:\n% norm1 = 7.348\n% Remark: This program calculates the Euclidean norm of the A matrix", "meta": {"author": "TheAlgorithms", "repo": "MATLAB-Octave", "sha": "e150b77ad256de46c1ce3815c3d7945ac4fc28dc", "save_path": "github-repos/MATLAB/TheAlgorithms-MATLAB-Octave", "path": "github-repos/MATLAB/TheAlgorithms-MATLAB-Octave/MATLAB-Octave-e150b77ad256de46c1ce3815c3d7945ac4fc28dc/matlab_for_beginners/part_4(array_nd_matrix)/program11.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947086083138, "lm_q2_score": 0.8723473663814338, "lm_q1q2_score": 0.8243636452988531}} {"text": "function C=discSinCosTrans(x,type)\n%%DISCSINCOSTRANS Compute the 1D discrete sine or cosine transformation of\n% a given array. All 16 standard types of sine and cosine\n% transforms are available plus a unitary version of the type\n% II even cosine transform.\n%\n%INPUTS: x An (N+1)X1 or 1X(N+1) real or complex vector whose discrete\n% sine or cosine transform is desired.\n% type A string specifying the type of discrete sine or cosine\n% transform desired. If omitted or an empty matrix is passed, the\n% default is 'CIIe'. Possible values are:\n% 'CIe' Perform a type I even discrete cosine transform. The\n% item in element k of the result is\n% x(0)+(-1)^k*X(N-1)+2*sum_{j=1}^{N-2}x(j)*cos(pi*j*k/(N-1))\n% where all indexation is form 0.\n% 'CIIe' Perform a type II even discrete cosine transform. The\n% item in element k of the result is the sum from n=0 to\n% N-1 of\n% 2*x(n)*cos(pi*k*(n+1/2)/N), where all indexation is from\n% 0.\n% 'CIIeU' This is the same as type CIIe, except for scaling. The\n% scaling is\n% CU(1)=CII(1)/(2*sqrt(N));\n% CU(2:end)=CII(2:end)*0.5*sqrt(2/N); where CIIe is the\n% type 2 transform and CU is the unitary transform.\n% 'CIIIe' Perform a type III even discrete cosine transform.\n% 'CIVe' Perform a type IV even discrete cosine transform.\n% 'CIo' Perform a type I odd discrete cosine transform.\n% 'CIIo' Perform a type II odd discrete cosine transform.\n% 'CIIIo' Perform a type III odd discrete cosine transform.\n% 'CIVo' Perform a type IV odd discrete cosine transform.\n% 'SIe' Perform a type I even discrete sine transform.\n% 'SIIe' Perform a type II even discrete sine transform.\n% 'SIIIe' Perform a type III even discrete sine transform.\n% 'SIVe' Perform a type IV even discrete sine transform.\n% 'SIIIe' Perform a type III even discrete sine transform.\n% 'SIVe' Perform a type IV even discrete sine transform.\n% 'SIo' Perform a type I odd discrete sine transform.\n% 'SIIo' Perform a type II odd discrete sine transform.\n% 'SIIIo' Perform a type III odd discrete sine transform.\n% 'SIVo' Perform a type IV odd discrete sine transform.\n%\n%OUTPUTS: C The (N+1)X1 or 1X(N+1) real discrete cosine or sine\n% transformation of x. \n%\n%The algorithms are implemented using the generalized discrete Fourier\n%transform (GDFT) based upon the relations of the sequences and the GDFT\n%that are given in [1]. The definition of the unitary version of the type\n%II transformation is taken from [2]. \n%\n%The inverse of this function is invDiscSinCosTrans.\n%\n%REFERENCES:\n%[1] S. Martucci, \"Symmetric convolution and the discrete sine and cosine\n% transforms,\" IEEE Transactions on Signal Processing, vol. 42, no. 5,\n% pp. 1038-1051, May 1994.\n%[2] J. Makhoul, \"A fast cosine transform in one and two dimensions,\" IEEE\n% Transactions on Acoustics, Speech, and Signal Processing, vol. ASSP-\n% 28, no. 1, pp. 27-34, Feb. 1980.\n%\n%December 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<2)\n type='CIIe';\nend\n\nN=length(x);\nif(size(x,1)==N)\n colVec=true;\nelse\n colVec=false;\nend\n\nx=x(:);\nswitch(type)\n case 'CIIeU'\n %Perform the CIIe transform\n C=genDFT([x;flip(x)],0,1/2);\n C=C(1:N);\n \n %Modify the weighting.\n C(1)=C(1)/(2*sqrt(N));\n C(2:end)=C(2:end)*0.5*sqrt(2/N);\n case 'CIe'\n C=fft([x;x((N-1):-1:2)]);\n C=C(1:N);\n case 'CIIe'\n C=genDFT([x;flip(x)],0,1/2);\n C=C(1:N);\n case 'CIIIe'\n C=genDFT([x;0;-flip(x(2:end))],1/2,0);\n C=C(1:N);\n case 'CIVe'\n C=genDFT([x;-flip(x)],1/2,1/2);\n C=C(1:N);\n case 'CIo'\n C=fft([x;flip(x(2:end))]);\n C=C(1:N);\n case 'CIIo'\n C=genDFT([x;flip(x(1:(end-1)))],0,1/2);\n C=C(1:N);\n case 'CIIIo'\n C=genDFT([x;-flip(x(2:end))],1/2,0);\n C=C(1:N);\n case 'CIVo'\n C=genDFT([x;0;-flip(x)],1/2,1/2);\n C=C(1:N);\n case 'SIe' \n C=1j*fft([0;x;0;-flip(x)]);\n C=C(2:(N+1));\n case 'SIIe'\n C=1j*genDFT([x;-flip(x)],0,1/2);\n C=C(2:(N+1));\n case 'SIIIe'\n C=1j*genDFT([0;x(1:end);flip(x(1:(end-1)))],1/2,0);\n C=C(1:N);\n case 'SIVe'\n C=1j*genDFT([x;flip(x)],1/2,1/2);\n C=C(1:N);\n case 'SIo'\n C=1j*fft([0;x;-flip(x)]);\n C=C(2:(N+1));\n case 'SIIo'\n C=1j*genDFT([x;0;-flip(x)],0,1/2);\n C=C(2:(N+1));\n case 'SIIIo'\n C=1j*genDFT([0;x;flip(x)],1/2,0);\n C=C(1:N);\n case 'SIVo'\n C=1j*genDFT([x;flip(x(1:(end-1)))],1/2,1/2);\n C=C(1:N);\n otherwise\n error('Discrete cosine transform type not suported.')\nend\n\n%Get rid of finite precision errors. We know that if the purely input is\n%real or imaginary, then the output must be the same.\nif(isreal(x))\n\tC=real(C);\nelseif(isImag(x))\n C=1j*imag(C);\nend\n\nif(~colVec)\n C=C.';\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/Signal_Processing/discSinCosTrans.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947086083138, "lm_q2_score": 0.8723473630627235, "lm_q1q2_score": 0.8243636421626893}} {"text": "classdef ChiSquareD\n%%CHISQUARED Functions to handle the central or non-central chi-squared\n% distributions. These distributions arise when summing the\n% squares of independent normal random variables. The result is\n% central if the mean of the normal random variables was zero.\n%Implemented methods are: mean, var, PDF, CDF, invCDF (only for the central\n% chi squared distribution), rand, (only for the\n% central chi squared distribution) entropy\n%\n%DEPENDENCIES: GammaD.m\n%\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nmethods(Static)\n\nfunction val=mean(nu,lambda)\n%%MEAN Obtain the mean of chi squared probability distribution.\n%\n%INPUTS: nu The number of degrees of freedom of the chi-squared\n% distribution. Note that nu>0.\n% lambda The non-centrality parameter of the distribution. In the\n% central chi-squared distribution, this is zero.\n%\n%OUTPUTS: val The mean of the chi squared distribution under consideration.\n%\n%The noncentral chi-squared distribution is descirbed in [1].\n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Noncentral Chi-Squared Distribution.\" From\n% MathWorld--A Wolfram Web Resource.\n% http://mathworld.wolfram.com/NoncentralChi-SquaredDistribution.html\n%\n%October 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n if(nargin<2||isempty(lambda))\n lambda=0;\n end\n\n val=nu+lambda;\nend\n\nfunction val=var(nu,lambda)\n%%VAR Obtain the variance of chi squared probability distribution for the\n% given number of degrees of freedom.\n%\n%INPUTS: nu The number of degrees of freedom of the chi-square\n% distribution. Note that nu>0.\n% lambda The non-centrality parameter of the distribution. In the\n% central chi-squared distribution, this is zero.\n%\n%OUTPUTS: val The variance of the chi squared distribution under\n% consideration.\n%\n%The noncentral chi-squared distribution is descirbed in [1].\n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Noncentral Chi-Squared Distribution.\" From\n% MathWorld--A Wolfram Web Resource.\n% http://mathworld.wolfram.com/NoncentralChi-SquaredDistribution.html\n%\n%October 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n if(nargin<2||isempty(lambda))\n lambda=0;\n end\n\n val=2*nu+4*lambda;\nend\n \nfunction val=PDF(x,nu,lambda)\n%%PDF Evaluate the chi squared probability distribution function (PDF) at\n% the desired points.\n%\n%INPUTS: x The point(s) at which the chi-squared PDF is to be evaluated.\n% Note that x>=0 for nonzero probabilities.\n% nu The number of degrees of freedom of the chi-square distribution.\n% Note that nu>0.\n% lambda The non-centrality parameter of the distribution. In the central\n% chi-squared distribution, this is zero.\n%\n%OUTPUTS: val The value(s) of the chi squared PDF evaluated at x.\n%\n%The noncentral chi-squared distribution is descirbed in [1].\n%\n%When lambda is very small but nonzero, the PDF function could run into\n%problems due to the logarithm of lambda. The logarithms were used instead\n%of a simpler form to lessen the numerical instability. If an invalid value\n%for the noncentral distribution is obtained, it is assumed that it is due\n%to using an extremely small nonzero value of lambda, and the result is\n%approximated using lambda=0.\n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Noncentral Chi-Squared Distribution.\" From\n% MathWorld--A Wolfram Web Resource.\n% http://mathworld.wolfram.com/NoncentralChi-SquaredDistribution.html\n%\n%September 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n if(nargin<3||isempty(lambda))\n lambda=0;\n end\n\n if(lambda==0)\n val=(1/(2^(nu/2)*gamma(nu/2))).*x.^((nu-2)/2).*exp(-x/2);\n else\n val=0.5*exp(-(x+lambda)/2+(nu/4-0.5)*(log(x)-log(lambda))).*besseli(nu/2-1,sqrt(lambda*x));\n \n if(~isfinite(val))\n val=(1/(2^(nu/2)*gamma(nu/2))).*x.^((nu-2)/2).*exp(-x/2);\n end\n end\n \n val(x<0)=0;\nend\n\nfunction prob=CDF(x,nu,lambda)\n%%CDF Evaluate the cumulative distribution function (CDF) of the central or\n% noncentral chi-squared distribution at desired points.\n%\n%INPUTS: x The point(s) at which the chi-squared CDF is to be evaluated.\n% Note that x>0 for nonzero values.\n% nu The number of degrees of freedom of the chi-square distribution.\n% Note that nu>0. When lambda is not zero, the CDF function is\n% numerically stabler when nu is an integer.\n% lambda The non-centrality parameter of the distribution. In the central\n% chi-squared distribution, this is zero.\n%\n%OUTPUTS: prob The value(s) of the CDF of the chi-squared distribution with\n% nu degrees of freedom and noncentrality parameter lambda\n% evaluated at x.\n%\n%The CDF of the central chi squared function with nu degrees of freedom\n%evaluated at x is just a special case of the incomplete gamma function, as\n%described at [1]. The incomplete gamma function is built into Matlab\n%without the use of any toolboxes. When the noncentrality parameter is\n%nonzero, the CDF is evaluated in terms of the equivalent noncentral gamma\n%distribution. The noncentral gamma algorithm is documented further in\n%GammaD.m.\n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Noncentral Chi-Squared Distribution.\" From\n% MathWorld--A Wolfram Web Resource.\n% http://mathworld.wolfram.com/NoncentralChi-SquaredDistribution.html\n%\n%September 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%Updated to use the noncentral gamma distribution's function\n%December 2014 David A. Karnick, Naval Research Laboratory, Washington D.C.\n\n if(nargin<3||isempty(lambda))\n lambda=0;\n end\n\n if(lambda==0)\n prob=gammainc(x/2,nu/2);\n else\n prob=GammaD.CDF(x,nu/2,2,lambda);\n end\n prob(x<=0)=0;\nend\n \nfunction val=invCDF(prob,nu)\n%%INVCDF Evaluate the inverse of the cumulative distribution function (CDF)\n% of the central chi squared distribution. This is only implemented\n% for the central chi-squared distribution.\n%\n%INPUTS: prob The probability or probabilities (0<=prob<=1) at which the \n% argument of the CDF is desired.\n% nu The number of degrees of freedom of the chi-squared\n% distribution. Note that nu>0.\n%\n%OUTPUTS: val The argument(s) of the CDF that would give the probability or\n% probabilities in prob.\n%\n%The CDF of the chi squared function with nu degrees of freedom evaluated\n%at x is just a special case of the incomplete gamma function, as described\n%on Mathworld at [1]. The inverse incomplete gamma function is built into\n%Matlab without the use of any toolboxes and thus is called here.\n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Noncentral Chi-Squared Distribution.\" From\n% MathWorld--A Wolfram Web Resource.\n% http://mathworld.wolfram.com/NoncentralChi-SquaredDistribution.html\n%\n%September 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n val=2*gammaincinv(prob,nu/2);\nend\n\nfunction vals=rand(N,nu,lambda)\n%%RAND Generate chi-squared 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% nu The number of degrees of freedom of the chi-squared\n% distribution. Note that nu>0. If lambda is not zero, nu >=1.\n% lambda The non-centrality parameter of the distribution. In the central\n% chi-squared distribution, this is zero. If this parameter is\n% omitted or an empty matrix is passed, then 0 is used.\n%\n%OUTPUTS: vals A matrix whose dimensions are determined by N of the\n% generated chi-squared random variables.\n%\n%The algorithm for the central chi squared distribution is an\n%implementation of the inverse transform algorithm of Chapter 5.1 of [1].\n%When the noncentral distribution is used, the random variables are\n%generated by summing the squares of normally distributed random variables.\n%\n%A non-central chi squared distribution is the sum of a chi-squared\n%distribution with nu-1 degrees of freedom plus the squared of a normal\n%distribution with mean sqrt(lambda) and standard deviation 1. This is how\n%the noncentral distribution is generated and why it is required that\n%nu>=1.\n%\n%REFERENCES:\n%[1] S. M. Ross, Simulation, Ed. 4, Amsterdam: Elsevier, 2006.\n%\n%September 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n if(nargin<3||isempty(lambda))\n lambda=0;\n end\n\n if(isscalar(N))\n dims=[N, N];\n else\n dims=N;\n end\n\n if(lambda==0)\n U=rand(dims);\n vals=ChiSquareD.invCDF(U,nu);\n else\n U=rand(dims);\n vals=ChiSquareD.invCDF(U,nu-1)+(sqrt(lambda)+randn(N)).^2;\n end\nend\n\nfunction entropyVal=entropy(nu)\n%%ENTROPY Obtain the differential entropy of the central chi squared\n% distribution given in nats. The differential entropy of a\n% continuous distribution is entropy=-int_x p(x)*log(p(x)) dx where\n% the integral is over all values of x. Units of nats mean that the\n% natural logarithm is used in the definition. Unlike the Shannon\n% entropy for discrete variables, the differential entropy of\n% continuous variables can be both positive and negative.\n%\n%INPUTS: nu The number of degrees of freedom of the chi-squared\n% distribution. Note that nu>0 \n%\n%OUTPUTS: entropyVal The value of the differential entropy in nats.\n%\n%Differential entropy is defined in Chapter 8 of [1].\n%\n%REFERENCES:\n%[1] T. M. Cover and J. A. Thomas, Elements of Information Theory, 2nd ed.\n% Hoboken, NJ: Wiley-Interscience, 2006.\n%\n%April 2018 David F. Crouse, Naval Research Laboratory, Washington D.C.\n \n entropyVal=nu/2+log(2)+gammaln(nu/2)+(1-nu/2)*psi(nu/2);\nend\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/ChiSquareD.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342012360933, "lm_q2_score": 0.8615382147637195, "lm_q1q2_score": 0.8241769219148606}} {"text": "function varargout = createRhombododecahedron()\n%CREATERHOMBODODECAHEDRON Create a 3D mesh representing a rhombododecahedron.\n%\n% [V, E, F] = createRhombododecahedron\n% V is a 14-by-3 array with vertex coordinate, \n% E is a 12-by-2 array containing indices of neighbour vertices,\n% F is a 8-by-3 array containing vertices array of each face.\n%\n% [V, F] = createRhombododecahedron;\n% Returns only the vertices and the face vertex indices.\n%\n% MESH = createRhombododecahedron;\n% Returns the data as a mesh structure, with fields 'vertices', 'edges'\n% and 'faces'.\n%\n% Example\n% [v, e, f] = createRhombododecahedron;\n% drawMesh(v, f);\n%\n%\n% See also\n% meshes3d, drawMesh\n\n% ---------\n% author : David Legland \n% e-mail: david.legland@inra.fr\n% INRA - TPV URPOI - BIA IMASTE\n% created the 10/02/2005.\n%\n\n% HISTORY\n% 04/01/2007: remove unused variables\n\nnodes = [0 0 2;...\n 1 -1 1;1 1 1;-1 1 1;-1 -1 1;...\n 2 0 0;0 2 0;-2 0 0;0 -2 0;...\n 1 -1 -1;1 1 -1;-1 1 -1;-1 -1 -1;...\n 0 0 -2];\n\nedges = [...\n 1 2;1 3;1 4;1 5;...\n 2 6;2 9;3 6;3 7;4 7;4 8;5 8;5 9;...\n 6 10;6 11;7 11;7 12;8 12;8 13;9 10;9 13; ...\n 10 14;11 14;12 14;13 14];\n\nfaces = [...\n 1 2 6 3;...\n 1 3 7 4;...\n 1 4 8 5;...\n 1 5 9 2;...\n 2 9 10 6;...\n 3 6 11 7;...\n 4 7 12 8;...\n 5 8 13 9;...\n 6 10 14 11;...\n 7 11 14 12;...\n 8 12 14 13;...\n 9 13 14 10];\n \n% format output\nvarargout = formatMeshOutput(nargout, nodes, edges, faces);\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/z_geom3d/meshes3d/createRhombododecahedron.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.9019206758704633, "lm_q1q2_score": 0.8240637454042669}} {"text": "function a = ris ( n )\n\n%*****************************************************************************80\n%\n%% RIS returns the RIS matrix.\n%\n% Discussion:\n%\n% This is sometimes called the \"dingdong\" matrix, invented by F N Ris.\n%\n% Formula:\n%\n% A(I,J) = 1 / ( 3 + 2 * N - 2 * I - 2 * J )\n%\n% Example:\n%\n% N = 5\n%\n% 1/9 1/7 1/5 1/3 1\n% 1/7 1/5 1/3 1 -1\n% 1/5 1/3 1 -1 -1/3\n% 1/3 1 -1 -1/3 -1/5\n% 1 -1 -1/3 -1/5 -1/7\n%\n% Properties:\n%\n% A is a Cauchy matrix.\n%\n% A is a Hankel matrix: constant along anti-diagonals.\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% The eigenvalues of A cluster around PI/2 and -PI/2.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 20 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% John Nash,\n% Compact Numerical Methods for Computers: Linear Algebra and\n% Function Minimisation,\n% John Wiley, 1979, page 210.\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\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 a(i,j) = 1.0 / ( 3 + 2 * n - 2 * i - 2 * 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/ris.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.9019206712569268, "lm_q1q2_score": 0.8240637433090063}} {"text": "function [ c_est, r_est, c_err, r_err ] = sphere_random_centralize ( ...\n m, n, c, r )\n\n%*****************************************************************************80\n%\n%% SPHERE_RANDOM_CENTRALIZE estimates the center of a sphere.\n%\n% Discussion:\n%\n% We generate N points on the M dimensional sphere of center C and radius R.\n% We seek to estimate the values of C and R.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 April 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, the spatial dimension.\n%\n% Input, integer N, the number of random points to generate.\n%\n% Input, real C(M,1), the center.\n%\n% Input, real R, the radius.\n%\n% Output, real C_EST(M,1), R_EST, the estimated center and radius.\n%\n% Output, real C_ERR, R_ERR, the errors in the estimates.\n%\n c = c(:);\n x = sphere_surface_sample ( m, n, c, r );\n\n c_est = sum ( x, 2 ) / n;\n c_err = norm ( c - c_est );\n\n r_mat = x - repmat ( c_est, 1, n );\n r_mat = r_mat.^2;\n r_mat = sum ( r_mat, 1 );\n r_mat = sqrt ( r_mat );\n r_est = sum ( r_mat ) / n;\n r_err = abs ( r - r_est );\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/centralize/sphere_random_centralize.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676518712608, "lm_q2_score": 0.90192067455231, "lm_q1q2_score": 0.8240637420798816}} {"text": "% Create Noise Signal and embed sine wave in it at a random location\nnpts=5000; % # points in signal\nsrate=1000; % sample rate (Hz)\ndur=npts/srate; % signal duration in sec\namp_n=3.5; % noise amplitude\namp_t=1.0; % sine wave amplitude\nfreq=100; % sine wave frequency\nsinepts=400; % # points in sine wave\n\nt=[0:npts-1]/srate; % signal time base\nsine_t=[0:sinepts-1]/srate; % sine wave time base\nnoise=(rand(1,npts)-.5)*amp_n; %noise signal\nsinewave=amp_t*(sin(2*pi*freq*sine_t)); % sine wave\n% random location of sinewave\nsinepos=floor(rand(1,1)*(npts-sinepts))+1;\nsignal = noise; % make signal equal to noise\nendsine = sinepos + sinepts-1; %calc index end of sine wave\n% add sinewave to signal starting at index sinepos\nsignal(sinepos:endsine) = signal(sinepos:endsine) + sinewave;\n\n% Plot signal\nsubplot(5,1,1)\nplot(t,signal);\nhold on\n%plot red dot on location of sine wave start\nplot(sinepos/srate,0,'.r');\nhold off\ntitle('Original Signal');\n\n\n% Step 1: Filter signal\nhbandwidth=5; %half bandwidth\nnyquist=srate/2;\nntaps=200;\nhpf=(freq-hbandwidth)/nyquist;\nlpf=(freq+hbandwidth)/nyquist;\n[b,a]=fir1(ntaps, [hpf lpf]); %calc filter coefficients\nsignal_f=filter(b,a,signal); %filter signal\nsubplot(5,1,2)\nplot(t,signal_f); %plot filtered signal\nhold on\n%plot red dot on location of sine wave\nplot(sinepos/srate,0,'.r');\nhold off\ntitle('Step 1. Filter Signal');\n\n\n\nsignal_r=abs(signal_f); %abs value of filtered signal\nsubplot(5,1,3)\nplot(t,signal_r); %plot filtered signal\nhold on\n%plot red dot on location of sine wave\nplot(sinepos/srate,0,'.r');\nhold off\ntitle('Step 2. Rectify Signal');\n\n\n% Step 3: Low-pass filter rectified signal\nlpf=10/nyquist; % low-pass filter corner frequency\nnpoles=6;\n[b,a]=butter(npoles, lpf); % Butterworth filter coeff\nsignal_env=filter(b,a,signal_r); %Filter signal\nsubplot(5,1,4)\nplot(t,signal_env); %plot filtered signal\nhold on\n%plot red dot on location of sine wave\nplot(sinepos/srate,0,'.r');\nhold off\ntitle('Step 3. Envelope Signal');\n\n\n\n% Step 4: Threshold signal\nthreshold=amp_t/2;\ngated=(signal_env>threshold);\nsubplot(5,1,5)\nplot(t,signal_env); %plot filtered signal\nhold on\n%plot red dot on location of sine wave\nplot(sinepos/srate,0,'.r');\nplot(t, gated, 'r'); % plot threshold signal\nhold off\ntitle('Step 4. Threshold Signal');\nxlabel('Time (s)');\n\n\nd_gated=diff(gated);\nplot(d_gated);\n\nfind(d_gated==1)\n\nfind(d_gated == -1)\n\nabs(find(d_gated==1) - find(d_gated == -1))\n\n\n\n", "meta": {"author": "yandld", "repo": "nav_matlab", "sha": "da70cb2083de407409ebe1ec1096a308611cf063", "save_path": "github-repos/MATLAB/yandld-nav_matlab", "path": "github-repos/MATLAB/yandld-nav_matlab/nav_matlab-da70cb2083de407409ebe1ec1096a308611cf063/study/MATLABsimplified/energy_detector.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.8239724741385371}} {"text": "function E = r8mat_expm2 ( A )\n\n%*****************************************************************************80\n%\n%% R8MAT_EXPM2 uses the Taylor series for the matrix exponential.\n%\n% Discussion:\n%\n% Formally,\n%\n% exp ( A ) = I + A + 1/2 A^2 + 1/3! A^3 + ...\n%\n% This function sums the series until a tolerance is satisfied.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 March 2011\n%\n% Author:\n%\n% Cleve Moler, Charles Van Loan\n%\n% Reference:\n%\n% Cleve Moler, Charles VanLoan,\n% Nineteen Dubious Ways to Compute the Exponential of a Matrix,\n% Twenty-Five Years Later,\n% SIAM Review,\n% Volume 45, Number 1, March 2003, pages 3-49.\n%\n% Parameters:\n%\n% Input, real A(N,N), the matrix.\n%\n% Output, real E(N,N), the estimate for exp(A).\n%\n E = zeros ( size ( A ) );\n F = eye ( size ( A ) );\n k = 1;\n\n while ( 0 < norm ( E + F - E, 1 ) )\n E = E + F;\n F = A * F / k;\n k = k + 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/matrix_exponential/r8mat_expm2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.879146761176671, "lm_q1q2_score": 0.8239458348853675}} {"text": "function b = r8vec_sht ( n, a )\n\n%*****************************************************************************80\n%\n%% R8VEC_SHT computes a \"slow\" Hartley transform of an R8VEC.\n%\n% Discussion:\n%\n% The discrete Hartley transform B of a set of data A is\n%\n% B(I) = 1/sqrt(N) * Sum ( 0 <= J <= N-1 ) A(J) * CAS(2*PI*I*J/N)\n%\n% Here, the data and coefficients are indexed from 0 to N-1.\n%\n% With the above normalization factor of 1/sqrt(N), the Hartley\n% transform is its own inverse.\n%\n% This routine is provided for illustration and testing. It is inefficient\n% relative to optimized routines.\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% Reference:\n%\n% Ralph Hartley,\n% A More Symmetrical Fourier Analysis Applied to Transmission Problems,\n% Proceedings of the Institute of Radio Engineers,\n% Volume 30, pages 144-150, 1942.\n%\n% Parameters:\n%\n% Input, integer ( kind = 4 ) N, the number of data values.\n%\n% Input, real A(N), the data to be transformed.\n%\n% Output, real B(N), the transformed data.\n%\n b(1:n) = 0.0;\n\n for i = 1 : n\n for j = 1 : n\n theta = 2.0 * pi * mod ( ( i - 1 ) * ( j - 1 ), n ) / n;\n b(i) = b(i) + a(j) * ( cos ( theta ) + sin ( theta ) );\n end\n end\n\n b(1:n) = b(1:n) / sqrt ( 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/sftpack/r8vec_sht.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.8757869867849167, "lm_q1q2_score": 0.8239314226092502}} {"text": "function F = ml_Fmeasure(cluster_labels, class_labels)\n%ML_FMEASURE Compute the Fmeasure for clustering with external validity\n%\n%\n% http://www.uni-weimar.de/medien/webis/teaching/lecturenotes/machine-learning/unit-en-cluster-analysis-evaluation.pdf\n% slide number 23-26\n%\n% Macro average F-measure\n%\n% Fm is an N x M matrix (N number of classes, M number of clusters) where\n% Fm(i,j) is the F-measure of the jth cluster computed with respect to\n% the ith class\n%\n% \n% input -----------------------------------------------------------------\n% \n% - cluster_labels : N x 1 vector of cluster labels given by the clustering algorithm\n% (N is the size of data)\n%\n% - class_labels : N x 1 vector of class labels (ground truth)\n%\n% output ----------------------------------------------------------------\n%\n% - F = macro averaged F-measure\n\n\nnbOfClusters = length(unique(cluster_labels));\nnbOfClasses = length(unique(class_labels));\nsizeClasses = zeros(nbOfClasses,1);\n\nFm = zeros(nbOfClasses,nbOfClusters);\n\nunique_cluster_labels = unique(cluster_labels);\nunique_class_labels = unique(class_labels);\n\n% for i = 1:nbOfClasses\n% for j = 1:nbOfClusters\n% N=0;\n% for k = 1:length(cluster_labels)\n% if(cluster_labels(k) == j && class_labels(k) == i)\n% N = N+1;\n% end\n% end\n% Precision = N/length(find(cluster_labels==j));\n% Recall = N/length(find(class_labels==i));\n% Fm(i,j) = 2*Precision*Recall/(Precision+Recall);\n% end\n% end\n\n\nfor i = 1:nbOfClasses\n for j = 1:nbOfClusters\n N=0;\n for k = 1:length(cluster_labels)\n if(cluster_labels(k) == unique_cluster_labels(j) && class_labels(k) == unique_class_labels(i))\n N = N+1;\n end\n end\n Precision = N/length(find(cluster_labels==unique_cluster_labels(j)));\n Recall = N/length(find(class_labels==unique_class_labels(i)));\n Fm(i,j) = 2*Precision*Recall/(Precision+Recall);\n end\nend\n\nfor m = 1:nbOfClasses\n sizeClasses(m,:) = length(find(class_labels==unique_class_labels(m)));\nend\n\nF = sum(max(Fm,[],2).*sizeClasses)/sum(sizeClasses);\n\nend\n\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/evaluation/clustering_metrics/ml_Fmeasure.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346504434783, "lm_q2_score": 0.8807970654616711, "lm_q1q2_score": 0.8238504562959887}} {"text": "function [ X ] = uniformCircle(c,R,N)\n% X = uniformCircle(c,R,N)\n% inputs : c = [c1,c2] center of the circle, R radius, N number of points\n% output : X of size Nx2, points uniformly distributed on the cricle\ntheta = 2*pi*rand(N,1);\nX = [c(1)+R*cos(theta) c(2)+R*sin(theta)];\n\nend\n\n", "meta": {"author": "SwanLab", "repo": "Swan", "sha": "f8355f3561bb1a1603f56b3676873147d22a511e", "save_path": "github-repos/MATLAB/SwanLab-Swan", "path": "github-repos/MATLAB/SwanLab-Swan/Swan-f8355f3561bb1a1603f56b3676873147d22a511e/gypsilabModified/openEbd/CloudsOfPoints/uniformCircle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.948154531885212, "lm_q2_score": 0.8688267643505193, "lm_q1q2_score": 0.82378203404211}} {"text": "function c = opoly(x,y,n)\n%\n% opolyfit OPOLYFIT(x,y,n) finds the n coefficients of a polynomial\n%\t\t formed from the data in row vector x that fits the data\n%\t\t in row vector y in a least-squares sense. Orthogonal\n%\t\t polynomials are used to improve accuracy. See also polyfit.\n%\n%\t\t c = opolyfit(x,y,n)\n%\t\t c ---\tcoefficient vector, size n\n%\n%\t\t References:\n%\t\t G. E. Forsythe, \"Generation and use of orthogonal poly-\n%\t\t nomials for data fitting on a digital computer\",\n%\t\t J. SIAM, 5(1957), 74-88.\n%\n%\t\t P. F. Hultquist, \"Numerical Methods for Engineers and\n%\t\t Computer Scientists\", Benjamin-Cummings, 1988.\n%\n%\t\t Copyright 1992. Gordon\tJ. Frazer, Signal Processing Research\n%\t\t Laboratory, and Roy J. Hughes, Laboratory for Instrumental and\n%\t\t Developmental Chemistry, QUT, Brisbane, AUSTRALIA, 1992.\n%\t\t Email:\tg.frazer@qut.edu.au or\tr.hughes@qut.edu.au\nn=n+1; % To make it similar to MATLAB polyfit.m\n\nif n<1\n error('polynomial order too small, must be greater than or equal to one');\nend\nif n+1>length(x)\n error('polynomial order too large for number of data points');\nend\n% normalise y to improve numerical stability\nyscale=0.5/max(abs(y));\nyy=yscale*y;\n% initialise opoloyfit\ngamma_0=length(x);\nalpha_0=mean(x);\nPC=zeros(n);\nPC(1,1)=1;\na=zeros(1,n);\na(1)=mean(yy);\n% calculate the\tfirst iteration\tmanually\nPC(2,1:2)=conv([1,-alpha_0],PC(1,1));\ngamma_k=sum(polyval(PC(2,1:2),x).*polyval(PC(2,1:2),x));\nbeta_k=gamma_k/gamma_0;\nalpha_k=sum(x.*(polyval(PC(2,1:2),x).*polyval(PC(2,1:2),x)))/gamma_k;\na(2)=sum(yy.*polyval(PC(2,1:2),x))/gamma_k;\n% calculate for\tthe remaining polynomial orders\nfor k=2:n-1\n PC(k+1,1:k+1)=conv([1,-alpha_k],PC(k,1:k))-beta_k*[0,0,PC(k-1,1:k-1)];\n gamma_km1=gamma_k;\n gamma_k=sum(polyval(PC(k+1,1:k+1),x).*polyval(PC(k+1,1:k+1),x));\n beta_k=gamma_k/gamma_km1;\n alpha_k=sum(x.*(polyval(PC(k+1,1:k+1),x).*polyval(PC(k+1,1:k+1),x)))/gamma_k;\n a(k+1)=sum(yy.*polyval(PC(k+1,1:k+1),x))/gamma_k;\nend\n% combine the a's to simplify the polynomial\nfor i=1:n\n PC(i,:)=a(i)*PC(i,:);\nend\nfor i=1:n\n cc(i)=sum(diag(PC,i-n));\nend\n% unnormalise c\tby the y scale factor\nc=(1/yscale)*cc;\n\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/tfsa_7.0/win64_bin/opoly.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.899121367808974, "lm_q1q2_score": 0.8236937205961095}} {"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n\n\n% circular convolution \n\n\n\n% mod(-m,N)\nN=4;\nfor m=0:3\np(m+1)=mod(-m,N);\nend\np\n\n\n\n\n% circular time-reversed sequence\nh=[1,1,0.5,2];\nfor m=0:3\nhs(1+m)=h(1+p(m+1));\nend\nhs'\nstem(0:N-1,hs);\naxis([-.4 3.4 -.2 2.2])\nlegend('h_s(m)=h[((-m))_N]')\n\n\n\n% circular convolution\nclear y;\nfigure\nN=4;\nx=[1,0,2.5,1.5];\nm=0:N-1;\nstem(m,x);\naxis([-.4 3.4 -.2 2.9])\nlegend('x[m]')\nn=0;\nhsn=circshift(hs',n);\nstem(m,hsn);\naxis([-.4 3.4 -.2 2.2]);\nlegend('h[((n-m))_N],n=0')\ny(n+1)=sum( x.*hsn')\n% or alternatively \n% y(n+1)=x*hsn;\n\nfigure\nm=0:N-1;\nstem(m,x);\naxis([-.4 3.4 -.2 2.9])\nlegend('x[m]')\n\nfigure\nn=1;\nhsn=circshift(hs',n);\nstem(m,hsn);\naxis([-.4 3.4 -.2 2.2]);\nlegend(' h[((n-m))_N], n=1')\ny(n+1)=sum(x.*hsn')\n\nfigure\nn=2;\nhsn=circshift(hs',n);\nstem(m,hsn);\naxis([-.4 3.4 -.2 2.2]);\nlegend(' h[((n-m))_N], n=2')\ny(n+1)=sum(x.*hsn')\n\nfigure\nn=3;\nhsn=circshift(hs',n);\nstem(m,hsn);\naxis([-.4 3.4 -.2 2.2]);\nlegend('h[((n-m))_N], n=3')\ny(n+1)=x*hsn\n\nfigure\nstem(m,y)\naxis([-.4 3.4 -.2 7.2]);\ntitle('circular convolution')\nlegend(' y[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/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/7/c78.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.8872046034098933, "lm_q1q2_score": 0.8236885599416418}} {"text": "function a = c4mat_test ( n )\n\n%*****************************************************************************80\n%\n%% C4MAT_TEST sets up a test matrix.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 04 April 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Output, complex A(N,N), the Fourier matrix.\n%\n complex_i = complex ( 0.0, 1.0 );\n \n for i = 1 : n\n for j = 1 : n\n\n angle = 2.0 * pi * ( i - 1 ) * ( j - 1 ) / n;\n\n a(i,j) = exp ( complex_i * angle ) / sqrt ( n );\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/blas0/c4mat_test.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.8872045862611166, "lm_q1q2_score": 0.8236885492927927}} {"text": "function varargout = rosenbrock(x)\n%ROSENBROCK Rosenbrock's 'banana' function in 2D\n\nif nargin == 0\n varargout{1} = [-2,-1]; % LB\n varargout{2} = [2,3]; % UB\n varargout{3} = [0,3000]; % Zlim\n varargout{4} = [-26.5,60]; % view\n varargout{5} = [1,1]; % xmin\n varargout{6} = 'Rosenbrock function'; % name\n varargout{7} = [-0.5,2.5]; % default x0\n return;\nend\n\nif size(x,2) == 1; x = x'; end\n\nvarargout{1} = 100*(x(:,2)-x(:,1).^2).^2+(1-x(:,1)).^2;\nif nargout > 1\n varargout{2} = [-400*(x(:,2)-x(:,1).^2).*x(:,1)-2*(1-x(:,1)), 200*(x(:,2)-x(:,1).^2)];\nend\n\nend", "meta": {"author": "lacerbi", "repo": "optimviz", "sha": "2cc41c19ffeaaa9a23239f53d80691cf3599357d", "save_path": "github-repos/MATLAB/lacerbi-optimviz", "path": "github-repos/MATLAB/lacerbi-optimviz/optimviz-2cc41c19ffeaaa9a23239f53d80691cf3599357d/rosenbrock.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768620069626, "lm_q2_score": 0.8723473829749844, "lm_q1q2_score": 0.8236502146373068}} {"text": "% Implementation of a simple version of the Dijkstra shortest path algorithm\n% Returns the distances from a single vertex to all others, doesn't save the path\n%\n% INPUTS: adjacency matrix, adj (nxn), start node s (index between 1 and n)\n% OUTPUTS: shortest path length from the start node to all other nodes, 1xn\n%\n% Note: Works for a weighted/directed graph.\n% GB: last updated, September 28, 2012\n\nfunction d = simpleDijkstra(adj,s)\n\nn=length(adj);\nd = inf*ones(1,n); % distance s-all nodes\nd(s) = 0; % s-s distance\nT = 1:n; % node set with shortest paths not found yet\n\nwhile not(isempty(T))\n [dmin,ind] = min(d(T));\n for j=1:length(T)\n if adj(T(ind),T(j))>0 && d(T(j))>d(T(ind))+adj(T(ind),T(j))\n d(T(j))=d(T(ind))+adj(T(ind),T(j));\n end\n end \n T = setdiff(T,T(ind));\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/simpleDijkstra.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9559813476288299, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.823614456786295}} {"text": "function [dist, pos] = distancePointEdge(point, edge)\n%DISTANCEPOINTEDGE Minimum distance between a point and an edge.\n%\n% DIST = distancePointEdge(POINT, EDGE);\n% Return the euclidean distance between edge EDGE and point POINT. \n% EDGE has the form: [x1 y1 x2 y2], and POINT is [x y].\n%\n% If EDGE is N-by-4 array, result is 1-by-4 array computed for each edge.\n% If POINT is a N-by-2 array, the result is a N-by-1 array.\n% If both POINT and EDGE are array, the result is computed for each\n% point-edge couple, and stored into a NP-by-NE array.\n%\n% [DIST POS] = distancePointEdge(POINT, EDGE);\n% Also returns the position of closest point on the edge. POS is\n% comprised between 0 (first point) and 1 (last point).\n%\n% Eaxmple\n% % Distance between a point and an edge\n% distancePointEdge([3 4], [0 0 10 0])\n% ans =\n% 4\n%\n% % Distance between several points and one edge\n% points = [10 15; 15 10; 30 10];\n% edge = [10 10 20 10];\n% distancePointEdge(points, edge)\n% ans = \n% 5 \n% 0\n% 10\n%\n% % Distance between a point a several edges\n% point = [14 33];\n% edges = [10 30 20 30; 20 30 20 40;20 40 10 40;10 40 10 30];\n% distancePointEdge(point, edges)\n% ans = \n% 3 6 7 4\n%\n%\n% See also \n% edges2d, points2d, distancePoints, distancePointLine\n% \n\n% ------\n% Author: David Legland\n% E-mail: david.legland@nantes.inra.fr\n% Created: 2004-04-07\n% Copyright 2004-2022 INRA - BIA-BIBS\n\n% direction vector of each edge (row vectors)\nvx = (edge(:, 3) - edge(:,1))';\nvy = (edge(:, 4) - edge(:,2))';\n\n% squared length of edges, with a check of validity\ndelta = vx .* vx + vy .* vy;\ninvalidEdges = delta < eps;\ndelta(invalidEdges) = 1; \n\n% difference of coordinates between point and edge first vertex \n% (NP-by-NE arrays)\ndx = bsxfun(@minus, point(:, 1), edge(:, 1)');\ndy = bsxfun(@minus, point(:, 2), edge(:, 2)');\n\n% compute position of points projected on the supporting line, by using\n% normalised dot product (NP-by-NE array)\npos = bsxfun(@rdivide, bsxfun(@times, dx, vx) + bsxfun(@times, dy, vy), delta);\n\n% ensure degenerated edges are correclty processed (consider the first\n% vertex is the closest)\npos(:, invalidEdges) = 0;\n\n% change position to ensure projected point is located on the edge\npos(pos < 0) = 0;\npos(pos > 1) = 1;\n\n% compute distance between point and its projection on the edge\ndist = hypot(bsxfun(@times, pos, vx) - dx, bsxfun(@times, pos, vy) - dy);\n", "meta": {"author": "mattools", "repo": "matGeom", "sha": "1fd2c937064be1ee1f4fd09fbfdf96145ebe5271", "save_path": "github-repos/MATLAB/mattools-matGeom", "path": "github-repos/MATLAB/mattools-matGeom/matGeom-1fd2c937064be1ee1f4fd09fbfdf96145ebe5271/matGeom/geom2d/distancePointEdge.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.8933094096048377, "lm_q1q2_score": 0.8235614461634646}} {"text": "function b = isPointInTriangle(point, p1, p2, p3)\n%ISPOINTINTRIANGLE Test if a point is located inside a triangle\n%\n% B = isPointInTriangle(POINT, V1, V2, V3)\n% POINT is a 1-by-2 row vector containing coordinates of the test point,\n% V1, V2 and V3 are 1-by-2 row vectors containing coordinates of triangle\n% vertices. The function returns 1 is the point is inside or on the\n% boundary of the triangle, and 0 otherwise.\n%\n% B = isPointInTriangle(POINT, VERTICES)\n% Specifiy the coordinates of vertices as a 3-by-2 array.\n%\n% If POINT contains more than one row, the result B has as many rows as\n% the input POINT.\n%\n%\n% Example\n% % vertices of the triangle\n% p1 = [0 0];\n% p2 = [10 0];\n% p3 = [5 10];\n% tri = [p1;p2;p3];\n% % check if points are inside\n% isPointInTriangle([0 0], tri)\n% ans =\n% 1\n% isPointInTriangle([5 5], tri)\n% ans =\n% 1\n% isPointInTriangle([10 5], tri)\n% ans =\n% 0\n% % check for an array of points\n% isPointInTriangle([0 0;1 0;0 1], tri)\n% ans =\n% 1\n% 1\n% 0\n%\n% See also\n% polygons2d, isPointInPolygon, isCounterClockwise\n%\n%\n% ------\n% Author: David Legland\n% e-mail: david.legland@grignon.inra.fr\n% Created: 2011-05-16, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2011 INRA - Cepia Software Platform.\n\n% if triangle vertices are given as a single array, extract vertices\nif nargin == 2\n p2 = p1(2, :);\n p3 = p1(3, :);\n p1 = p1(1, :);\nend\n\n% check triangle orientation\nisDirect = isCounterClockwise(p1, p2, p3);\n\n% check location of point with respect to each side\nif isDirect\n b12 = isCounterClockwise(p1, p2, point) >= 0;\n b23 = isCounterClockwise(p2, p3, point) >= 0;\n b31 = isCounterClockwise(p3, p1, point) >= 0;\nelse\n b12 = isCounterClockwise(p1, p2, point) <= 0;\n b23 = isCounterClockwise(p2, p3, point) <= 0;\n b31 = isCounterClockwise(p3, p1, point) <= 0;\nend\n\n% combines the 3 results\nb = b12 & b23 & b31;\n\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/geom2d/isPointInTriangle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.917302662976859, "lm_q1q2_score": 0.8234582819918588}} {"text": "function Z = projectData(X, U, K)\n%PROJECTDATA Computes the reduced data representation when projecting only\n%on to the top k eigenvectors\n% Z = projectData(X, U, K) computes the projection of\n% the normalized inputs X into the reduced dimensional space spanned by\n% the first K columns of U. It returns the projected examples in Z.\n%\n\n% You need to return the following variables correctly.\nZ = zeros(size(X, 1), K);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the projection of the data using only the top K\n% eigenvectors in U (first K columns).\n% For the i-th example X(i,:), the projection on to the k-th\n% eigenvector is given as follows:\n% x = X(i, :)';\n% projection_k = x' * U(:, k);\n%\n\nUreduce = U(:, 1:K);\n\nfor i=1:size(X, 1)\n z = Ureduce' * X(i, :)';\n Z(i, :) = z;\nend;\n\n% =============================================================\n\nend\n", "meta": {"author": "zsiciarz", "repo": "ml-coursera", "sha": "54208ee72b88f1dc3c9235e644a47f618b80441c", "save_path": "github-repos/MATLAB/zsiciarz-ml-coursera", "path": "github-repos/MATLAB/zsiciarz-ml-coursera/ml-coursera-54208ee72b88f1dc3c9235e644a47f618b80441c/octave/mlclass-ex7/projectData.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.8976952838963489, "lm_q1q2_score": 0.8234582693862063}} {"text": "function x = twos2dec(t)\n\n% TWOS2DEC Convert binary string two's complement to decimal integer.\n% \n% Usage: X = TWOS2DEC(T)\n% \n% Converts the two's complement representation as a string given by T to\n% decimal integers X. T can be a character array or cell string. Input\n% multiple numbers into T along the rows, and the output will be as a\n% column vector. Similarly to BIN2DEC, leading spaces in T are sign\n% extended (so treated as either 0 or 1 depending on the first non space\n% character), and embedded and trailing spaces are removed.\n% \n% Example:\n% >> twos2dec(['010 111'; ' 010111'; '101011 '; ' 10 1'])\n% \n% ans =\n% \n% 23\n% 23\n% -21\n% -3\n% \n% Inputs:\n% -T: string two's complement numbers to convert to decimal integers.\n% \n% Outputs:\n% -X: decimal representation of T.\n% \n% See also: DEC2TWOS, FIX2DEC, DEC2FIX, BIN2DEC, HEX2DEC, BASE2DEC.\n\nerror(nargchk(1, 1, nargin));\nif iscellstr(t)\n t = char(t);\nend\n\n% Convert to numbers.\nx = bin2dec(t);\n\n% Get the number of bits as the number of 0's and 1's in each row.\nnbits = sum(t == '0' | t == '1', 2);\n\n% Case for negative numbers.\nxneg = log2(x) >= nbits - 1;\n% xneg = bitshift(x, -(nbits - 1)) == 1;\nif any(xneg)\n x(xneg) = -( bitcmp(x(xneg), nbits(xneg)) + 1 );\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/38889-twos-complement-binary-strings/twos2dec.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.8840392817460332, "lm_q1q2_score": 0.8234494439514003}} {"text": "function y = logMvGamma(x, d)\n% Compute logarithm multivariate Gamma function \n% which is used in the probability density function of the Wishart and inverse Wishart distributions.\n% Gamma_d(x) = pi^(d(d-1)/4) \\prod_(j=1)^d Gamma(x+(1-j)/2)\n% log(Gamma_d(x)) = d(d-1)/4 log(pi) + \\sum_(j=1)^d log(Gamma(x+(1-j)/2))\n% Input:\n% x: m x n data matrix\n% d: dimension\n% Output:\n% y: m x n logarithm multivariate Gamma\n% Written by Michael Chen (sth4nth@gmail.com).\ny = d*(d-1)/4*log(pi)+sum(gammaln(x(:)+(1-(1:d))/2),2);\ny = reshape(y,size(x));", "meta": {"author": "PRML", "repo": "PRMLT", "sha": "baac49f643db6b39e75307d3b21307b32b29a7a9", "save_path": "github-repos/MATLAB/PRML-PRMLT", "path": "github-repos/MATLAB/PRML-PRMLT/PRMLT-baac49f643db6b39e75307d3b21307b32b29a7a9/chapter02/logMvGamma.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9755769113660688, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.8232845700067977}} {"text": "function value = i4vec_norm_l0 ( n, a )\n\n%*****************************************************************************80\n%\n%% I4VEC_NORM_L0 returns the l0 \"norm\" of an I4VEC.\n%\n% Discussion:\n%\n% An I4VEC is a vector of I4's.\n%\n% The l0 \"norm\" simply counts the number of nonzero entries in the vector.\n% It is not a true norm, but has some similarities to one. It is useful\n% in the study of compressive sensing.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 June 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of entries in the vector.\n%\n% Input, integer A(N), the vector.\n%\n% Output, integer I4VEC_NORM_L0, the value of the norm.\n%\n value = sum ( a(1:n) ~= 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/i4lib/i4vec_norm_l0.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.9073122188543454, "lm_q1q2_score": 0.8232154647563729}} {"text": "function [U, S] = pca(X)\n%PCA Run principal component analysis on the dataset X\n% [U, S, X] = pca(X) computes eigenvectors of the covariance matrix of X\n% Returns the eigenvectors U, the eigenvalues (on diagonal) in S\n%\n\n% Useful values\n[m, n] = size(X);\n\n% You need to return the following variables correctly.\nU = zeros(n);\nS = zeros(n);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: You should first compute the covariance matrix. Then, you\n% should use the \"svd\" function to compute the eigenvectors\n% and eigenvalues of the covariance matrix. \n%\n% Note: When computing the covariance matrix, remember to divide by m (the\n% number of examples).\n%\n\nSigma = X'*X/m;\n\n[U,S] = svd(Sigma);\n\n\n\n\n\n% =========================================================================\n\nend\n", "meta": {"author": "lawlite19", "repo": "MachineLearningEx", "sha": "44be60fe4d639d18af5ea5011f069eed348e97b8", "save_path": "github-repos/MATLAB/lawlite19-MachineLearningEx", "path": "github-repos/MATLAB/lawlite19-MachineLearningEx/MachineLearningEx-44be60fe4d639d18af5ea5011f069eed348e97b8/machine-learning-ex7/ex7/pca.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995702, "lm_q2_score": 0.8962513689768735, "lm_q1q2_score": 0.8231891680861905}} {"text": "function [J, grad] = lrCostFunction(theta, X, y, lambda)\n%LRCOSTFUNCTION Compute cost and gradient for logistic regression with\n%regularization\n% J = LRCOSTFUNCTION(theta, X, y, lambda) computes the cost of using\n% theta as the parameter for regularized logistic regression and the\n% gradient of the cost w.r.t. to the parameters.\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly\nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n% Hint: The computation of the cost function and gradients can be\n% efficiently vectorized. For example, consider the computation\n%\n% sigmoid(X * theta)\n%\n% Each row of the resulting matrix will contain the value of the\n% prediction for that example. You can make use of this to vectorize\n% the cost function and gradient computations.\n%\n% Hint: When computing the gradient of the regularized cost function,\n% there're many possible vectorized solutions, but one solution\n% looks like:\n% grad = (unregularized gradient for logistic regression)\n% temp = theta;\n% temp(1) = 0; % because we don't add anything for j = 0\n% grad = grad + YOUR_CODE_HERE (using the temp variable)\n%\n\nsigmo = sigmoid(X * theta);\n\nJreg = lambda / (2 * m) * (theta' * theta - theta(1) .^2);\n\nJ = 1 / m * (-y' * log(sigmo) - (1 - y)' * log(1 - sigmo)) + Jreg;\n\ntemp = theta;\ntemp(1) = 0;\ngradreg = lambda / m * temp;\n\ngrad = 1 / m * X' * (sigmo - y) + gradreg;\n\n% =============================================================\n\ngrad = grad(:);\n\nend\n", "meta": {"author": "benoitvallon", "repo": "coursera-machine-learning", "sha": "74ec09a5072eb5f3fec942fee45076e4f05b35af", "save_path": "github-repos/MATLAB/benoitvallon-coursera-machine-learning", "path": "github-repos/MATLAB/benoitvallon-coursera-machine-learning/coursera-machine-learning-74ec09a5072eb5f3fec942fee45076e4f05b35af/machine-learning-ex3/ex3/lrCostFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240125464114, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.8231820372742247}} {"text": "function l = l1pp ( n, h )\n\n%*****************************************************************************80\n%\n%% L1PP stores the 1D PP Laplacian as a full matrix.\n%\n% Discussion:\n%\n% The N grid points are assumed to be evenly spaced by H.\n%\n% For N = 5, the discrete Laplacian with periodic boundary conditions\n% has the matrix form L:\n%\n% 2 -1 0 0 -1\n% -1 2 -1 0 0\n% 0 -1 2 -1 0\n% 0 0 -1 2 -1\n% -1 0 0 -1 2\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 29 October 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of points.\n% N must be at least 3.\n%\n% Input, real H, the spacing between points.\n%\n% Output, real L(N,N), the Laplacian matrix.\n%\n if ( n < 3 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'L1PP - Fatal error!\\n' );\n fprintf ( 1, ' N < 3.\\n' );\n error ( 'L1PP - Fatal error!' );\n end\n\n l = zeros ( n, n );\n\n i = 1;\n l(1,1) = 2.0 / h / h;\n l(1,2) = -1.0 / h / h;\n l(1,n) = -1.0 / h / h;\n\n for i = 2 : n - 1\n l(i,i-1) = -1.0 / h / h;\n l(i,i) = 2.0 / h / h;\n l(i,i+1) = -1.0 / h / h;\n end\n\n i = n;\n l(n,1) = -1.0 / h / h;\n l(n,n-1) = -1.0 / h / h;\n l(n,n) = 2.0 / h / h;\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/laplacian/l1pp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216356, "lm_q2_score": 0.8856314813647587, "lm_q1q2_score": 0.8231416851307775}} {"text": "function [ thetaVec,sVec ] = getEllipseLengthVector( a,b, theta0,theta1 )\n%% About:\n% This function is used to return the length of the ellipse as a function\n% of the angle theta.\n\n%% Inputs:\n% theta0, theta1: start/end angle of the arc of the ellipse (from the parametric equation of the ellipse)\n% a,b: the big and the small radious of the ellipse.\n\n% Mohammad SAFEEA 10-Nov-2017\n\nthetaSpan = [theta0 theta1];\ns0 = 0;\nopts = odeset('RelTol',1e-2,'AbsTol',1e-4);\n[thetaVec,sVec] = ode45(@(theta,s) ((a*a*sin(theta)*sin(theta)+b*b*cos(theta)*cos(theta))^0.5), thetaSpan, s0,opts);\n\nend\n\n", "meta": {"author": "Modi1987", "repo": "KST-Kuka-Sunrise-Toolbox", "sha": "9299bed2b46058aeb4105d7fbff6d2290ce68bba", "save_path": "github-repos/MATLAB/Modi1987-KST-Kuka-Sunrise-Toolbox", "path": "github-repos/MATLAB/Modi1987-KST-Kuka-Sunrise-Toolbox/KST-Kuka-Sunrise-Toolbox-9299bed2b46058aeb4105d7fbff6d2290ce68bba/realTimeControlDrawEllipse/getEllipseLengthVector.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9683812327313545, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.823096134869401}} {"text": "function pde = sincosdata3\n%% SINCOSDATA3 trigonometric data for Poisson equation in 3-D\n%\n% u = cos(pi*x)*cos(pi*y)*cos(pi*z);\n% f = - Delta u = 3*pi^2*cos(pi*x)*cos(pi*y)*cos(pi*z);\n% Du = (-pi*sin(pi*x)*cos(pi*y)*cos(pi*z), \n% -pi*cos(pi*x)*sin(pi*y)*cos(pi*z),\n% -pi*cos(pi*x)*cos(pi*y)*sin(pi*z));\n%\n% Copyright (C) Long Chen. See COPYRIGHT.txt for details.\n\npde = struct('f',@f,'exactu',@exactu,'g_D',@g_D,'Du',@Du,'g_N',@g_N, 'phi', @phi);\n\n % load data (right hand side function)\n function s = f(p)\n x = p(:,1); y = p(:,2); z = p(:,3);\n s = 3*pi^2*cos(pi*x).*cos(pi*y).*cos(pi*z);\n end\n % exact solution\n function s = exactu(p)\n x = p(:,1); y = p(:,2); z = p(:,3);\n s = cos(pi*x).*cos(pi*y).*cos(pi*z); % for neumann boundary condition, int_u =0\n end\n % Dirichlet boundary condition\n function s = g_D(p)\n s = exactu(p);\n end\n % Neumann boundary condtion\n function f = g_N(p)\n f = zeros(size(p,1),1);\n x = p(:,1); y = p(:,2); z = p(:,3);\n uprime = [-pi*sin(pi*x).*cos(pi*y).*cos(pi*z) ...\n -pi*cos(pi*x).*sin(pi*y).*cos(pi*z) ...\n -pi*cos(pi*x).*cos(pi*y).*sin(pi*z)];\n downbd = (abs(z) 100) = 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(-((x1-pi).^2 + (x2-pi).^2));\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/easom.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191322715436, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.8230439363505747}} {"text": "function varargout = styblinskitang(X)\n% Styblinski-Tang function\n%\n% STYBLINSKYTANG([x1, x2, ..., xn]) returns the value of the \n% Styblinski-Tang at the specified points. All [xi] may be vectors. \n% The search domain is \n%\n% -5 < x_i < 5\n%\n% The global minimum is \n%\n% f(x1, x2, ..., xn) = \n% f(-2.903534, -2.903534, ..., -2.903534) = -39.16599 * n\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} = inf; % # dims\n varargout{2} = -5; % LB\n varargout{3} = +5; % LB\n varargout{4} = -2.903534018185960e+000; % solution\n varargout{5} = -3.916616570377142e+001; % *(#dims) .. function value at solution\n\n % otherwise, output function value\n else\n\n % keep all values in the search domain\n X(X < -5) = inf; X(X > 5) = inf;\n\n % NOTE: orientation can not be determined automatically\n % defaults to columnsums...\n varargout{1} = sum(X.^4 - 16*X.^2 + 5*X, 1)/2;\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/styblinskitang.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191246389617, "lm_q2_score": 0.8615382094310355, "lm_q1q2_score": 0.8230439280766754}} {"text": "function y = gvar(x,n)\n%GVAR Variance of a grouped sample.\n% In some scientific works, once the data have been gathered from a \n% population of interest, it is often difficult to get a sense of what \n% the data indicate when they are presented in an unorganized fashion. \n% Assembling the raw data into a meaningful form, such as a frequency \n% distribution, makes the data easier to understand and interpret. It is\n% in the context of frequency distributions that the importance of \n% conveying in a succinct way numerical information contained in the data\n% is encountered.\n% So, grouped data is data that has been organized into groups known as\n% classes. The raw dataset can be organized by constructing a table \n% showing the frequency distribution of the variable (whose values are \n% given in the raw dataset). Such a frequency table is often referred to\n% as grouped data.\n% Here, we developed a m-code to calculate the variance of a grouped data.\n% One can input the returns or modified vectors n and xout containing the\n% frequency counts and the bin locations of the hist m-function, in a \n% column form matrix.\n% Normalizes Y by (N-1), where N is the sample size. This is an unbiased\n% estimator of the variance of the population from which X is drawn.\n% Y = VAR(X,1) normalizes by N and produces the second moment of the \n% sample about its mean. VAR(X,0) is the same as VAR(X). \n%\n% Variance calculation uses the formula,\n%\n% \n% V = Sum(F*(MC - M)^2)/D \n%\n% where:\n% F = class frequency\n% MC = mark class\n% M = grouped mean\n% D = N - 1 or N, whether normalizes by n-1 or by n\n% N = sample size [=sum(F)]\n% \n% Syntax: function y = gvar(x) \n% \n% Inputs:\n% x - data matrix (Size of matrix must be n-by-2; absolut frequency=\n% column 1, class mark=column 2) \n% n - [normalized by n-1] = 0 (default), [normalized by n] = 1 \n% Outputs:\n% y - variance of the values in x\n%\n% Example: Suppose we have the next frequency table:\n%\n% ----------------\n% MC F\n% ----------------\n% 5 6\n% 15 16\n% 25 24\n% 35 25\n% 45 17\n% ----------------\n%\n% Taken from:\n% http://mlsc.lboro.ac.uk/resources/statistics/var_stand_deviat_group.pdf\n%\n% Where we are interested to get the variance value normalized by n.\n%\n% Data input:\n% x=[5 6;15 16;25 24;35 25;45 17];\n%\n% Calling on Matlab the function: \n% y = gvar(x,1)\n%\n% Answer is:\n%\n% y = 138.7268\n%\n% Created by A. Trujillo-Ortiz and R. Hernandez-Walls\n% Facultad de Ciencias Marinas\n% Universidad Autonoma de Baja California\n% Apdo. Postal 453\n% Ensenada, Baja California\n% Mexico.\n% atrujo@uabc.edu.mx\n%\n% Copyright (C) September 18, 2012.\n%\n% To cite this file, this would be an appropriate format:\n% Trujillo-Ortiz, A. and R. Hernandez-Walls. (2012). \n% gvar:Varience of a grouped sample. [WWW document].\n% URL http://www.mathworks.com/matlabcentral/fileexchange/\n% 38281-gvar\n%\n% Reference:\n% Jayaraman, K. (1999), A Statistical Manual for Foresty Research. Foresty\n% Research Support Programme for Asia and the Pacific. FAO-\n% Corporate Document Repository. Forestry Statistics and Data\n% Collection. \n% URL http://www.fao.org/DOCREP/003/X6831E/X6831E00.HTM\n% PDF ftp://ftp.fao.org/docrep/fao/003/X6831E/X6831E00.pdf \n%\n\nif nargin < 2,\n n = 0; %default\nend\n\nc = size(x,2);\n\nif c ~= 2\n error('stats:gvar:BadData','X must have two colums.');\nend\n\nmc = x(:,1); %class mark\nf = x(:,2); %absolut frequency\ns = sum(f.*mc);\nm = s/sum(f);\nss = sum(f.*(mc - m).^2);\n\nif n == 0; %default\n d = sum(f) - 1;\nelse n = 1;\n d = sum(f);\nend\n\ny = ss/d;\n\nreturn,\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/38281-gvar/gvar.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422158380861, "lm_q2_score": 0.8652240791017535, "lm_q1q2_score": 0.8229511477933092}} {"text": "function volume = sphere_imp_zone_volume_3d ( r, h1, h2 )\n\n%*****************************************************************************80\n%\n%% SPHERE_IMP_ZONE_VOLUME_3D computes the volume of a spherical zone in 3D.\n%\n% Discussion:\n%\n% An implicit sphere in 3D satisfies the equation:\n%\n% sum ( ( P(1:DIM_NUM) - CENTER(1:DIM_NUM) )**2 ) = R**2\n%\n% Draw any radius of the sphere and note the point P where the radius\n% intersects the sphere. Now choose two points on the radius line, a\n% distance H1 and H2 from the point P. Consider all the points on or within\n% the sphere whose projection onto the radius lies between these two points.\n% These points constitute the spherical zone, which can also be considered\n% the difference of two spherical caps.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 February 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R, the radius of the sphere.\n%\n% Input, real H1, H2, the distances that define the \n% thickness of the zone. H1 and H2 must be between 0 and 2 * R.\n%\n% Output, real VOLUME, the volume of the spherical zone\n%\n h11 = min ( h1, h2 );\n h11 = max ( h11, 0.0 );\n\n if ( 2.0 * r <= h11 )\n volume = 0.0;\n return\n end\n\n h22 = max ( h1, h2 );\n h22 = min ( h22, 2.0 * r );\n\n if ( h22 <= 0.0 )\n volume = 0.0;\n return\n end\n\n volume = ( 1.0 / 3.0 ) * pi * ( ...\n h22 * h22 * ( 3.0 * r - h22 ) ...\n - h11 * h11 * ( 3.0 * r - h11 ) );\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_imp_zone_volume_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475762847495, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.8229267800157044}} {"text": "function [airfoildata] = PerformRegression(data)\n% Relate the coefficients of the drag polar to Re as parabolic functions.\n% Drag polar is Cd = a0 + a1*alpha + a2*alpha^2\n% The contents of airfoildata are the coefficients resulting from the\n% polynomial regression with respect to Reynolds number:\n%'NACA 4 or 5 digit' | 3 coefficients for a0 |\n% 3 coefficients for a1 | 3 coefficients for a2 | \n% 3 coefficients for alpha_stall \n% so that:\n% a0 = b1 + b2*log10(Re) + b3*log10(Re)^2\n% a1 = c1 + c2*log10(Re) + c3*log10(Re)^2\n% a2 = d1 + d2*log10(Re) + d3*log10(Re)^2\n% and:\n% alphastall = k1 + k2*log10(Re) + k3*log10(Re)^2\n\nfor i = 1:length(data)\n if length(data(i).Re) >= 2\n airfoildata{1}{i} = data(i).airfoil;\n airfoildata{2}{i} = [ones(size(data(i).Re)) log10(data(i).Re) log10(data(i).Re).^2]\\[data(i).a0];\n airfoildata{3}{i} = [ones(size(data(i).Re)) log10(data(i).Re) log10(data(i).Re).^2]\\[data(i).a1];\n airfoildata{4}{i} = [ones(size(data(i).Re)) log10(data(i).Re) log10(data(i).Re).^2]\\[data(i).a2];\n airfoildata{5}{i} = [ones(size(data(i).Re)) log10(data(i).Re) log10(data(i).Re).^2]\\[data(i).alphastall];\n end\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/15442-wing-designer/PerformRegression.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9658995762509215, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.8229008449608329}} {"text": "function [ w, xy ] = triangle_unit_o07 ( )\n\n%*****************************************************************************80\n%\n%% TRIANGLE_UNIT_O07 returns a 7 point quadrature rule for the unit triangle.\n%\n% Discussion:\n%\n% This rule is precise for monomials through degree 5.\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% 16 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(7), the weights.\n%\n% Output, real XY(2,7), the abscissas.\n%\n w(1:7,1) = [ ...\n 0.12593918054482715260, ...\n 0.12593918054482715260, ...\n 0.12593918054482715260, ...\n 0.13239415278850618074, ...\n 0.13239415278850618074, ...\n 0.13239415278850618074, ...\n 0.22500000000000000000 ];\n\n xy(1:2,1:7) = [ ...\n 0.79742698535308732240, 0.10128650732345633880; ...\n 0.10128650732345633880, 0.79742698535308732240; ...\n 0.10128650732345633880, 0.10128650732345633880; ...\n 0.059715871789769820459, 0.47014206410511508977; ...\n 0.47014206410511508977, 0.059715871789769820459; ...\n 0.47014206410511508977, 0.47014206410511508977; ...\n 0.33333333333333333333, 0.33333333333333333333 ]';\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/triangle_felippa_rule/triangle_unit_o07.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8947894604912848, "lm_q1q2_score": 0.822886444317417}} {"text": "function a = pascal2 ( n )\n\n%*****************************************************************************80\n%\n%% PASCAL2 returns the PASCAL2 matrix.\n%\n% Formula:\n%\n% If ( I = 1 or J = 1 )\n% A(I,J) = 1\n% else\n% A(I,J) = A(I-1,J) + A(I,J-1)\n%\n% Example:\n%\n% N = 5\n%\n% 1 1 1 1 1\n% 1 2 3 4 5\n% 1 3 6 10 15\n% 1 4 10 20 35\n% 1 5 15 35 70\n%\n% Properties:\n%\n% A is a \"chunk\" of the Pascal binomial combinatorial triangle.\n%\n% A is positive definite.\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% A is integral, therefore det ( A ) is integral, and \n% det ( A ) * inverse ( A ) is integral.\n%\n% A is nonsingular.\n%\n% det ( A ) = 1.\n%\n% A is unimodular.\n%\n% Eigenvalues of A occur in reciprocal pairs.\n%\n% The condition number of A is approximately 16^N / ( N*PI ).\n%\n% The elements of the inverse of A are integers.\n%\n% A(I,J) = (I+J-2)! / ( (I-1)! * (J-1)! )\n%\n% The Cholesky factor of A is a lower triangular matrix R,\n% such that A = R * R'. The matrix R is a Pascal\n% matrix of the type generated by subroutine PASCAL. In other\n% words, PASCAL2 = PASCAL * PASCAL'.\n%\n% If the (N,N) entry of A is decreased by 1, the matrix is singular.\n%\n% Gregory and Karney consider a generalization of this matrix as\n% their test matrix 3.7, in which every element is multiplied by a\n% nonzero constant K. They point out that if K is the reciprocal of\n% an integer, then the inverse matrix has all integer entries.\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% 18 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Robert Brawer, Magnus Pirovino,\n% The linear algebra of the Pascal matrix,\n% Linear Algebra and Applications,\n% Volume 174, 1992, pages 13-23.\n%\n% Robert Gregory, David Karney,\n% Example 3.7,\n% A Collection of Matrices for Testing Computational Algorithms,\n% Wiley, 1969, page 32, \n% LC: QA263.G68.\n%\n% Nicholas Higham,\n% Accuracy and Stability of Numerical Algorithms,\n% Society for Industrial and Applied Mathematics,\n% Philadelphia, PA, USA, 1996; section 26.4.\n%\n% Sam Karlin,\n% Total Positivity, Volume 1,\n% Stanford University Press, 1968.\n%\n% Morris Newman, John Todd,\n% The evaluation of matrix inversion programs,\n% Journal of the Society for Industrial and Applied Mathematics,\n% Volume 6, Number 4, pages 466-476, 1958.\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% John Todd,\n% Basic Numerical Mathematics, Vol. 2: Numerical Algebra,\n% Academic Press, 1977, page 172.\n%\n% HW Turnbull,\n% The Theory of Determinants, Matrices, and Invariants,\n% Blackie, 1929.\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\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 == 1 )\n a(i,j) = 1.0;\n elseif ( j == 1 )\n a(i,j) = 1.0;\n else\n a(i,j) = a(i,j-1) + a(i-1,j);\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/pascal2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.88242786954645, "lm_q1q2_score": 0.8228227901019589}} {"text": "function [phi,dphi]=pt2TetrahedronCoords3D(x,v)\n%%PT2TETRAHEDRONCOORDS3D Convert a 3D point to barycentric coordinates in\n% a tetrahedron using the relative areas of subtetrahedra, as\n% discussed at the beginning of [1]. A signed tetrahedral volume area\n% is used so that points outside of the tetrahedron can also be\n% represented (albeit with some negative weights).\n%\n%INPUTS: x The 3XnumPts set of points to convert into tetrahedral\n% coordinates.\n% v The 3X4 set of vertices of the tetrahedron.\n%\n%OUTPUTS: phi A 4XnumPts set of the coordinates in the triangle.\n% dphi A 4X3XnumPts set of derivatives of the elements of phi\n% (rows) taken with respect to the elements of x (columns) for\n% each input measurement (3rd dimension).\n%\n%In [1], the coordinates are defined as the ratio of the volume of a number\n%of sub-tetrahedra (with x as a vertex) and the tetrahedron given in v.\n%Here, things differ a little bit in that signed tetrahedral volumes are\n%used with a very specific ordering. This allows this function to work\n%with points inside the tetrahedron (with all positive weights) as well as\n%with points outside the tetrahdron (with some negative weights).\n%\n%EXAMPLE 1:\n%In this example, the coordinates of three points are found and the points\n%are recreated from the phi values. The residual error of the reverse\n%conversion is seen to be on the order of finite precision errors.\n% x=sqrt(3)/3;\n% h=sqrt(6)/3;\n% d=sqrt(3)/6;\n% v=[x, -d, -d, 0;\n% 0, 1/2,-1/2, 0;\n% 0, 0, 0, h];\n% xPts=[[0;0;0.5],[x;0;0],[1;1;1]];\n% phi=pt2TetrahedronCoords3D(xPts,v);\n% xBack=barycentricCoords2Pt(phi,v);\n% ResidualErr=max(max(abs(xBack-xPts)))\n%\n%EXAMPLE 2:\n%In this example, we verify that the derivative is consistent with\n%numerical differentiation. The absolute error is consistent with what one\n%might expect due to finite precision limitations.\n% v=randn(3,4);\n% x=randn(3,1);\n% [~,dphi]=pt2TetrahedronCoords3D(x,v);\n% f=@(y)pt2TetrahedronCoords3D(y,v);\n% dPhiNumDiff=numDiff(x,f,4);\n% RelErr=max(max(abs((dphi-dPhiNumDiff)./dPhiNumDiff)))\n%\n%REFERENCES:\n%[1] M. S. Floater, \"Generalized barycentric coordinates and applications,\"\n% Acta Numerica, vol. 24, pp. 161-214, 1 May 2015.\n%\n%December 2021 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\na=v(:,1);\nb=v(:,2);\nc=v(:,3);\nd=v(:,4);\n\nnumX=size(x,2);\nphi=zeros(4,numX);\ndphi=zeros(4,3,numX);\nfor curX=1:numX\n [Va,dVa]=tetrahedronVolume([b,x(:,curX),d,c],false,2);\n [Vb,dVb]=tetrahedronVolume([a,x(:,curX),c,d],false,2);\n [Vc,dVc]=tetrahedronVolume([a,x(:,curX),d,b],false,2);\n [Vd,dVd]=tetrahedronVolume([a,x(:,curX),b,c],false,2);\n\n %Nominally, V=tetrahedronVolume(v,false); should equal Va+Vb+Vc+Vd.\n %However, to ensure that phi is normalized to more significant digits,\n %we compute V directly from the sum rather than computing it once\n %outside this loop and reusing it.\n V=Va+Vb+Vc+Vd;\n\n phi(:,curX)=[Va;Vb;Vc;Vd]/V;\n\n dphi(:,:,curX)=[dVa;\n dVb;\n dVc;\n dVd]/V;\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/Coordinate_Systems/Barycentric_Coordinate_Systems/pt2TetrahedronCoords3D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062238, "lm_q2_score": 0.8824278726384089, "lm_q1q2_score": 0.8228227863595383}} {"text": "function x = blend_102 ( r, s, x00, x01, x10, x11 )\n\n%*****************************************************************************80\n%\n%% BLEND_102 extends scalar point data into a square.\n%\n% Diagram:\n%\n% 01------------11\n% | . |\n% | . |\n% |.....rs......|\n% | . |\n% | . |\n% 00------------10\n%\n% Formula:\n%\n% Written in terms of R and S, the map has the form:\n%\n% X(R,S) =\n% 1 * ( + x00 )\n% + r * ( - x00 + x10 )\n% + s * ( - x00 + x01 )\n% + r * s * ( + x00 - x10 - x01 + x11 )\n%\n% Written in terms of the coefficients, the map has the form:\n%\n% X(R,S) = x00 * ( 1 - r - s + r * s )\n% + x01 * ( s - r * s )\n% + x10 * ( r - r * s )\n% + x11 * ( r * s )\n%\n% = x00 * ( 1 - r ) * ( 1 - s )\n% + x01 * ( 1 - r ) * s\n% + x10 * r * ( 1 - s )\n% + x11 * r s\n%\n% The nonlinear term ( r * s ) has an important role:\n%\n% If ( x01 + x10 - x00 - x11 ) is zero, then the input data lies in\n% a plane, and the mapping is affine. All the interpolated data\n% will lie on the plane defined by the four corner values. In\n% particular, on any line through the square, data values at\n% intermediate points will lie between the values at the endpoints.\n%\n% If ( x01 + x10 - x00 - x11 ) is not zero, then the input data does\n% not lie in a plane, and the interpolation map is nonlinear. On\n% any line through the square, data values at intermediate points\n% may lie above or below the data values at the endpoints. The\n% size of the coefficient of r * s will determine how severe this\n% effect is.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 October 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% William Gordon,\n% Blending-Function Methods of Bivariate and Multivariate Interpolation\n% and Approximation,\n% SIAM Journal on Numerical Analysis,\n% Volume 8, Number 1, March 1971, pages 158-177.\n%\n% William Gordon and Charles Hall,\n% Transfinite Element Methods: Blending-Function Interpolation over\n% Arbitrary Curved Element Domains,\n% Numerische Mathematik,\n% Volume 21, Number 1, 1973, pages 109-129.\n%\n% William Gordon and Charles Hall,\n% Construction of Curvilinear Coordinate Systems and Application to\n% Mesh Generation,\n% International Journal of Numerical Methods in Engineering,\n% Volume 7, 1973, pages 461-477.\n%\n% Joe Thompson, Bharat Soni, Nigel Weatherill,\n% Handbook of Grid Generation,\n% CRC Press, 1999.\n%\n% Parameters:\n%\n% Input, real R, S, the coordinates where an\n% interpolated value is desired.\n%\n% Input, real X00, X01, X10, X11, the data values\n% at the corners.\n%\n% Output, real X, the interpolated data value at (R,S).\n%\n x = + x00 ...\n + r * ( - x00 + x10 ) ...\n + s * ( - x00 + x01 ) ...\n + r * s * ( + x00 - x10 - x01 + x11 );\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/blend/blend_102.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603708, "lm_q2_score": 0.8824278664544912, "lm_q1q2_score": 0.8228227839060878}} {"text": "function b = bernoulli_number ( n )\n\n%*****************************************************************************80\n%\n%% BERNOULLI_NUMBER computes the value of the Bernoulli numbers B(0) through B(N).\n%\n% Discussion:\n%\n% The Bernoulli numbers are rational.\n%\n% If we define the sum of the M-th powers of the first N integers as:\n%\n% SIGMA(M,N) = sum ( 0 <= I <= N ) I**M\n%\n% and let C(I,J) be the combinatorial coefficient:\n%\n% C(I,J) = I! / ( ( I - J )! * J! )\n%\n% then the Bernoulli numbers B(J) satisfy:\n%\n% SIGMA(M,N) = 1/(M+1) * sum ( 0 <= J <= M ) C(M+1,J) B(J) * (N+1)**(M+1-J)\n%\n% First values:\n%\n% B0 1 = 1.00000000000\n% B1 -1/2 = -0.50000000000\n% B2 1/6 = 1.66666666666\n% B3 0 = 0\n% B4 -1/30 = -0.03333333333\n% B5 0 = 0\n% B6 1/42 = 0.02380952380\n% B7 0 = 0\n% B8 -1/30 = -0.03333333333\n% B9 0 = 0\n% B10 5/66 = 0.07575757575\n% B11 0 = 0\n% B12 -691/2730 = -0.25311355311\n% B13 0 = 0\n% B14 7/6 = 1.16666666666\n% B15 0 = 0\n% B16 -3617/510 = -7.09215686274\n% B17 0 = 0\n% B18 43867/798 = 54.97117794486\n% B19 0 = 0\n% B20 -174611/330 = -529.12424242424\n% B21 0 = 0\n% B22 854,513/138 = 6192.123\n% B23 0 = 0\n% B24 -236364091/2730 = -86580.257\n% B25 0 = 0\n% B26 8553103/6 = 1425517.16666\n% B27 0 = 0\n% B28 -23749461029/870 = -27298231.0678\n% B29 0 = 0\n% B30 8615841276005/14322 = 601580873.901\n%\n% Recursion:\n%\n% With C(N+1,K) denoting the standard binomial coefficient,\n%\n% B(0) = 1.0\n% B(N) = - ( sum ( 0 <= K < N ) C(N+1,K) * B(K) ) / C(N+1,N)\n%\n% Warning:\n%\n% This recursion, which is used in this routine, rapidly results\n% in significant errors.\n%\n% Special Values:\n%\n% Except for B(1), all Bernoulli numbers of odd index are 0.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 December 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the highest Bernoulli number to compute.\n%\n% Output, real B(1:N+1), B(I+1) contains the I-th Bernoulli number.\n%\n if ( n < 0 )\n b = [];\n return\n end\n\n b(1) = 1.0;\n\n if ( n < 1 )\n return\n end\n\n b(2) = -0.5;\n\n c = zeros ( n + 2, 1 );\n \n c(1) = 1;\n c(2) = 2;\n c(3) = 1;\n\n for i = 2 : n\n\n c = comb_row_next ( i + 1, c );\n \n if ( mod ( i, 2 ) == 1 )\n \n b(i+1) = 0.0;\n \n else\n \n b_sum = 0.0;\n for j = 0 : i - 1\n b_sum = b_sum + b(j+1) * c(j+1);\n end\n \n b(i+1) = -b_sum / c(i+1);\n \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/polpak/bernoulli_number.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.8824278556326344, "lm_q1q2_score": 0.8228227787843573}} {"text": "function [s,t]=HFMChirp(T,fStart,fEnd,tSamp,phi)\n%%LFMCHIRP Generate a complex hyperbolic frequency modulated (HFM) signal.\n% It can be an upchirp or a downchirp. HFM chirps have a role in\n% radar and sonar signal processing. They are more Doppler\n% insensitive than linear FM chirps.\n%\n%INPUTS: T The duration of the chirp (seconds).\n% fStart The frequency at the start of the chirp (Hertz). This must be\n% >0.\n% fEnd The frequency at the end of the chirp (Hertz). This must be >0.\n% tSamp If this is scalar, it is the sampling rate of the chirp and the\n% number of samples depends on T. Otherwise, this is a numSampX1\n% array of times at which samples are desired. Samples before\n% time 0 and after time T are set to zero. If this parameter is\n% omitted or an empty matrix is passed, the Nyquist sampling\n% rate is used.\n% phi The phase offset of the chirp. If this parameter is omitted or\n% an empty matrix is passed, then the default of pi/2 is used,\n% which makes the real part of the signal start at zero.\n%\n%OUTPUT: s The numSampX1 complex chirp signal.\n% t The sample times used. If tSamp was not a scalar, then this is\n% just tSamp.\n%\n%HFM chirps are described in [1] along with a range bias model for target\n%tracking that is relevant when Doppler filtering is not performed.\n%\n%EXAMPLE 1:\n%Here is an example of an upchirp:\n% T=1e-3;\n% fStart=1e3;\n% fEnd=50e3;\n% tSamp=1/(100*2*fEnd);%100 times the Nyquist frequency.\n% [s,t]=HFMChirp(T,fStart,fEnd,tSamp);\n% figure(1)\n% clf\n% plot(t,real(s),'linewidth',2)\n% h1=xlabel('t');\n% h2=ylabel('s');\n% set(gca,'FontSize',14,'FontWeight','bold','FontName','Times')\n% set(h1,'FontSize',14,'FontWeight','bold','FontName','Times')\n% set(h2,'FontSize',14,'FontWeight','bold','FontName','Times')\n\n%EXAMPLE 2:\n%Here is an example of a downchirp:\n% T=1e-3;\n% fStart=50e3;\n% fEnd=1e3;\n% tSamp=1/(100*2*fStart);%100 times the Nyquist frequency.\n% [s,t]=HFMChirp(T,fStart,fEnd,tSamp);\n% figure(2)\n% clf\n% plot(t,real(s),'linewidth',2)\n% h1=xlabel('t');\n% h2=ylabel('s');\n% set(gca,'FontSize',14,'FontWeight','bold','FontName','Times')\n% set(h1,'FontSize',14,'FontWeight','bold','FontName','Times')\n% set(h2,'FontSize',14,'FontWeight','bold','FontName','Times')\n%\n%REFERENCES:\n%[1] X. Song, P. Willett, and S. Zhou, \"Range bias modeling for hyperbolic-\n% frequency-modulated waveforms in target tracking,\" IEEE Journal of\n% Oceanic Engineering, vol. 37, no. 4, pp. 670-679, Oct. 2012.\n%\n%November 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<4||isempty(tSamp))\n %Default to the Nyquist sampling rate.\n tSamp=1/(2*max(fStart,fEnd));\nend\n\nif(nargin<5||isempty(phi))\n phi=pi/2;%Phase offset so the signal starts at zero, by default.\nend\n\n%Equation 1\nb=(fStart-fEnd)/(fStart*fEnd*T);\n\nif(isscalar(tSamp))\n %If a scalar sampling rate is given.\n NPulse=fix(T/tSamp);\n t=(0:(NPulse-1))*tSamp;\nelse\n %If the samples themselves are given\n t=tSamp;\nend\n\ns=exp(1j*(phi+(2*pi/b)*log(1+b*fStart*t)));\n\nsel=(t>T)&(t<0);\ns(sel)=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/Signal_Processing/HFMChirp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.927363299661721, "lm_q2_score": 0.8872046056466901, "lm_q1q2_score": 0.8227609905675906}} {"text": "function [ n_data_new, n, c ] = bernoulli_number_values ( n_data )\n\n%*****************************************************************************80\n%\n%% BERNOULLI_NUMBER_VALUES returns some values of the Bernoulli numbers.\n%\n% Discussion:\n%\n% The Bernoulli numbers are rational.\n%\n% If we define the sum of the M-th powers of the first N integers as:\n%\n% SIGMA(M,N) = sum ( 0 <= I <= N ) I**M\n%\n% and let C(I,J) be the combinatorial coefficient:\n%\n% C(I,J) = I! / ( ( I - J )! * J! )\n%\n% then the Bernoulli numbers B(J) satisfy:\n%\n% SIGMA(M,N) = 1/(M+1) * sum ( 0 <= J <= M ) C(M+1,J) B(J) * (N+1)**(M+1-J)\n%\n% First values:\n%\n% B0 1 = 1.00000000000\n% B1 -1/2 = -0.50000000000\n% B2 1/6 = 1.66666666666\n% B3 0 = 0\n% B4 -1/30 = -0.03333333333\n% B5 0 = 0\n% B6 1/42 = 0.02380952380\n% B7 0 = 0\n% B8 -1/30 = -0.03333333333\n% B9 0 = 0\n% B10 5/66 = 0.07575757575\n% B11 0 = 0\n% B12 -691/2730 = -0.25311355311\n% B13 0 = 0\n% B14 7/6 = 1.16666666666\n% B15 0 = 0\n% B16 -3617/510 = -7.09215686274\n% B17 0 = 0\n% B18 43867/798 = 54.97117794486\n% B19 0 = 0\n% B20 -174611/330 = -529.12424242424\n% B21 0 = 0\n% B22 854,513/138 = 6192.123\n% B23 0 = 0\n% B24 -236364091/2730 = -86580.257\n% B25 0 = 0\n% B26 8553103/6 = 1425517.16666\n% B27 0 = 0\n% B28 -23749461029/870 = -27298231.0678\n% B29 0 = 0\n% B30 8615841276005/14322 = 601580873.901\n%\n% Recursion:\n%\n% With C(N+1,K) denoting the standard binomial coefficient,\n%\n% B(0) = 1.0\n% B(N) = - ( sum ( 0 <= K < N ) C(N+1,K) * B(K) ) / C(N+1,N)\n%\n% Special Values:\n%\n% Except for B(1), all Bernoulli numbers of odd index are 0.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 May 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% Parameters:\n%\n% Input, integer N_DATA, indicates the index of the previous test data\n% returned, or is 0 if this is the first call. For repeated calls,\n% set the input value of N_DATA to the output value of N_DATA_NEW\n% from the previous call.\n%\n% Output, integer N_DATA_NEW, the index of the test data.\n%\n% Output, integer N, the order of the Bernoulli number.\n%\n% Output, real C, the value of the Bernoulli number.\n%\n n_max = 10;\n c_vec = [ ...\n 1.0000000000E+00, -0.5000000000E+00, 0.1666666667E+00, ...\n 0.0000000000E+00, -0.0333333333E+00, -0.02380952381E+00, ...\n -0.0333333333E+00, 0.0757575757E+00, -529.1242424E+00, ...\n 601580873.9E+00 ];\n n_vec = [ ...\n 0, 1, 2, 3, 4, 6, 8, 10, 20, 30 ];\n\n n_data_new = n_data;\n\n if ( n_data_new < 0 )\n n_data_new = 0;\n end\n\n n_data_new = n_data_new + 1;\n\n if ( n_max < n_data_new )\n n_data_new = 0;\n n = 0;\n c = 0;\n else\n n = n_vec(n_data_new);\n c = c_vec(n_data_new);\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/polpak/bernoulli_number_values.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8902942319436397, "lm_q1q2_score": 0.8227581318249843}} {"text": "function a = r83t_dif2 ( m, n )\n\n%*****************************************************************************80\n%\n%% R83T_DIF2 returns the DIF2 matrix in R83T format.\n%\n% Example:\n%\n% N = 5\n%\n% 2 -1 . . .\n% -1 2 -1 . .\n% . -1 2 -1 .\n% . . -1 2 -1\n% . . . -1 2\n%\n% Properties:\n%\n% A is banded, with bandwidth 3.\n%\n% A is tridiagonal.\n%\n% Because A is tridiagonal, it has property A (bipartite).\n%\n% A is a special case of the TRIS or tridiagonal scalar matrix.\n%\n% A is integral, therefore det ( A ) is integral, and \n% det ( A ) * inverse ( A ) is integral.\n%\n% A is Toeplitz: constant along diagonals.\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% A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\n%\n% A is positive definite.\n%\n% A is an M matrix.\n%\n% A is weakly diagonally dominant, but not strictly diagonally dominant.\n%\n% A has an LU factorization A = L * U, without pivoting.\n%\n% The matrix L is lower bidiagonal with subdiagonal elements:\n%\n% L(I+1,I) = -I/(I+1)\n%\n% The matrix U is upper bidiagonal, with diagonal elements\n%\n% U(I,I) = (I+1)/I\n%\n% and superdiagonal elements which are all -1.\n%\n% A has a Cholesky factorization A = L * L', with L lower bidiagonal.\n%\n% L(I,I) = sqrt ( (I+1) / I )\n% L(I,I-1) = -sqrt ( (I-1) / I )\n%\n% The eigenvalues are\n%\n% LAMBDA(I) = 2 + 2 * COS(I*PI/(N+1))\n% = 4 SIN^2(I*PI/(2*N+2))\n%\n% The corresponding eigenvector X(I) has entries\n%\n% X(I)(J) = sqrt(2/(N+1)) * sin ( I*J*PI/(N+1) ).\n%\n% Simple linear systems:\n%\n% x = (1,1,1,...,1,1), A*x=(1,0,0,...,0,1)\n%\n% x = (1,2,3,...,n-1,n), A*x=(0,0,0,...,0,n+1)\n%\n% det ( A ) = N + 1.\n%\n% The value of the determinant can be seen by induction,\n% and expanding the determinant across the first row:\n%\n% det ( A(N) ) = 2 * det ( A(N-1) ) - (-1) * (-1) * det ( A(N-2) )\n% = 2 * N - (N-1)\n% = N + 1\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 July 2000\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Robert Gregory, David Karney,\n% A Collection of Matrices for Testing Computational Algorithms,\n% Wiley, 1969,\n% ISBN: 0882756494,\n% LC: QA263.68\n%\n% Morris Newman, John Todd,\n% Example A8,\n% The evaluation of matrix inversion programs,\n% Journal of the Society for Industrial and Applied Mathematics,\n% Volume 6, Number 4, pages 466-476, 1958.\n%\n% John Todd,\n% Basic Numerical Mathematics,\n% Volume 2: Numerical Algebra,\n% Birkhauser, 1980,\n% ISBN: 0817608117,\n% LC: QA297.T58.\n%\n% Joan Westlake,\n% A Handbook of Numerical Matrix Inversion and Solution of \n% Linear Equations,\n% John Wiley, 1968,\n% ISBN13: 978-0471936756,\n% LC: QA263.W47.\n%\n% Parameters:\n%\n% Input, integer M, N, the order of the matrix.\n%\n% Output, real A(M,3), the matrix.\n%\n a = zeros(m,3);\n\n mn = min ( m, n );\n\n a(2:mn,1) = -1.0;\n a(1:mn,2) = +2.0;\n a(1:mn-1,3) = -1.0;\n\n if ( m < n )\n a(mn,3) = -1.0;\n elseif ( n < m )\n a(mn+1,1) = -1.0;\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/cg/r83t_dif2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895028, "lm_q2_score": 0.8902942290328344, "lm_q1q2_score": 0.8227581272749369}} {"text": "function value = circle_segment_contains_point ( r, c, omega1, omega2, xy )\n\n%*****************************************************************************80\n%\n%% CIRCLE_SEGMENT_CONTAINS_POINT reports whether a point is in 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% In this function, we allow the circle to have an arbitrary center C,\n% arbitrary radius R, and we describe the points P1 and P2 by specifying\n% their angles OMEGA1 and OMEGA2.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 16 May 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R, the radius of the circle.\n% 0 < R.\n%\n% Input, real C(2,1), the center of the circle.\n%\n% Input, real OMEGA1, OMEGA2, the angles of the two points on the\n% circumference of the circle that define the circle segment.\n% OMEGA1 < OMEGA2 <= OMEGA1 + 2 * PI\n%\n% Input, real XY(2,1), a point.\n%\n% Output, integer VALUE, is TRUE if the point is inside the circle segment.\n%\n if ( r <= 0.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'CIRCLE_SEGMENT_CONTAINS_POINT - Fatal error!\\n' );\n fprintf ( 1, ' R <= 0.0.\\n' );\n error ( 'CIRCLE_SEGMENT_CONTAINS_POINT - Fatal error!' )\n end\n\n while ( omega2 < omega1 )\n omega2 = omega2 + 2.0 * pi;\n end\n%\n% Destroy all row vectors.\n%\n c = c(:);\n xy = xy(:);\n%\n% Compute the vector V = XY - C:\n%\n v(1:2,1) = xy(1:2,1) - c(1:2,1);\n%\n% a: Point must be inside the circle, so ||V|| <= R.\n%\n v_r = norm ( v );\n if ( r < v_r )\n value = 0;\n return\n end\n%\n% b: Angle made by the vector V must be between OMEGA1 and OMEGA2.\n%\n v_omega = atan2 ( v(2), v(1) );\n\n while ( omega1 <= v_omega + 2.0 * pi )\n v_omega = v_omega - 2.0 * pi;\n end\n\n while ( v_omega + 2.0 * pi <= omega1 )\n v_omega = v_omega + 2.0 * pi;\n end\n\n if ( omega2 < v_omega )\n value = 0;\n return\n end\n%\n% c: Projection of V onto unit centerline must be at least R-H.\n%\n omegah = 0.5 * ( omega1 + omega2 );\n v_project = v(1) * cos ( omegah ) + v(2) * sin ( omegah );\n\n theta = omega2 - omega1;\n h = circle_segment_height_from_angle ( r, theta );\n\n if ( v_project < r - h )\n value = 0;\n return\n end\n\n value = 1;\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/circle_segment/circle_segment_contains_point.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895028, "lm_q2_score": 0.8902942144788077, "lm_q1q2_score": 0.8227581138249522}} {"text": "function xn=linEqSolveFirstnRows(A,b,n)\n%%LINEQSOLVEFIRSTNROWS This function solves the problem A*x=b for the first\n% n rows of x. The matrix A CAN be singular as long as\n% a unique solution exists for the first n rows of x.\n% This function is useful for finding the position\n% estimate in an information filter state even before\n% estimates of all of the other target state\n% components have become observable In such an\n% instance A is the inverse covariance matrix, x is\n% the target state and b is the information state.\n%\n%INPUTS: A The NXN matrix A in the equation A*x=b, where x is unknown. The\n% matrix can be singular, but the first n rows of x should be\n% observable.\n% b The NX1 column vector b in the equation A*x=b.\n% n The number of rows of x, starting from the first row and going\n% down, for which one wishes to solve in the equation A*b. n must\n% be less than or equal to the number of rows in A.\n%\n%OUTPUTS: xn The first n rows of the column vector of x solved from A*x=b.\n% If any of the components of xn are not finite, then the\n% problem was not completely observable. Because of how the\n% problem is solved, if the kth component is not finite, then\n% all subsequent components will not be finite, regardless of\n% whether they are observable.\n%\n%The linear equation is solved by performing a modified qr decomposition on\n%the matrix A such that A=Q*R, where Q is an rotation matrix and R is a\n%LOWER triangular matrix. A standard QR decomposition produces an upper\n%triangular matrix. By flipping the rows and columns of a and then\n%performing the inverse operations on Q and R, one can get a decomposition\n%where R is a lower-triangular marix. One can then write R*x=Q'*b, since\n%the transpose of a rotation matrix is its inverse. The first n rows of x\n%can then be solved using forward substitution.\n%\n%The QR decomposition is in Matlab's built-in function qr. It is also\n%discussed in Chapter 5.2 of [1].\n%\n%REFERENCES:\n%[1] G. E. Golub and C. F. van Loan, Matrix Computations, 4rd ed.\n% Baltimore, MD: Johns Hopkins University Press, 2013.\n%\n%June 2014 David F.Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n%Perform a lower-triangular qr decomposition.\n[Q,R]=qr(rot90(A,2));\nQ=rot90(Q,2);\nR=rot90(R,2);\n%Now, Q*R=A and R is lower-triangular.\n\nb=Q'*b;\n\n%Perform forward substitution to solve for the first n components of x.\nxn=zeros(n,1);\nxn(1)=b(1)/R(1,1);\nfor curRow=2:n\n xn(curRow)=(b(curRow)-sum(xn(1:(curRow-1))'.*R(curRow,1:(curRow-1))))/R(curRow,curRow);\nend\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/linEqSolveFirstnRows.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947148047778, "lm_q2_score": 0.8705972751232809, "lm_q1q2_score": 0.8227098237149415}} {"text": "function a = fibonacci2 ( n )\n\n%*****************************************************************************80\n%\n%% FIBONACCI2 returns the FIBONACCI2 matrix.\n%\n% Example:\n%\n% N = 5\n%\n% 0 1 0 0 0\n% 1 1 0 0 0\n% 0 1 1 0 0\n% 0 0 1 1 0\n% 0 0 0 1 1\n%\n% Properties:\n%\n% A is generally not symmetric: A' /= A.\n%\n% A is tridiagonal.\n%\n% Because A is tridiagonal, it has property A (bipartite).\n%\n% A is banded, with bandwidth 3.\n%\n% A is integral: int ( A ) = A.\n%\n% A is a zero/one matrix.\n%\n% If N = 1 then\n% det ( A ) = 0\n% else\n% det ( A ) = (-1)^(N-1)\n%\n% If 1 < N, then A is unimodular.\n%\n% For 2 <= N, A has the eigenvalues:\n%\n% PHI (once),\n% 1 (N-2) times,\n% 1-PHI (once).\n%\n% When applied to a Fibonacci1 matrix B, the Fibonacci2 matrix\n% A produces the \"next\" Fibonacci1 matrix C = A*B.\n%\n% Let PHI be the golden ratio (1+sqrt(5))/2.\n%\n% For 2 <= N, the eigenvalues and eigenvectors are:\n%\n% LAMBDA(1) = PHI, vector = (1,PHI,PHI^2,...PHI^(N-1));\n% LAMBDA(2:N-1) = 1 vector = (0,0,0,...,0,1);\n% LAMBDA(N) = 1 - PHI. vector = ((-PHI)^(N-1),(-PHI)^(N-2),...,1)\n%\n% Note that there is only one eigenvector corresponding to 1.\n% Hence, for 3 < N, the matrix is defective. This fact means, \n% for instance, that the convergence of the eigenvector in the power \n% method will be very slow.\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% 08 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\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 == 1 )\n\n if ( j == 2 )\n a(i,j) = 1.0;\n else\n a(i,j) = 0.0;\n end\n\n else\n\n if ( j == i-1 | j == i )\n a(i,j) = 1.0;\n else\n a(i,j) = 0.0;\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/test_mat/fibonacci2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.8991213698363247, "lm_q1q2_score": 0.8226069936590873}} {"text": "function cdf = cosine_cdf ( x, a, b )\n\n%*****************************************************************************80\n%\n%% COSINE_CDF evaluates the Cosine CDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 06 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the PDF.\n%\n% Input, real A, B, the parameter of the PDF.\n% 0.0 < B.\n%\n% Output, real CDF, the value of the CDF.\n%\n if ( x <= a - pi * b )\n\n cdf = 0.0;\n\n elseif ( x <= a + pi * b )\n\n y = ( x - a ) / b;\n\n cdf = 0.5 + ( y + sin ( y ) ) / ( 2.0 * pi );\n\n elseif ( a + pi * b < x )\n\n cdf = 1.0;\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/prob/cosine_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.8225616564098038}} {"text": "function [ area, radin, radout ] = polygon_side_data_2d ( n, side )\n\n%*****************************************************************************80\n%\n%% POLYGON_SIDE_DATA_2D determines polygonal data from its side length in 2D.\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, integer N, the number of sides of the polygon.\n% N must be at least 3.\n%\n% Input, real SIDE, the length of one side of the polygon.\n%\n% Output, real AREA, the area of the regular polygon.\n%\n% Output, real RADIN, the inner radius of the polygon, that is,\n% the radius of the largest circle that can be inscribed within\n% the polygon.\n%\n% Output, real RADOUT, the outer radius of the polygon, that is,\n% the radius of the smallest circle that can be described about\n% the polygon.\n%\n if ( n < 3 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'POLYGON_SIDE_DATA_2D - Fatal error!\\n' );\n fprintf ( 1, ' Input value of N must be at least 3.\\n' );\n fprintf ( 1, ' but your input value was N = ', n );\n error ( 'POLYGON_SIDE_DATA_2D - Fatal error!' );\n end\n\n angle = pi / n;\n area = 0.5 * n * side * side / tan ( angle );\n radin = 0.5 * side / tan ( angle );\n radout = 0.5 * side / sin ( angle );\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_side_data_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.8933093954028816, "lm_q1q2_score": 0.8225500647798742}} {"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\nH_Theta = X * Theta';\nError = H_Theta - Y;\nError_logical = Error .* R;\nJ = 1/2 * sum(Error_logical(:).^2) + ...\n lambda/2*Theta(:)'*Theta(:) + ...\n lambda/2*X(:)'*X(:);\n\nX_grad = Error_logical*Theta + lambda*X;\nTheta_grad = Error_logical'*X + lambda*Theta;\n\n% =============================================================\n\ngrad = [X_grad(:); Theta_grad(:)];\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/ex8/cofiCostFunc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248123094438, "lm_q2_score": 0.8757870013740061, "lm_q1q2_score": 0.8223857245882766}} {"text": "function cx = cheby_u_polynomial ( n, x )\n\n%*****************************************************************************80\n%\n%% CHEBY_U_POLYNOMIAL evaluates the Chebyshev polynomials of the second kind.\n%\n% Differential equation:\n%\n% (1-X*X) Y'' - 3 X Y' + N (N+2) Y = 0\n%\n% First terms:\n%\n% U(0)(X) = 1\n% U(1)(X) = 2 X\n% U(2)(X) = 4 X^2 - 1\n% U(3)(X) = 8 X^3 - 4 X\n% U(4)(X) = 16 X^4 - 12 X^2 + 1\n% U(5)(X) = 32 X^5 - 32 X^3 + 6 X\n% U(6)(X) = 64 X^6 - 80 X^4 + 24 X^2 - 1\n% U(7)(X) = 128 X^7 - 192 X^5 + 80 X^3 - 8X\n%\n% Recursion:\n%\n% U(0)(X) = 1,\n% U(1)(X) = 2 * X,\n% U(N)(X) = 2 * X * U(N-1)(X) - U(N-2)(X)\n%\n% Norm:\n%\n% Integral ( -1 <= X <= 1 ) ( 1 - X^2 ) * U(N)(X)^2 dX = PI/2\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 July 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the highest polynomial to compute.\n%\n% Input, real X, the point at which the polynomials are to be computed.\n%\n% Output, real CX(1:N+1), the values of the N+1 Chebyshev polynomials.\n%\n cx = zeros ( n + 1, 1 );\n\n if ( n < 0 )\n cx = [];\n return\n end\n\n cx(1) = 1.0;\n\n if ( n < 1 )\n return\n end\n\n cx(2) = 2.0 * x;\n\n for i = 2 : n\n cx(i+1) = 2.0 * x * cx(i) - cx(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/test_mat/cheby_u_polynomial.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107984180245, "lm_q2_score": 0.877476800298183, "lm_q1q2_score": 0.8223807326007535}} {"text": "function fx = p38_fun ( n, x )\n\n%*****************************************************************************80\n%\n%% P38_FUN evaluates the integrand for problem 38.\n%\n% Discussion:\n%\n% The problem has a parameter ALPHA that can be set by calling\n% P38_PARAM_SET.\n%\n% The integrand oscillates more strongly as ALPHA is increased.\n%\n% The suggested range for ALPHA is 0 to 10.\n%\n% Interval:\n%\n% 0 <= x <= pi\n%\n% Integrand:\n%\n% cos ( 2^ALPHA * sin ( x ) )\n%\n% Exact Integral:\n%\n% pi * J0 ( 2^ALPHA )\n%\n% where J0 ( x ) is the J Bessel function of order 0.\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% Robert Piessens, Elise de Doncker-Kapenga,\n% Christian Ueberhuber, David Kahaner,\n% QUADPACK: A Subroutine Package for Automatic Integration,\n% Springer, 1983, page 83.\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 alpha = p38_param_get ( );\n\n fx = cos ( 2.0^alpha * sin ( x ) );\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/p38_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465170505205, "lm_q2_score": 0.8791467722591728, "lm_q1q2_score": 0.8223068714088244}} {"text": "function [ n_data, x, fx ] = bessel_i1_spherical_values ( n_data )\n\n%*****************************************************************************80\n%\n%% BESSEL_I1_SPHERICAL_VALUES returns some values of the Spherical Bessel function i1.\n%\n% Discussion:\n%\n% In Mathematica, the function can be evaluated by:\n%\n% Sqrt[Pi/(2*x)] * BesselI[3/2,x]\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 06 January 2007\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% LC: QA47.A34,\n% ISBN: 0-486-61272-4.\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, real X, the argument of the function.\n%\n% Output, real FX, the value of the function.\n%\n n_max = 21;\n\n fx_vec = [ ...\n 0.03336667857363341E+00, ...\n 0.06693371456802954E+00, ...\n 0.1354788933285401E+00, ...\n 0.2072931911031093E+00, ...\n 0.2841280857128948E+00, ...\n 0.3678794411714423E+00, ...\n 0.4606425870674146E+00, ...\n 0.5647736480096238E+00, ...\n 0.6829590627779635E+00, ...\n 0.8182955028627777E+00, ...\n 0.9743827435800610E+00, ...\n 1.155432469636406E+00, ...\n 1.366396525527973E+00, ...\n 1.613118767572064E+00, ...\n 1.902515460838681E+00, ...\n 2.242790117769266E+00, ...\n 2.643689828630357E+00, ...\n 3.116811526884873E+00, ...\n 3.675968313148932E+00, ...\n 4.337627987747642E+00, ...\n 5.121438384183637E+00 ];\n\n x_vec = [ ...\n 0.1E+00, ...\n 0.2E+00, ...\n 0.4E+00, ...\n 0.6E+00, ...\n 0.8E+00, ...\n 1.0E+00, ...\n 1.2E+00, ...\n 1.4E+00, ...\n 1.6E+00, ...\n 1.8E+00, ...\n 2.0E+00, ...\n 2.2E+00, ...\n 2.4E+00, ...\n 2.6E+00, ...\n 2.8E+00, ...\n 3.0E+00, ...\n 3.2E+00, ...\n 3.4E+00, ...\n 3.6E+00, ...\n 3.8E+00, ...\n 4.0E+00 ];\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 x = 0.0;\n fx = 0.0;\n else\n x = x_vec(n_data);\n fx = fx_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/bessel_i1_spherical_values.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370312, "lm_q2_score": 0.8791467659263148, "lm_q1q2_score": 0.8223068559787636}} {"text": "function [y,s]=gammalns(x)\n% GAMMALNS Log of Gamma(x) for positive or negative real x [y,s]=(x)\n%\n% Inputs: x real matrix of input values\n%\n% Outputs: y log(gamma(x)) or, if s is present, log(abs(gamma(x))) \n% s sign(gamma(x))\n%\n% If s is not specified then y will b complex if gamma(x) is negative (i.e. if floor(x) is negative and odd).\n% Uses gamma(x) = pi/gamma(1-z)/sin(pi*z) which is 5.5.3 from [1]\n%\n% [1]\tF. W. J. Olver, D. W. Lozier, R. F. Boisvert, and C. W. Clark, editors.\n% NIST Handbook of Mathematical Functions. CUP, 2010. ISBN 978-0-521-14063-8.\n\n% Copyright (C) Mike Brookes 2017\n% Version: $Id: gammalns.m 9975 2017-07-02 09:57:41Z 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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\npersistent l\nm=x<=0;\ny=zeros(size(x));\ns=ones(size(x));\nif ~all(m(:)) % non-negative x values\n y(~m)=gammaln(x(~m));\nend\nf=m & (x==fix(x)); % find and non-positive integers\nif any(f(:))\n y(f)=Inf; % set output to infinity\n m=m & ~f; % do not consider these values furhter\nend\nif any(m(:)) % negative x values\n if isempty(l)\n l=log(pi);\n end\n t=sin(pi*x(m));\n if nargout>1\n p=t<0;\n s(m)=1-2*(p); \n y(m)=l-gammaln(1-x(m))-log(abs(t));\n else\n y(m)=l-gammaln(1-x(m))-log(t);\n end\nend\n \n", "meta": {"author": "jtkim-kaist", "repo": "Speech-enhancement", "sha": "84f1a3c1273fb4952522b911dd62cbb4476a534d", "save_path": "github-repos/MATLAB/jtkim-kaist-Speech-enhancement", "path": "github-repos/MATLAB/jtkim-kaist-Speech-enhancement/Speech-enhancement-84f1a3c1273fb4952522b911dd62cbb4476a534d/SE/lib/sub_lib/voicebox/gammalns.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.8887588038050466, "lm_q1q2_score": 0.822306271742077}} {"text": "function error_frobenius = r8mat_is_inverse_left ( m, n, a, b )\n\n%*****************************************************************************80\n%\n%% R8MAT_IS_INVERSE_LEFT determines if one matrix is the left inverse of another.\n%\n% Discussion:\n%\n% This routine returns the Frobenius norm of B * A - I.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 10 July 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns \n% of the matrix.\n%\n% Input, real A(M,N), the matrix.\n%\n% Input, real B(N,M), the matrix to be checked as a left inverse of A.\n%\n% Output, real ERROR_FROBENIUS, the Frobenius norm\n% of the difference matrix B * A - I, which would be exactly zero\n% if B was the exact left inverse of A and computer arithmetic were exact.\n%\n c(1:n,1:n) = b(1:n,1:m) * a(1:m,1:n);\n\n for i = 1 : n\n c(i,i) = c(i,i) - 1.0;\n end\n\n error_frobenius = r8mat_norm_fro ( n, n, c );\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/test_mat/r8mat_is_inverse_left.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229961215457, "lm_q2_score": 0.8887587920192298, "lm_q1q2_score": 0.8223062626698484}} {"text": "function [xi,w]=orthoPolyZerosFromRecur(n,a,b,c,mu0)\n%%ORTHOPOLYZEROSFROMRECUR Consider a family of polynomials p_n(x) such that\n% p_n(x) is nth order and the polynomials are orthonormal with\n% respect to some weighting function w(x). This means that\n% integral_lowL^upL w(x)*p_n(x)*p_m(x) dx =1 if m=n and is\n% zero otherwise. All such polynomials can be written in\n% recursive form as\n% p_i(x)=(a(i)*x+b(i))*p_{(i-1)}(x)-c(i)*p_{i-2}(x)\n% starting with p_{-1}(x)=0 and p_0(x)=1. This function finds\n% the zeros of the nth polynomial given expressions for the\n% recursion of the polynomials. Parameters for common\n% orthogonal polynomials are given below. The zeros of such\n% orthonormal polynomials can be used as quadrature points for\n% 1D integration from lowL to upL of all polynomials up to\n% order 2*n-1 times the weighting function w(x). The\n% associated quadrature weights for such integrals can also be\n% returned by this function if two outputs are requested.\n%\n%INPUTS: n The order of the polynomial whose zeros are desired.\n% a,b,c There are two formulations for the input. In the first one,\n% a,b, and c are vectors or function handles such that a(i), b(i),\n% and c(i) give the appropriate values for the recursive\n% formulation of the function values in\n% p_i(x)=(a(i)*x+b(i))*p_{(i-1)}(x)-c(i)*p_{i-2}(x)\n% where the values of i used in a and b go from 1 to n, and\n% indices used in c(i) go from 2 to n. c(1) is not used.\n% Alternatively, if c is omitted or an empty matrix is passed,\n% then a and b are assumed to be coefficients in the three-term\n% expansion of the form\n% b(i)*p_i(x)=(x-a(i))*p_{(i-1)}(x)-b(i-1)*p_{i-2}(x)\n% and can be vectors or function handles. Indices of a run from 1\n% to n and b run from 1 to (n-1).\n% mu0 This parameter is only needed if the second output of this\n% function is desired. The quadrature weights must be scaled by\n% mu0=integral_lowL^upL w(x) dx. This is that mu0.\n%\n%OUTPUTS: xi The 1Xn set of zeros of the given set of orthonormal\n% polynomials.\n% w The set of n cubature weights associated with the orthonormal\n% polynomials. This requires the input mu0 be specified.\n%\n%When xi and w are used for quadrature integration, one can write\n%integral_lowL^upL w(x)*f(x) dx=sum_{i=1}^n w(i)*f(xi(i))\n%where the equality holds for all polynomials up to degree 2*n-1. This is\n%the fundamental theorem of Gaussian quadrature. Thus, finding the zeros of\n%polynomials that are orthonormal over a region of interest with respect to\n%a particular weighting function can be useful.\n%\n%The algorithm is that of [1]. Because an eigenvalue decomposition is used,\n%the results can be numerically unstable for large n.\n%\n%Examples of values for common polynomials, are given in [2]. Some are:\n%1) Hermite polynomials. These are orthonormal with respect to exp(-x^2)\n% integrated over (-Inf,Inf). The recursion from [3] is\n% mu0=sqrt(pi);\n% a=@(i)2;\n% b=@(i)0;\n% c=@(i)2*(i-1);\n%\n%2) Legendre polynomials. These are orthonormal with respect to w(x)=1 for\n% integration over [-1,+1]. The recursion from [3] is\n% mu0=2;\n% a=@(i)(2*(i-1)+1)/i;\n% b=@(i)0;\n% c=@(i)(i-1)/i;\n%However, the function GaussLegendrePoints1D should provide\n%higher-precision zeros than this function.\n%\n%3) Laguerre polynomials. These are orthonormal with respect to\n% w(x)=exp(-x) for integration over [0,Inf). The recursion from [3] is\n% mu0=1;\n% a=@(i)-1/i;\n% b=@(i)(2*(i-1)+1)/i;\n% c=@(i)(i-1)/i;\n%\n%4) Associated Laguerre polynomials. These are orthonormal with respect to\n% w(x)=x^c1*exp(-x) for integration over [0,Inf). When considering\n% c1>-1, the recursion from [3] is\n% mu0=gamma(1+c1);\n% a=@(i)(-1/i);\n% b=@(i)(2*i-1+c1)/i;\n% c=@(i)(i-1+c1)/i;\n%\n%5) Gegenbauer polynomials. These are orthonormal with respect to\n% w(x)=(1-x^2)^(c1-1/2) for integration over [-1,1]. When considering\n% c1>-(1/2), the recursion from [3] is\n% mu0=(sqrt(pi)*gamma((1/2)+c1))/gamma(1+c1);\n% a=@(i)2*(i+c1-1)/i;\n% b=@(i)0;\n% c=@(i)(i+2*c1-2)/i;\n%\n%6) Modified Hermite polynomials that are orthogonal with respect to the\n% standard normal N(0,1) distribution integrated over (-Inf,Inf). These\n% are for w(x)=1/sqrt(2*pi)*exp(-x^2/2). The recursion [3] is\n% mu0=1;\n% a=@(i)1;\n% b=@(i)0;\n% c=@(i)i-1;\n%\n%REFERENCES:\n%[1] G. H. Golub and J. H. Welsh, \"Calculation of Gauss quadrature rules,\"\n% Mathematics of Computation, vol. 23, pp. 221-230, 1969.\n%[2] Weisstein, Eric W. \"Orthogonal Polynomials.\" From MathWorld--A Wolfram\n% Web Resource. http://mathworld.wolfram.com/OrthogonalPolynomials.html\n%[3] Abramowitz, M. and Stegun, I. A. (Eds.). \"Orthogonal Polynomials.\"\n% Table 22.7 in Ch. 22 in Handbook of Mathematical Functions with\n% Formulas, Graphs, and Mathematical Tables, 9th printing. New York:\n% Dover, pp. 782, 1972.\n%\n%August 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nJ=zeros(n,n);\nif(nargin<4||isempty(c))\n %If alpha and beta are directly given as a and b.\n for i=1:(n-1)\n J(i,i)=a(i);\n J(i,i+1)=b(i);\n J(i+1,i)=b(i);\n end\n J(n,n)=a(n);\nelse\n %The first row\n %Rows 1 through n-1\n for i=1:(n-1)\n bi=b(i);\n ai=a(i);\n aiNext=a(i+1);\n ciNext=c(i+1);\n\n %From Equation 2.2 in [1].\n alpha=-bi/ai;\n beta=sqrt(ciNext/(ai*aiNext));\n\n J(i,i)=alpha;\n J(i,i+1)=beta;\n J(i+1,i)=beta;\n end\n %The final row\n i=n;\n bi=b(i);\n ai=a(i);\n alpha=-bi/ai;\n J(i,i)=alpha;\nend\n\n[V,D]=eig(J);\n\nxi=diag(D)';\nw=abs(V(1,:)').^2*mu0;\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/orthoPolyZerosFromRecur.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088084787998, "lm_q2_score": 0.8856314738181875, "lm_q1q2_score": 0.8222280613588668}} {"text": "function p = circle_imp_points_3d ( r, pc, nc, n )\n\n%*****************************************************************************80\n%\n%% CIRCLE_IMP_POINTS_3D returns points on an implicit circle in 3D.\n%\n% Discussion:\n%\n% Points P on an implicit circle in 3D satisfy the equations:\n%\n% ( P(1) - PC(1) )^2\n% + ( P(2) - PC(2) )^2\n% + ( P(3) - PC(3) )^2 = R^2\n%\n% and\n%\n% ( P(1) - PC(1) ) * NC(1)\n% + ( P(2) - PC(2) ) * NC(2)\n% + ( P(3) - PC(3) ) * NC(3) = 0\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 R, the radius of the circle.\n%\n% Input, real PC(3,1), the center of the circle.\n%\n% Input, real NC(3,1), a nonzero vector that is normal to\n% the plane of the circle. It is customary, but not necessary,\n% that this vector have unit norm.\n%\n% Input, integer N, the number of points desired.\n% N must be at least 1.\n%\n% Output, real P(3,N), the coordinates of points\n% on the circle.\n%\n\n%\n% Get two unit vectors N1 and N2 which are orthogonal to each other,\n% and to NC.\n%\n [ n1, n2 ] = plane_normal_basis_3d ( pc, nc );\n%\n% Rotate R units away from PC in the plane of N1 and N2.\n%\n for i = 1 : n\n\n theta = ( 2.0 * pi * ( i - 1 ) ) / n;\n\n p(1:3,i) = ( pc(1:3,1) ...\n + r * ( cos ( theta ) * n1(1:3,1) ...\n + sin ( theta ) * n2(1:3,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/geometry/circle_imp_points_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996141, "lm_q2_score": 0.8723473647220786, "lm_q1q2_score": 0.8221932544713303}} {"text": "function[varargout]=cum2mom(varargin)\n%CUM2MOM Convert cumulants to moments.\n%\n% [M0,M1,...MN]=CUM2MOM(K0,K1,...KN) converts the first N cumulants \n% K0,K1,...KN into the first N moments M0,M1,...MN.\n%\n% The KN and MN are all scalars or arrays of the same size.\n%\n% Note for a probability density function, M0=1 and K0=0.\n%\n% MCELL=CUM2MOM(KCELL), where KCELL is a cell array whose (N+1)th\n% is the Nth cumulant, returns a similar cell array of moments.\n%\n% CUM2MOM is inverted by MOM2CUM. \n%\n% See also MOM2CUM, BELLPOLY.\n% \n% Usage: [m0,m1,m2]=cum2mom(k0,k1,k2);\n% mcell=cum2mom(kcell);\n% __________________________________________________________________\n% This is part of JLAB --- type 'help jlab' for more information\n% (C) 2008 J.M. Lilly --- type 'help jlab_license' for details\n\n%Tests for CUM2MOM are run by MOM2CUM.\nif strcmpi(varargin{1}, '--t'),return,end\n\nif nargin==1&&iscell(varargin{1})\n cum=varargin{1};\nelse\n cum=varargin;\nend\nmom=cell(size(cum));\nmom{1}=exp(cum{1});\n\ncum=cum(2:end);\nmom(2:end)=bellpoly(cum);\n\nfor i=2:length(mom)\n mom{i}=mom{i}.*mom{1};\nend\n\nif nargin==1&&iscell(varargin{1})\n varargout{1}=mom;\nelse\n varargout=mom;\nend\n\n", "meta": {"author": "jonathanlilly", "repo": "jLab", "sha": "9f32f63e647209bc1cb81c8713deb954857f1919", "save_path": "github-repos/MATLAB/jonathanlilly-jLab", "path": "github-repos/MATLAB/jonathanlilly-jLab/jLab-9f32f63e647209bc1cb81c8713deb954857f1919/jCommon/cum2mom.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.891811044719067, "lm_q1q2_score": 0.8221800708651212}} {"text": "function proj = projPointOnEllipse(point, elli)\n%PROJPOINTONELLIPSE Project a point orthogonally onto an ellipse.\n%\n% PROJ = projPointOnEllipse(PT, ELLI)\n% Computes the (orthogonal) projection of point PT onto the ellipse given\n% by ELLI.\n%\n%\n% Example\n% % create an ellipse and a point\n% elli = [50 50 40 20 30];\n% pt = [60 10];\n% % display reference figures\n% figure; hold on; drawEllipse(elli, 'b');\n% axis equal; axis([0 100 0 100]);\n% drawPoint(pt, 'bo');\n% % compute projected point\n% proj = projPointOnEllipse(pt, elli);\n% drawEdge([pt proj], 'b');\n% drawPoint(proj, 'k*');\n%\n% See also \n% ellipses2d, distancePointEllipse, projPointOnLine, ellipsePoint\n% drawEllipse\n%\n\n% ------\n% Author: David Legland\n% E-mail: david.legland@inrae.fr\n% Created: 2022-07-17, using Matlab 9.12.0.1884302 (R2022a)\n% Copyright 2022 INRAE - BIA Research Unit - BIBS Platform (Nantes)\n\n% defaults\nnMaxIters = 4;\n\n% compute transform to centered axis-aligned ellipse\ncenter = elli(1:2);\ntheta = deg2rad(elli(5));\ntransfo = createRotation(-theta) * createTranslation(-center);\npointT = transformPoint(point, transfo);\n\n% retrieve ellipse semi axis lengths\na = elli(3);\nb = elli(4);\n\n% keep absolute values\npx = abs(pointT(:,1));\npy = abs(pointT(:,2));\n\n% initial guess of solution\ntx = 0.707;\nty = 0.707;\n\n% iterate\nfor i = 1:nMaxIters\n x = a * tx;\n y = b * ty;\n\n ex = (a*a - b*b) * power(tx, 3) / a;\n ey = (b*b - a*a) * power(ty, 3) / b;\n\n rx = x - ex;\n ry = y - ey;\n\n qx = px - ex;\n qy = py - ey;\n\n r = hypot(ry, rx);\n q = hypot(qy, qx);\n\n tx = min(1, max(0, (qx .* r ./ q + ex) / a));\n ty = min(1, max(0, (qy .* r ./ q + ey) / b));\n t = hypot(ty, tx);\n tx = tx ./ t;\n ty = ty ./ t;\n\nend\n\n% computes coordinates of projection\nprojX = a * tx;\nprojY = b * ty;\n\n% fix sign\nprojX(pointT(:,1) < 0) = -projX(pointT(:,1) < 0);\nprojY(pointT(:,2) < 0) = -projY(pointT(:,2) < 0);\n\n% project pack to basis of original ellipse\nproj = transformPoint([projX projY], inv(transfo));\n", "meta": {"author": "mattools", "repo": "matGeom", "sha": "1fd2c937064be1ee1f4fd09fbfdf96145ebe5271", "save_path": "github-repos/MATLAB/mattools-matGeom", "path": "github-repos/MATLAB/mattools-matGeom/matGeom-1fd2c937064be1ee1f4fd09fbfdf96145ebe5271/matGeom/geom2d/projPointOnEllipse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8807970748488296, "lm_q1q2_score": 0.8221631311907586}} {"text": "function sigma_n = sigma ( n )\n\n%*****************************************************************************80\n%\n%% SIGMA returns the value of SIGMA(N), the divisor sum.\n%\n% Definition:\n%\n% SIGMA(N) is the sum of the distinct divisors of N, including 1 and N.\n%\n% First values:\n%\n% N SIGMA(N)\n%\n% 1 1\n% 2 3\n% 3 4\n% 4 7\n% 5 6\n% 6 12\n% 7 8\n% 8 15\n% 9 13\n% 10 18\n% 11 12\n% 12 28\n% 13 14\n% 14 24\n% 15 24\n% 16 31\n% 17 18\n% 18 39\n% 19 20\n% 20 42\n%\n% Formula:\n%\n% SIGMA(U*V) = SIGMA(U) * SIGMA(V) if U and V are relatively prime.\n%\n% SIGMA(P^K) = ( P^(K+1) - 1 ) / ( P - 1 ) if P is prime.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 July 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the value to be analyzed.\n%\n% Output, integer SIGMA_N, the value of SIGMA(N). If N is less than\n% or equal to 0, SIGMA_N will be returned as 0. If there is not\n% enough room for factoring N, SIGMA_N is returned as -1.\n%\n maxfactor = 20;\n\n if ( n <= 0 )\n sigma_n = 0;\n return\n end\n\n if ( n == 1 )\n sigma_n = 1;\n return\n end\n%\n% Factor N.\n%\n [ nfactor, factor, power, nleft ] = i4_factor ( n );\n\n if ( nleft ~= 1 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'SIGMA - Fatal error!\\n' );\n fprintf ( 1, ' Not enough factorization space.\\n' );\n sigma_n = -1;\n error ( 'SIGMA - Fatal error!' );\n end\n\n sigma_n = 1;\n for i = 1 : nfactor\n sigma_n = ( sigma_n * ( factor(i)^( power(i) + 1 ) - 1 ) ) ...\n / ( factor(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/polpak/sigma.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8962513738264114, "lm_q1q2_score": 0.8221337729207397}} {"text": "function [ x, err, iter, flag ] = sor(A, x, b, w, max_it, tol)\n%\n% [ x, err, iter, flag ] = sor(A, x, b, w, max_it, tol)\n%\n% SOR Successive Over-Relaxation Method\n% This function solves linear equation systems such as Ax=b using SOR \n% method (Successive Over-Relaxation).\n% When the relaxation scalar w=1, the method used is Gauss-Seidel.\n%\n% Input:\n% A - input matrix\n% x - inicial vector\n% b - vector b\n% w - relaxation scalar\n% max_it - maximum number of iterations\n% tol - tolerance\n%\n% Output:\n% x - solution vector\n% err - norm err estimate\n% iter - nu,ber of performed iterations\n% flag - 0 = a solution was found / 1 = no convergence for max_it\n%\n% Example:\n% [ x, err, iter, flag ] = sor( [.5 .125; .125 .25], zeros(2,1),\n% ones(2,1), .5, 1e4, 1e-4 )\n%\n% Author:\tTashi Ravach\n% Version:\t1.0\n% Date: 08/06/2006\n%\n\n if nargin == 3\n w = .5;\n max_it = 1e4;\n tol = 1e-4;\n elseif nargin == 4\n max_it = 1e4;\n tol = 1e-4;\n elseif nargin == 5\n tol = 1e-4;\n elseif nargin ~= 6\n error('sor: invalid input parameters');\n end\n \n flag = 0;\n iter = 0;\n\n norma2_b = norm(b);\n if (norma2_b == 0.0)\n norma2_b = 1.0;\n end\n\n r = b - A * x;\n err = norm(r) / norma2_b;\n if (err < tol)\n return\n end\n\n % separate A into several matrix for SOR/Gauss-Seidel\n [ M, N, b ] = matsep(A, b, w, 2);\n\n for iter = 1 : max_it\n x_1 = x;\n x = M \\ (N * x + b); % adjust the aproximation\n %err = norm(x - x_1) / norm(x); % compute error\n err = norm(x_1 - x, 1); % compute error\n if (err <= tol) % check for convergence\n break\n end \n end\n b = b / w; % vector b\n\n if (err > tol) % no convergence\n flag = 1;\n end \n \nend\n\n\nfunction [ M, N, b ] = matsep(A, b, w, flag)\n%\n% [ M, N, b ] = matsep(A, b, w, flag)\n%\n% MATSEP Matrix Separation\n% Input matrix is splitted into several others in diferent ways depending\n% on the method to be used: Jacobi and SOR (Gauss-Seidel when w = 1)\n%\n% Input:\n% A - input matrix\n% x - inicial vector\n% b - vector b\n% flag - 1 = Jacobi / 2 = SOR\n%\n% Output:\n% M - matrix M\n% N - matrix N\n% b - vector b (modified for SOR)\n%\n% Author:\tTashi Ravach\n% Version:\t1.0\n% Date: 08/06/2006\n%\n\n if nargin ~= 4\n error('matsep: invalid input parameters');\n end\n \n [ m, n ] = size(A);\n if m ~= n\n error('matsep: input matrix A must have dimension nXn');\n end\n \n [ l, o ] = size(b);\n if l ~= n && o ~= 1\n error('matsep: input matrix b must have dimension nX1');\n end\n\n if (flag == 1) % separation for Jacobi\n M = diag(diag(A));\n N = diag(diag(A)) - A;\n elseif (flag == 2) % separation for SOR/Gauss-Seidel\n b = w * b;\n M = w * tril(A, -1) + diag(diag(A));\n N = -w * triu(A, 1) + (1.0 - w) * diag(diag(A));\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/28226-successive-over-relaxation/sor.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426831, "lm_q2_score": 0.8962513745192024, "lm_q1q2_score": 0.8221337613989874}} {"text": "function value = torus_square_volume_3d ( r1, r2 )\n\n%*****************************************************************************80\n%\n%% TORUS_SQUARE_VOLUME_3D returns the volume of a square torus in 3D.\n%\n% Integration region:\n%\n% Points (X,Y,Z) such that:\n%\n% R1 - R2 <= SQRT ( X**2 + Y**2 ) <= R1 + R2,\n% -R2 <= Z <= R2.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 20 May 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R1, R2, the two radii that define the torus.\n%\n% Output, real TORUS_SQUARE_VOLUME_3D, the volume of the torus.\n%\n value = 8.0E+00 * pi * r1 * r2 * 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/stroud/torus_square_volume_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768604361742, "lm_q2_score": 0.8705972784807408, "lm_q1q2_score": 0.8219978051002235}} {"text": "function mean = binomial_mean ( a, b )\n\n%*****************************************************************************80\n%\n%% BINOMIAL_MEAN returns the mean of the Binomial PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer A, the number of trials.\n% 1 <= A.\n%\n% Input, real B, the probability of success on one trial.\n% 0.0 <= B <= 1.0.\n%\n% Output, real MEAN, the expected value of the number of\n% successes in A trials.\n%\n mean = a * b;\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/binomial_mean.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625069680097, "lm_q2_score": 0.88242786954645, "lm_q1q2_score": 0.8219484755861761}} {"text": "function w = faddeeva(z,N)\n% FADDEEVA Faddeeva function\n% W = FADDEEVA(Z) is the Faddeeva function, aka the plasma dispersion\n% function, for each element of Z. The Faddeeva function is defined as:\n%\n% w(z) = exp(-z^2) * erfc(-j*z)\n%\n% where erfc(x) is the complex complementary error function.\n%\n% W = FADDEEVA(Z,N) can be used to explicitly specify the number of terms\n% to truncate the expansion (see (13) in [1]). N = 16 is used as default.\n%\n% Example:\n% x = linspace(-10,10,1001); [X,Y] = meshgrid(x,x); \n% W = faddeeva(complex(X,Y)); \n% figure; \n% subplot(121); imagesc(x,x,real(W)); axis xy square; caxis([-1 1]); \n% title('re(faddeeva(z))'); xlabel('re(z)'); ylabel('im(z)'); \n% subplot(122); imagesc(x,x,imag(W)); axis xy square; caxis([-1 1]);\n% title('im(faddeeva(z))'); xlabel('re(z)'); ylabel('im(z)'); \n%\n% Reference:\n% [1] J.A.C. Weideman, \"Computation of the Complex Error Function,\" SIAM\n% J. Numerical Analysis, pp. 1497-1518, No. 5, Vol. 31, Oct., 1994 \n% Available Online: http://www.jstor.org/stable/2158232\n\nif nargin<2, N = []; end\nif isempty(N), N = 16; end\n\nw = zeros(size(z)); % initialize output\n\n%%%%%\n% for purely imaginary-valued inputs, use erf as is if z is real\nidx = real(z)==0; %\nw(idx) = exp(-z(idx).^2).*erfc(imag(z(idx)));\n\nif all(idx), return; end\nidx = ~idx;\n\n%%%%%\n% for complex-valued inputs\n\n% make sure all points are in the upper half-plane (positive imag. values)\nidx1 = idx & imag(z)<0;\nz(idx1) = conj(z(idx1));\n\nM = 2*N;\nM2 = 2*M;\nk = (-M+1:1:M-1)'; % M2 = no. of sampling points.\nL = sqrt(N/sqrt(2)); % Optimal choice of L.\n\ntheta = k*pi/M;\nt = L*tan(theta/2); % Variables theta and t.\nf = exp(-t.^2).*(L^2+t.^2);\nf = [0; f]; % Function to be transformed.\na = real(fft(fftshift(f)))/M2; % Coefficients of transform.\na = flipud(a(2:N+1)); % Reorder coefficients.\n\nZ = (L+1i*z(idx))./(L-1i*z(idx));\np = polyval(a,Z); % Polynomial evaluation.\nw(idx) = 2*p./(L-1i*z(idx)).^2 + (1/sqrt(pi))./(L-1i*z(idx)); % Evaluate w(z).\n\n% convert the upper half-plane results to the lower half-plane if necesary\nw(idx1) = conj(2*exp(-z(idx1).^2) - w(idx1));\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/22207-faddeeva-function-fft-based/faddeeva.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.8824278649085118, "lm_q1q2_score": 0.8219484679083253}} {"text": "%% SQUAREPOISSON Poisson equation in a square domain.\n%\n% squarePoisson computes approximations of the Poisson equation in the\n% unit square on a sequence of meshes obtained by uniform refinement. It\n% plots the approximation error (in L2 norm or H1 norm) vs the number of\n% nodes.\n% \n% See also Poisson, crack, Lshape\n%\n% Copyright (C) Long Chen. See COPYRIGHT.txt for details.\n\nclose all; clear all;\n%% Parameters \nmaxIt = 4; N = zeros(maxIt,1);\nerruIuh = zeros(maxIt,1);\n\n%% Generate an initial mesh \n[node,elem] = squaremesh([0 1 0 1], 0.25);\n%bdFlag = setboundary(node,elem,'Dirichlet','~(x==0)','Neumann','x==0');\nbdFlag = setboundary(node,elem,'Dirichlet','all','Neumann','y==1');\n%bdFlag = setboundary(node,elem,'Dirichlet');\nfor k = 1:3\n [node,elem,bdFlag] = uniformrefine(node,elem,bdFlag);\n% [node,elem,bdFlag] = uniformbisect(node,elem,bdFlag);\nend\n\n%% Get the data of the pde\npde = sincosdata;\n% pde = mixBCdata;\noption.solver = 'mg';\n\n%% Finite Element Method \nfor k = 1:maxIt\n % solve the equation\n [u,Du,eqn] = PoissonWG(node,elem,pde,bdFlag,option);\n N(k) = size(elem,1);\n % compute error\n uI = zeros(N(k)+size(eqn.edge,1),1);\n uI(1:N(k)) = pde.exactu((node(elem(:,1),:)+node(elem(:,2),:)+node(elem(:,3),:))/3);\n uI(N(k)+1:end) = pde.exactu((node(eqn.edge(:,1),:)+node(eqn.edge(:,2),:))/2);\n erruIuh(k) = sqrt((u-uI)'*eqn.A*(u-uI));\n % refine mesh\n [node,elem,bdFlag] = uniformrefine(node,elem,bdFlag);\n% [node,elem,bdFlag] = uniformbisect(node,elem,bdFlag);\nend\n\n%% Plot convergence rates\nfigure(2);\nshowrate(N,erruIuh);\n%% Error table\n% The optimal rate of convergence of the H1-norm (1st order) and L2-norm\n% (2nd order) is observed. The 2nd order convergent rate between two\n% discrete functions ||DuI-Duh|| is known as superconvergence.\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/example/2D/squarePoissonWG.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.894789468908171, "lm_q1q2_score": 0.8218464437640546}} {"text": "% Excersize 1 - Calculate the equilibrium surface temperature of an icy\n% body (e.g. a comet) at a given distance from the Sun.\n\n% This sample program is a script that balances the equation of heat\n% transfer on the surface of a ball made of ice, to find an equilibrium\n% temperature. This script demonstrates how physical units can be used in\n% calculations.\n\n%% Set up the workspace with needed variables\nsi=setUnits;\n% We begin by calling the |setUnits| function in order to get the interface\n% structure that holds all predefined units.\n\nLSun=3.8e26*si.joule/si.second;\n% Total brightness of the Sun. This is the energy radiated by the Sun every\n% second. (Tip: si.s is shorthand for si.second.)\n\ndSun=2.5*1.496e11*si.meter;\n% Distance from the Sun to the body whose temperature we must calculate. I\n% have chosen a distance of 2.5 astronomical units (Earth-Sun distances)\n% that puts our \"comet\" betwen Mars and Jupiter. (Tip: si.astronomical_unit\n% is already defined, and si.AU is even easier. Also, si.m is shorthand for\n% si.meter.)\n\nKB=1.3806e-23*si.joule/si.K;\n% Boltzmann's constant. (Tip: si.boltzmann is defined.)\n\nstefan=5.67e-8*si.joule/si.m^2/si.s/si.K^4;\n% The Stefan-Boltzmann constant. (Tip: Guess what, si.stefan_boltzmann.)\n\nHice=2.8345e6*si.joule/si.kg;\n% Latent heat for sublimation of ice.\n\nA=3.56e12*si.newton/si.m^2; B=6141.667*si.kelvin;\n% These parameters are used in an empirical formula for the saturation\n% vapor pressure. (Tip: si.N and si.K are shorter.)\n\navogad=6.022e23*si.mole^(-1);\n% Avogadro's number. (Tip: Try si.avogadro.)\n\nmH2O=18*si.g/si.mole;\n% The molecular weight of water.\n\n%% Now, Lion-hunt for the temperature of equilibrium\n% When we write down the equation:\n% radiant energy from the Sun = (radiant + sublimation)energy from the body\n% we essentially get an implicit function of temperature vs. distance from\n% the Sun. This function however cannot be inverted so we need to hunt for\n% the temperature that will balance the equation.\n\ntol=1e-3;\n% We'll use this as the relative accuracy.\n\nTlo=1*si.K; Thi=400*si.K;\n% The desired temperature is definitely bracketed by these values.\n\nwhile (Thi-Tlo)/Thi>tol\n T=(Tlo+Thi)/2;\n fT=(stefan*T^4)+(Hice*sqrt(mH2O/(2*avogad*pi*KB*T))*A*exp(-(B/T)))-...\n (0.25*(LSun/(4*pi*dSun^2)));\n if double(fT)>0\n Thi=T;\n else\n Tlo=T;\n end\nend\n\n%% That's it. The desired temperature is\nfprintf('The equilibrium temperature is\\n')\nT\n% Try to introduce an easy-to-make-hard-to-detect error in one of the above\n% statements, and run the script again. Instead of getting a wrong answer\n% you will probably get an informative error message that will help you\n% trace the \"bug\".", "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/13018-physunits-module-from-fortran/physunits/iceball.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632329799585, "lm_q2_score": 0.8633916029436189, "lm_q1q2_score": 0.8218307225056617}} {"text": "function C = xeucn( A, T, shape )\n% n-dimensional euclidean distance between each window in A and template T.\n%\n% Similar to normxcorrn, except at each point (i,j) calculates the\n% euclidean distance between the T and the window in A surrounding the\n% point, storing the result in C(i,j).\n%\n% USAGE\n% C = xeucn( A, T, [shape] )\n%\n% INPUTS\n% A - first d-dimensional matrix\n% T - second d-dimensional matrix\n% shape - ['full'] 'valid', or 'same' (see convn)\n%\n% OUTPUTS\n% C - correlation matrix\n%\n% EXAMPLE\n% T=gaussSmooth(rand(20),2); A=repmat(T,[3 3]);\n% C1=normxcorrn(T,A); C2=xcorrn(A,T); C3=xeucn(A,T);\n% figure(1); im(C1); figure(2); im(C2); figure(3); im(-C3);\n%\n% See also XCORRN, CONVNFAST\n%\n% Piotr's Image&Video Toolbox Version 2.0\n% Copyright 2012 Piotr Dollar. [pdollar-at-caltech.edu]\n% Please email me if you find bugs, or have suggestions or questions!\n% Licensed under the Simplified BSD License [see external/bsd.txt]\n\nif( nargin<3 || isempty(shape)); shape='full'; end\nnd = ndims(T);\nif(nd~=ndims(A)); error('xeucn: T and A must have same ndims'); end;\n\n% flip for conv purposes\nif(nd==2); T=rot90(T,2); else for d=1:nd; T=flipdim(T,d); end; end\n\n% The expression for euclidean distance can be rewritten as:\n% D(k,l) = sumj( (Akj - Tlj).^2 )\n% = sumj( Akj.^2 ) + sumj( Tlj.^2 ) - 2*sumj(Akj.*Tlj);\n% T is constant. Hence simply need square of A in each window, as\n% well as each dot product between A and T.\nAmag = localSum( A.*A, size(T), shape ); % sum of squares per window\nTmag = T.^2; Tmag = sum( Tmag(:) ); % sum of squares of T\nC = Amag + Tmag - 2 * convnFast(A,T,shape); % distance squared\n% C( Amag<.01 ) = Tmag; % prevent numerical errors\nC = real(sqrt(real(C)));\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/Toolbox/SketchTokens-master/toolbox/images/xeucn.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391600697869, "lm_q2_score": 0.8902942261220292, "lm_q1q2_score": 0.8217764346946588}} {"text": "function h=spreadop(f,coef)\n%SPREADOP Spreading operator\n% Usage: h=spreadop(f,c);\n%\n% `spreadop(f,c)` applies the operator with spreading function *c* to the\n% input *f*. *c* must be square.\n%\n% `spreadop(f,c)` computes the following for *c* of size $L \\times L$:\n% \n% .. L-1 L-1 \n% h(l+1) = sum sum c(m+1,n+1)*exp(2*pi*i*l*m/L)*f(l-n+1)\n% n=0 m=0\n%\n% .. math:: h\\left(l+1\\right)=\\sum_{n=0}^{L-1}\\sum_{m=0}^{L-1}c\\left(m+1,n+1\\right)e^{2{\\pi}ilm/L}f\\left(l-n+1\\right)\n%\n% where $l=0,\\ldots,L-1$ and $l-n$ is computed modulo *L*.\n%\n% The combined symbol of two spreading operators can be found by using\n% `tconv`. Consider two symbols *c1* and *c2* and define *f1* and *f2* by::\n%\n% h = tconv(c1,c2)\n% f1 = spreadop(spreadop(f,c2),c1);\n% f2 = spreadop(f,h);\n%\n% then *f1* and *f2* are equal.\n%\n% See also: tconv, spreadfun, spreadinv, spreadadj\n%\n% References: feko98\n\n% AUTHOR: Peter L. Søndergaard\n% TESTING: TEST_SPREAD\n% REFERENCE: REF_SPREADOP\n\ncomplainif_argnonotinrange(nargin,2,2,mfilename);\n\nif ndims(coef)>2 || size(coef,1)~=size(coef,2)\n error('Input symbol coef must be a square matrix.');\nend;\n\nL=size(coef,1);\n\n% Change f to correct shape.\n[f,Ls,W,wasrow,remembershape]=comp_sigreshape_pre(f,'DGT',0);\n\nf=postpad(f,L);\n\nh=zeros(L,W);\n\nif issparse(coef) && nnz(coef)\n ps = zeros(N,1);\n \nelse % get probabilities\n xs = (xs-m(:)*ones(1,N))';\n denom = (2*pi)^(d/2)*sqrt(abs(det(C)));\n mahal = sum( (xs/C).*xs, 2 );\n numer = exp(-0.5*mahal);\n ps = numer/denom;\nend\n", "meta": {"author": "pdollar", "repo": "toolbox", "sha": "e87332637bbe8e8b92dd487c87567d9628404523", "save_path": "github-repos/MATLAB/pdollar-toolbox", "path": "github-repos/MATLAB/pdollar-toolbox/toolbox-e87332637bbe8e8b92dd487c87567d9628404523/matlab/normpdf2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133565584851, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.8215568726198677}} {"text": "function [ x, y, w ] = legendre_2d_set ( a, b, nx, ny )\n\n%*****************************************************************************80\n%\n%% LEGENDRE_2D_SET: set a 2D Gauss-Legendre quadrature rule.\n%\n% Discussion:\n%\n% The integral:\n%\n% integral ( a(2) <= y <= b(2) ) ( a(1) <= x <= b(1) ) f(x,y) dx dy\n%\n% The quadrature rule:\n%\n% sum ( 1 <= i <= n ) w(i) * f ( x(i),y(i) )\n%\n% where n = nx * ny, the orders of the rule in the X and Y directions.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 29 May 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A(2), B(2), the lower and upper integration\n% limits.\n%\n% Input, integer NX, NY, the orders in the X and Y directions.\n% NX and NY must be between 1 and 10.\n%\n% Output, real X(N), Y(N), the abscissas.\n%\n% Output, real W(N), the weights.\n%\n\n%\n% Get the rules for [-1,+1].\n%\n [ xx, wx ] = legendre_set ( nx );\n [ yy, wy ] = legendre_set ( ny );\n%\n% Adjust from [-1,+1] to [A,B].\n%\n for i = 1 : nx\n xx(i) = ( ( 1.0 - xx(i) ) * a(1) ...\n + ( 1.0 + xx(i) ) * b(1) ) ...\n / 2.0;\n wx(i) = wx(i) * ( b(1) - a(1) ) / 2.0;\n end\n\n for j = 1 : ny\n yy(j) = ( ( 1.0 - yy(j) ) * a(2) ...\n + ( 1.0 + yy(j) ) * b(2) ) ...\n / 2.0;\n wy(j) = wy(j) * ( b(2) - a(2) ) / 2.0;\n end\n%\n% Compute the product rule.\n%\n n = nx * ny;\n x = zeros ( n, 1 );\n y = zeros ( n, 1 );\n w = zeros ( n, 1 );\n\n k = 0;\n for j = 1 : ny\n for i = 1 : nx\n k = k + 1;\n x(k) = xx(i);\n y(k) = yy(j);\n w(k) = wx(i) * wy(j);\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/square_exactness/legendre_2d_set.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409306, "lm_q2_score": 0.8791467770088162, "lm_q1q2_score": 0.821470495600488}} {"text": "function W = compute_mesh_weight(vertex,face,type,options)\n\n% compute_mesh_weight - compute a weight matrix\n%\n% W = compute_mesh_weight(vertex,face,type,options);\n%\n% W is sparse weight matrix and W(i,j)=0 is vertex i and vertex j are not\n% connected in the mesh.\n%\n% type is either \n% 'combinatorial': W(i,j)=1 is vertex i is conntected to vertex j.\n% 'distance': W(i,j) = 1/d_ij^2 where d_ij is distance between vertex\n% i and j.\n% 'conformal': W(i,j) = cot(alpha_ij)+cot(beta_ij) where alpha_ij and\n% beta_ij are the adjacent angle to edge (i,j)\n%\n% If options.normalize=1, the the rows of W are normalize to sum to 1.\n%\n% Copyright (c) 2007 Gabriel Peyre\n\noptions.null = 0;\n[vertex,face] = check_face_vertex(vertex,face);\n\nnface = size(face,1);\nn = max(max(face));\n\nif isfield(options, 'verb')\n verb = options.verb;\nelse\n verb = n>5000;\nend\n\nif nargin<3\n type = 'conformal';\nend\n\nswitch lower(type)\n case 'combinatorial'\n W = triangulation2adjacency(face);\n case 'distance'\n W = my_euclidean_distance(triangulation2adjacency(face),vertex);\n W(W>0) = 1./W(W>0);\n W = (W+W')/2; \n case 'conformal'\n % conformal laplacian\n W = sparse(n,n);\n ring = compute_vertex_face_ring(face);\n for i = 1:n\n if verb\n progressbar(i,n);\n end\n for b = ring{i}\n % b is a face adjacent to a\n bf = face(:,b);\n % compute complementary vertices\n if bf(1)==i\n v = bf(2:3);\n elseif bf(2)==i\n v = bf([1 3]);\n elseif bf(3)==i\n v = bf(1:2);\n else\n error('Problem in face ring.');\n end\n j = v(1); k = v(2);\n vi = vertex(:,i);\n vj = vertex(:,j);\n vk = vertex(:,k);\n % angles\n alpha = myangle(vk-vi,vk-vj);\n beta = myangle(vj-vi,vj-vk);\n % add weight\n W(i,j) = W(i,j) + cot( alpha );\n W(i,k) = W(i,k) + cot( beta );\n end\n end\n otherwise\n error('Unknown type.')\nend\n\nif isfield(options, 'normalize') && options.normalize==1\n W = diag(sum(W,2).^(-1)) * W;\nend\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nfunction beta = myangle(u,v);\n\ndu = sqrt( sum(u.^2) );\ndv = sqrt( sum(v.^2) );\ndu = max(du,eps); dv = max(dv,eps);\nbeta = acos( sum(u.*v) / (du*dv) );\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nfunction W = my_euclidean_distance(A,vertex)\n\nif size(vertex,1) S, C -> R, S -> W, R -> W. Node 1 is W, 2 is S, 3 is C, 4 is R.\n%\n% [A, names] = mk_adj_mat(connections, name, 1)\n% The last argument of 1 indicates that we should topologically sort the nodes (parents before children).\n% In the example, the numbering becomes: node 1 is C, 2 is R, 3 is S, 4 is W\n% and the return value of names gets permuted to {'Cloudy', 'Rain', 'Sprinkler', 'WetGrass'}.\n% Note that topological sorting the graph is only possible if it has no directed cycles.\n\nif nargin < 3, topological = 0; end\n \nn=length(names);\nA=zeros(n);\n[nr nc] = size(connections);\nfor r=1:nr\n from = strmatch(connections{r,1}, names, 'exact');\n assert(~isempty(from));\n to = strmatch(connections{r,2}, names, 'exact');\n assert(~isempty(to));\n %fprintf(1, 'from %s %d to %s %d\\n', connections{r,1}, from, connections{r,2}, to);\n A(from,to) = 1;\nend\n\nif topological\n order = topological_sort(A); \n A = A(order, order); \n names = names(order); \nend\n\n\n", "meta": {"author": "bayesnet", "repo": "bnt", "sha": "bebba5f437b4e1e29169f0f3669df59fb5392e62", "save_path": "github-repos/MATLAB/bayesnet-bnt", "path": "github-repos/MATLAB/bayesnet-bnt/bnt-bebba5f437b4e1e29169f0f3669df59fb5392e62/graph/mk_adj_mat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8976952859490985, "lm_q1q2_score": 0.8213022744075262}} {"text": "function [g]=gsp_design_expwin(G, bmax, a)\n%GSP_DESIGN_EXPWIN create an expwin window of lenth N with parameter a\n% Usage: g = gsp_design_expwin(G);\n% g = gsp_design_expwin(G, bmax);\n% g = gsp_design_expwin(G, bmax, a);\n%\n% Input parameters:\n% G : Graph structure\n% bmax : Maximum relative band (default 0.2)\n% a : Slope parameter (default 1).\n%\n% Output parameters\n% g : filter\n%\n% This function design the following filter:\n%\n% .. g(x) = s( (1-x) / bmax /lmax )\n%\n% .. math:: g(x) = s\\left(\\frac{1-x}{\\lambda_{\\text{max}} b_{\\text{max}} }\\right)\n% \n% where $s(x)$ is the step function\n%\n% .. / 0 if x < -1\n% .. s(x) = | exp(-a/x) / ( exp(-a/x) + exp(-a/(1-x)) ) if x in [-1, 1]\n% .. \\ 1 if x > 1\n%\n% .. math:: s(x)=\\begin{cases} 0 & \\mbox{if }x<-1 \\\\ \\frac{e^{-\\frac{a}{x}}}{e^{-\\frac{a}{x}}+e^{-\\frac{a}{1-x}}} & \\mbox{if }x\\in[-1,1]\\\\ 1 & \\mbox{if }x>1 \\end{cases}\n%\n% It uses a clever exponential construction to obtain an infinitely\n% differentiable function that is band limited!\n%\n% This function will compute the maximum eigenvalue of the laplacian. To\n% be more efficient, you can precompute it using::\n%\n% G = gsp_estimate_lmax(G);\n%\n% Example:::\n%\n% Nf = 4;\n% G = gsp_sensor(100);\n% G = gsp_estimate_lmax(G);\n% g = gsp_design_expwin(G); \n% gsp_plot_filter(G,g); \n%\n\n\n% Author: Nathanael Perraudin\n% Date : 18 December 2014\n\n\nif nargin<3\n a = 1;\nend\n\n\nif nargin<2\n bmax = 0.2;\nend\n\n\nif numel(bmax)>1\n g = cell(numel(bmax),1);\n for ii = 1:numel(bmax);\n g{ii} = gsp_design_expwin(G,bmax(ii),a);\n end\n return\nend\n\nif isstruct(G)\n if ~isfield(G,'lmax')\n% if param.verbose\n fprintf('GSP_DESIGN_EXPWIN has to compute lmax \\n')\n% end\n G = gsp_estimate_lmax(G);\n end\n lmax = G.lmax;\nelse\n lmax = G;\nend\n\ng = @(x) gsp_smooth_downstep(x/bmax/lmax, a , 1);\n \n\n \nend\n\n\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/filters/gsp_design_expwin.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603709, "lm_q2_score": 0.8807970889295663, "lm_q1q2_score": 0.8213021600069565}} {"text": "function K = intmat(N, varargin)\n%INTMAT Spectral integration matrix.\n% K = INTMAT(N) returns the N x N integration matrix associated with the\n% Chebyshev spectral collocation method at second-kind Chebyshev points. \n%\n% K = INTMAT(N, P) returns the N x N integration matrix of order P.\n%\n% K = INTMAT(N, P, DOM) scales the integration matrix K to the domain\n% DOM. DOM should be a 1x2 vector.\n%\n% K = INTMAT([M N]) returns the M x N first-order rectangular integration \n% matrix which maps from an N-point Chebyshev grid of the second kind to an \n% M-point Chebyshev grid of the same kind.\n% \n% K = INTMAT([M N], P) returns an M x N rectangular integration matrix of \n% order P which maps from an N-point to an M-point Chebyshev grid, both of\n% second kind.\n%\n% K = INTMAT([M N], P, DOM) returns the same K but scaled to the domain DOM.\n%\n% See also CUMSUMMAT, DIFFMAT, DIFFROW, INTROW.\n\n% This code has been written for Aurentz and Trefethen, \n% \"Block operators and spectral discretizations\", and is not\n% yet fully compliant with standard Chebfun coding practices.\n\n% Copyright 2015 by The University of Oxford and The Chebfun Developers.\n% See http://www.chebfun.org/ for Chebfun information.\n\n% Parse inputs\n[m, n, p, dom] = parseInputs(N, varargin{:});\n\n% Build Lagrange basis\nK = chebfun(eye(n),dom); \n\n% Integrate p times\nK = cumsum(K,p);\n\n% Evaluate at grid of size m\nK = feval(K,chebpts(m,dom));\n\nend\n\nfunction [m, n, p, dom] = parseInputs(N, varargin)\n% Parse the inputs to INTMAT.\n\np = 1;\ndom = [-1 1];\n\nif ( isscalar(N) )\n n = N;\n m = n;\nelse\n m = N(1);\n n = N(2);\nend\n\nfor j = 1:numel(varargin)\n v = varargin{j};\n if ( isnumeric(v) )\n if ( isscalar(v) )\n p = v;\n else\n dom = v;\n end\n else\n error('CHEBFUN:intmat:unknown', ...\n 'Unknown input of type %s.', class(v));\n end\nend\n\nend\n\n", "meta": {"author": "chebfun", "repo": "chebfun", "sha": "8c49396a55e46ddd57a1d108c6a8f32e37536d54", "save_path": "github-repos/MATLAB/chebfun-chebfun", "path": "github-repos/MATLAB/chebfun-chebfun/chebfun-8c49396a55e46ddd57a1d108c6a8f32e37536d54/intmat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.8856314617436728, "lm_q1q2_score": 0.8213021093131231}} {"text": "function [ Nreg ] = eigRegularizer( N, k )\n\n% -----------------------------------------------------------------\n% matrizer regularization by checking eigenvalues\n% -----------------------------------------------------------------\n%\n% N: input square matrix\n% k: required condition number\n\n% -----------------------------------------------------------------\n\n[V, D] = eig(N); \t\t\t\t\t % eigenvectors and eigenvalues\ne = diag(D); % eigenvalues (ascending order)\n\n% k = 1e6; % condition number\n% pos = find( e < (e(end)/k) );\n% e(pos) = e(end)/k; % regularized eigenvalues\n% Nreg = V*diag(e)*V'; % regularized matrix\n\npos = e < (max(e) / k);\ne(pos) = max(e) / k; % regularized eigenvalues\nNreg = V * diag(e) * V'; % regularized matrix\n%Nreg = real(V*diag(e)*V'); % regularized matrix\n\n% -----------------------------------------------------------------\n\n% figure; imagesc(N); colorbar\n% figure; imagesc(Nreg); colorbar\n% figure; imagesc(N-Nreg); colorbar\n", "meta": {"author": "goGPS-Project", "repo": "goGPS_MATLAB", "sha": "30644df61d2459e3347ac5f3e31b71d9f69f4b01", "save_path": "github-repos/MATLAB/goGPS-Project-goGPS_MATLAB", "path": "github-repos/MATLAB/goGPS-Project-goGPS_MATLAB/goGPS_MATLAB-30644df61d2459e3347ac5f3e31b71d9f69f4b01/source/utility/eigRegularizer.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750387190132, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.8212828716477847}} {"text": "% P. Perona and W. T. Freeman, \"A factorization approach to grouping\",\n% In H. Burkardt and B. Neumann, editors, Proc ECCV, pages 655-670, 1998.\n\n% Yair Weiss, \"Segmentation Using Eigenvectors: A Unifying View\", UC\n% Berkeley.\n\n% Asad Ali\n% GIK Institute of Engineering Sciences & Technology, Pakistan\n% Email: asad_82@yahoo.com\n\n% CONCEPT: Clustering algorithm based on thresholding of the first eigenvector of\n% the affinity matrix\nclear all;\nclose all;\n\nTHRESHOLD = 0.28; % change the threshold depending on the data.\n% generate the data\ndata = GenerateData(1);\n% break the block matrix structure\ndata = data(3:14,:);\nfigure,plot(data(:,1), data(:,2),'r+'),title('Original Data Points'); grid on;shg\n\naffinity = CalculateAffinity(data);\nfigure,imshow(affinity,[]),title('Affinity Matrix')\n\n[eigVectors,eigValues] = eig(affinity);\n\n% first eigenvector is the one which has the highest eigenvalue\nsz = size(eigVectors);\nfirstEig = eigVectors(:,sz(1,2));\n\n% plot the eigen vector corresponding to the largest eigen value\n[xx1,yy1,val1] = find(firstEig > THRESHOLD);\n[xx2,yy2,val2] = find(firstEig <= THRESHOLD);\nfigure,\nhold on;\nplot(data(xx1,1),data(xx1,2),'g*')\nplot(data(xx2,1),data(xx2,2),'b*')\nhold off;\ntitle('Clustering Results after thresholding the First Eigenvector');\ngrid on;shg\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/26354-spectral-clustering-algorithms/Spectral Clustering/Perona_Freeman.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191348157374, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.8212532355217335}} {"text": "function volume = ball01_volume ( )\n\n%*****************************************************************************80\n%\n%% BALL01_VOLUME returns the volume of the unit ball.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 02 January 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Output, real VOLUME, the volume of the unit ball.\n%\n r = 1.0;\n volume = 4.0 * pi * r ^ 3 / 3.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/ball_monte_carlo/ball01_volume.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.891811041124754, "lm_q1q2_score": 0.8211703995132557}} {"text": "function [dStates, A, B, Positions] = Derive_EoM()\n\n%This function derives the equations of motion for a tractor trailer truck.\n\n%The outputs assume that the states and inputs are being listed in the\n%order in which they are defined\n\n%% Parameters\n\nLt = sym('Lt');\nLc = sym('Lc');\n\n%% Inputs\n\nv = sym('v');\npsi = sym('psi');\n\n%% States\n\nx = sym('x');\ny = sym('y');\nth = sym('th');\nphi = sym('phi');\n\n%% State Derivatives\n\nDx = sym('Dx');\nDy = sym('Dy');\nDth = sym('Dth');\nDphi = sym('Dphi');\n\n%% Equations of motion\n\n%Unit Vectors\n i = [1;0];\n j = [0;1];\n\n An = cos(th)*i + sin(th)*j;\n At = -sin(th)*i + cos(th)*j;\n Bn = cos(phi)*An + sin(phi)*At;\n Bt = -sin(phi)*An + cos(phi)*At;\n Cn = cos(psi)*Bn + sin(psi)*Bt;\n Ct = -sin(psi)*Bn + cos(psi)*Bt;\n\n%Derivatives of Unit Vectors\n dAn = Dth*At;\n dAt = -Dth*An;\n dBn = (Dphi + Dth)*Bt;\n dBt = -(Dphi + Dth)*Bn;\n\n%Position Vectors\n Pa = x*i + y*j;\n Pb = Pa + Lt*At;\n Pc = Pb + Lc*Bt;\n Positions = [Pa,Pb,Pc];\n \n%Derivatives of Position Vectors\n dPa = Dx*i + Dy*j;\n dPb = dPa + Lt*dAt;\n dPc = dPb + Lc*dBt;\n \n%Trailer Back Wheel Constraint\n RHS_1 = 0;\n LHS_1 = Dot(dPa,An);\n \n%Cab Back Wheel Constraint\n RHS_2 = 0;\n LHS_2 = Dot(dPb,Bn);\n \n%Cab Front Wheel Constraints\n RHS_3 = dPc(1);\n LHS_3 = v*Ct(1);\n \n RHS_4 = dPc(2);\n LHS_4 = v*Ct(2);\n\n%Solve for State Derivatives\n Solution = solve(...\n RHS_1-LHS_1, RHS_2-LHS_2, RHS_3-LHS_3, RHS_4-LHS_4,...\n Dx, Dy, Dth, Dphi); \n \n%Express as Vector [Dx, Dy, Dth, Dphi]\n\n dStates = [...\n Solution.Dx;\n Solution.Dy;\n Solution.Dth;\n Solution.Dphi];\n \n%% Jacobian Calculations\n\n J_x = diff(dStates,x);\n J_y = diff(dStates,y);\n J_th = diff(dStates,th);\n J_phi = diff(dStates,phi);\n J_v = diff(dStates,v);\n J_psi = diff(dStates,psi);\n \n A = [J_x, J_y, J_th, J_phi];\n B = [J_v, J_psi];\n\nend", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/tractorTrailer/Derive_EoM.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.963779943094681, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.8210950248117697}} {"text": "function [inv_map,bi_inv_map,logdet,invA] = invchol2(A)\n% INVCHOL2\n% Does a Cholesky decomposition on A and returns logdet, inverse and\n% two function handles that respectively map X to A\\X and A\\X/A.\n%\n\nif nargin==0\n test_this();\n return;\nend\n\nif isreal(A)\n\n R = chol(A); %R'*R = A\n inv_map = @(X) R\\(R'\\X); \n\n % inv(A)*X*inv(A)\n bi_inv_map = @(X) (inv_map(X)/R)/(R');\n\n\n if nargout>2\n logdet = 2*sum(log(diag(R)));\n if nargout>3\n invA = inv_map(eye(size(A)));\n end\n end\nelse\n inv_map = @(X) A\\X; \n\n % inv(A)*X*inv(A)\n bi_inv_map = @(X) (A\\X)/A;\n\n\n if nargout>2\n logdet = log(det(A));\n if nargout>3\n invA = inv_map(eye(size(A)));\n end\n end\nend\n\nfunction test_this()\ndim = 3;\nr = randn(dim,2*dim);\nA = r*r';\n[inv_map,bi_inv_map,logdet,iA] = invchol2(A);\n[logdet,log(det(A))]\nX = randn(dim,3);\nY1 = A\\X,\nY2 = inv_map(X)\n\nZ1 = (A\\X)/A\nZ2 = bi_inv_map(X)\n\n\niA,\ninv(A)\n", "meta": {"author": "nesl", "repo": "asvspoof2019", "sha": "8b780369f7273345c22d979192119198bbf3db13", "save_path": "github-repos/MATLAB/nesl-asvspoof2019", "path": "github-repos/MATLAB/nesl-asvspoof2019/asvspoof2019-8b780369f7273345c22d979192119198bbf3db13/baseline/tDCF_v1/bosaris_toolkit.1.06/bosaris_toolkit/utility_funcs/Optimization_Toolkit/MV2DF/utils/invchol2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338057771059, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.8210659773599043}} {"text": "function [t] = LineSearchGoldenSection(func,LB,UB,EPSILON)\n%\n% Golden Section search for an approximate minimum of unimodal \n% function f(t) using only function evaluations\n%\n% length of location interval is reduced by 0.318 each iteration \n%\n\nnarginchk(3,4);\nif nargin == 3\n EPSILON = max(abs(UB) + abs(LB),2)*0.5e-4;\nend\nGR = (sqrt(5)-1)/2; % 0.618\n\nl = UB - (UB-LB)*GR;\nr = LB + (UB-LB)*GR;\nfl = func(l);\nfr = func(r);\nwhile UB - LB >= EPSILON\n if fl < fr\n UB = r;\n r = l;\n fr = fl;\n l = UB - (UB-LB)*GR;\n fl = func(l);\n else\n LB = l;\n l = r;\n fl = fr;\n r = LB + (UB-LB)*GR;\n fr = func(r);\n end\nend\n\nt = (UB+LB)/2;\n\nend", "meta": {"author": "yuanhao-cui", "repo": "Must-Reading-on-ISAC", "sha": "34cd6615c52ebca121428a979e756c608b195040", "save_path": "github-repos/MATLAB/yuanhao-cui-Must-Reading-on-ISAC", "path": "github-repos/MATLAB/yuanhao-cui-Must-Reading-on-ISAC/Must-Reading-on-ISAC-34cd6615c52ebca121428a979e756c608b195040/Codes/Fan2018TSP/Codes for DFRC Waveform Design/Waveform Design With Given Radar Beampatterns/LineSearchGoldenSection.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9489172615983309, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.8210260654590548}} {"text": "function value = lrline ( xu, yu, xv1, yv1, xv2, yv2, dv )\n\n%*****************************************************************************80\n%\n%% LRLINE determines if a point is left of, right or, or on a directed line.\n%\n% Discussion:\n%\n% The directed line is parallel to, and at a signed distance DV from\n% a directed base line from (XV1,YV1) to (XV2,YV2).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 February 2005\n%\n% Author:\n%\n% Original FORTRAN77 version by Barry Joe,\n% MATLAB version by John Burkardt\n%\n% Reference:\n%\n% Barry Joe,\n% GEOMPACK - a software package for the generation of meshes\n% using geometric algorithms,\n% Advances in Engineering Software,\n% Volume 13, pages 325-331, 1991.\n%\n% Parameters:\n%\n% Input, real XU, YU, the coordinates of the point whose\n% position relative to the directed line is to be determined.\n%\n% Input, real XV1, YV1, XV2, YV2, the coordinates of two points\n% that determine the directed base line.\n%\n% Input, real DV, the signed distance of the directed line\n% from the directed base line through the points (XV1,YV1) and (XV2,YV2).\n% DV is positive for a line to the left of the base line.\n%\n% Output, integer VALUE, the result:\n% +1, the point is to the right of the directed line;\n% 0, the point is on the directed line;\n% -1, the point is to the left of the directed line.\n%\n tol = 100.0 * eps;\n\n dx = xv2 - xv1;\n dy = yv2 - yv1;\n dxu = xu - xv1;\n dyu = yu - yv1;\n\n tolabs = tol * max ( abs ( dx ), ...\n max ( abs ( dy ), ...\n max ( abs ( dxu ), ...\n max ( abs ( dyu ), abs ( dv ) ) ) ) );\n\n t = dy * dxu - dx * dyu + dv * sqrt ( dx * dx + dy * dy );\n\n if ( tolabs < t )\n value = 1;\n elseif ( -tolabs <= t )\n value = 0;\n else\n value = -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/triangulation/lrline.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069105, "lm_q2_score": 0.8872045937171068, "lm_q1q2_score": 0.8208682626892643}} {"text": "function variance = uniform_discrete_variance ( a, b )\n\n%*****************************************************************************80\n%\n%% UNIFORM_DISCRETE_VARIANCE returns the variance of the Uniform discrete PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer A, B, the parameters of the PDF.\n% A <= B.\n%\n% Output, real VARIANCE, the variance of the PDF.\n%\n variance = ( ( b + 1 - a )^2 - 1 ) / 12.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/prob/uniform_discrete_variance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.8840392802184581, "lm_q1q2_score": 0.8207498477915198}} {"text": "function integral = circle01_monomial_integral ( e )\n\n%*****************************************************************************80\n%\n%% CIRCLE01_MONOMIAL_INTEGRAL: integrals on circumference of unit circle in 2D.\n%\n% Discussion:\n%\n% The integration region is \n%\n% X^2 + Y^2 = 1.\n%\n% The monomial is F(X,Y) = X^E(1) * Y^E(2).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 11 January 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Philip Davis, Philip Rabinowitz,\n% Methods of Numerical Integration,\n% Second Edition,\n% Academic Press, 1984, page 263.\n%\n% Parameters:\n%\n% Input, integer E(2), the exponents of X and Y in the \n% monomial. Each exponent must be nonnegative.\n%\n% Output, real INTEGRAL, the integral.\n%\n if ( any ( e(1:2) < 0 ) )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'CIRCLE01_MONOMIAL_INTEGRAL - Fatal error!\\n' );\n fprintf ( 1, ' All exponents must be nonnegative.\\n' );\n error ( 'CIRCLE01_MONOMIAL_INTEGRAL - Fatal error!' );\n end\n\n if ( any ( mod ( e(1:2), 2 ) == 1 ) )\n\n integral = 0.0;\n\n else\n\n integral = 2.0;\n\n for i = 1 : 2\n integral = integral * gamma ( 0.5 * ( e(i) + 1 ) );\n end\n\n integral = integral / gamma ( 0.5 * sum ( e(1:2) + 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/circle_integrals/circle01_monomial_integral.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966762263736, "lm_q2_score": 0.8670357494949104, "lm_q1q2_score": 0.8207331586413248}} {"text": "function omega_en_n = transport_rate(lat, Vn, Ve, h)\n% transport_rate: calculates the transport rate in the navigation frame.\n%\n% INPUT\n%\tlat, 1x1 latitude (rad).\n%\tVn, 1x1 North velocity (m/s).\n% Ve, 1x1 East velocity (m/s).\n% h, altitude (m).\n%\n% OUTPUT\n%\tomega_en_n, 3x3 skew-symmetric transport rate matrix (rad/s).\n%\n% Copyright (C) 2014, Rodrigo Gonzalez, all rights reserved.\n%\n% This file is part of NaveGo, an open-source MATLAB toolbox for\n% simulation of integrated navigation systems.\n%\n% NaveGo is free software: you can redistribute it and/or modify\n% it under the terms of the GNU Lesser General Public License (LGPL)\n% version 3 as published by the Free Software Foundation.\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 Lesser General Public License for more details.\n%\n% You should have received a copy of the GNU Lesser General Public\n% License along with this program. If not, see\n% .\n%\n% References:\n%\n% Paul D. Groves. Principles of GNSS, Inertial, and\n% Multisensor Integrated Navigation Systems. Second Edition.\n% Eq. 5.44, page 177.\n%\n% Version: 002\n% Date: 2022/01/25\n% Author: Rodrigo Gonzalez \n% URL: https://github.com/rodralez/navego\n\nh = abs(h);\n\n\n[RM,RN] = radius(lat);\n\nom_en_n(1,1) = Ve / (RN + h); % North\nom_en_n(2,1) = -(Vn / (RM + h)); % East\nom_en_n(3,1) = -(Ve * tan(lat) / (RN + h)); % Down\n\nomega_en_n = skewm(om_en_n);\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/ins/transport_rate.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741308615413, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.8206790059730004}} {"text": "function d = distancePointLine3d(point, line)\n%DISTANCEPOINTLINE3D Euclidean distance between 3D point and line.\n%\n% D = distancePointLine3d(POINT, LINE);\n% Returns the distance between point POINT and the line LINE, given as:\n% POINT : [x0 y0 z0]\n% LINE : [x0 y0 z0 dx dy dz]\n% D : (positive) scalar \n% \n% See also:\n% lines3d, isPointOnLine3d, distancePointEdge3d, projPointOnLine3d,\n% \n%\n% References\n% http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html\n\n% ---------\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 23/05/2005.\n%\n\n% HISTORY\n% 15/01/2007 unify size of input data\n% 31/01/2007 typo in data formatting, and replace norm by vecnorm3d\n% 12/12/2010 changed to bsxfun implementation - Sven Holcombe\n\n% cf. Mathworld (distance point line 3d) for formula\nd = bsxfun(@rdivide, vectorNorm3d( ...\n crossProduct3d(line(:,4:6), bsxfun(@minus, line(:,1:3), point)) ), ...\n vectorNorm3d(line(:,4:6)));\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/distancePointLine3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741308615412, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.8206790059730003}} {"text": "function variance = hypergeometric_variance ( n, m, l )\n\n%*****************************************************************************80\n%\n%% HYPERGEOMETRIC_VARIANCE returns the variance of the Hypergeometric PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of balls selected.\n% 0 <= N <= L.\n%\n% Input, integer M, the number of white balls in the population.\n% 0 <= M <= L.\n%\n% Input, integer L, the number of balls to select from.\n% 0 <= L.\n%\n% Output, real VARIANCE, the variance of the PDF.\n%\n variance = n * m * ( l - m ) * ( l - n ) / ( l * l * ( l - 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/prob/hypergeometric_variance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067147399244, "lm_q2_score": 0.8705972818382005, "lm_q1q2_score": 0.8205437839668305}} {"text": "function p = perms_m(n, m)\n%perms_m(n, m): return the mth permutation of the digits 1:n\n% where m is from 0 to factorial(n) - 1\n%\n% The ordering is fairly arbitrary, but there is a bijection between m to\n% the n! permutations (asking for same m twice gets same permutation), and\n% perms_m(n, 0) is 1:n in order.\n%\n% Example:\n% p = perms(1:4);\n% P = zeros(size(p));\n% for i = 1:size(P,1)\n% P(i, :) = perms_m(4, i-1)';\n% end\n% all(all(sortrows(P) == sortrows(p)))\n%\n% See also: perms, randperm, uperms, signs_m, nchoosek_m, sample_no_repl\n\n% Copyright 2010 Ged Ridgway\n% http://www.mathworks.com/matlabcentral/fileexchange/authors/27434\n \nn = ceil(abs(n)); m = round(abs(m));\n\nM = factorial(n) - 1; % max m\nif m < 0 || m > M\n error('perms_m:m_range', 'Require 0 <= m <= %d', M);\nend\n\np = zeros(n,1);\nd = 1:n;\nF = factorial(n); % (F in loop goes from factorial(n-1) to factorial(0))\nfor f = 1:n\n F = F / (n + 1 - f); % (here rather than end of loop to avoid div-by-0)\n x = floor(m / F);\n p(f) = d(f + x);\n d(f + x) = d(f);\n m = rem(m, F);\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/27321-unique-random-permutations/perms_m.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506716354847, "lm_q2_score": 0.8705972616934408, "lm_q1q2_score": 0.8205437663862062}} {"text": "function alpha_pq = moment_normalized ( n, x, y, p, q )\n\n%*****************************************************************************80\n%\n%% MOMENT_NORMALIZED computes a normalized moment of a polygon.\n%\n% Discussion:\n%\n% Alpha(P,Q) = Integral ( x, y in polygon ) x^p y^q dx dy / Area ( polygon )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 October 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Carsten Steger,\n% On the calculation of arbitrary moments of polygons,\n% Technical Report FGBV-96-05,\n% Forschungsgruppe Bildverstehen, Informatik IX,\n% Technische Universitaet Muenchen, October 1996.\n%\n% Parameters:\n%\n% Input, integer N, the number of vertices of the polygon.\n%\n% Input, real X(N), Y(N), the vertex coordinates.\n%\n% Input, integer P, Q, the indices of the moment.\n%\n% Output, real ALPHA_PQ, the normalized moment Alpha(P,Q).\n%\n nu_pq = moment ( n, x, y, p, q );\n nu_00 = moment ( n, x, y, 0, 0 );\n\n alpha_pq = nu_pq / nu_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/polygon_integrals/moment_normalized.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545348152283, "lm_q2_score": 0.8652240860523328, "lm_q1q2_score": 0.8203661408218806}} {"text": "function sca=RLSsca(X,loc,p)\n%Syntax: sca=RLSsca(X,loc,p)\n%___________________________\n%\n% Calculates the Reweighted Least Squares (RLS) scale parameter \n% of the columns of a matrix X.\n%\n% sca is the RLS estimated vector of scales.\n% X is the matrix with the data sets.\n% loc is the location vector. Its default value is the LMS location.\n% p is the number of parameters. Its default value is 1.\n%\n% Reference:\n% Rousseeuw PJ, Leroy AM (1987): Robust regression and outlier detection. Wiley.\n%\n%\n% Alexandros Leontitsis\n% Institute of Mathematics and Statistics\n% University of Kent at Canterbury\n% Canterbury\n% Kent, CT2 7NF\n% U.K.\n%\n% University e-mail: al10@ukc.ac.uk (until December 2002)\n% Lifetime e-mail: leoaleq@yahoo.com\n% Homepage: http://www.geocities.com/CapeCanaveral/Lab/1421\n%\n% Sep 3, 2001.\n\nif nargin<1 | isempty(X)==1\n error('Not enough input arguments.');\nelse\n % X must be 2-dimensional\n if ndims(X)>2\n error('Invalid data set.');\n end\n % If X is a row vector make it a column vector\n if size(X,1)==1\n X=X';\n end\n \n % n is the length of the data set\n n=size(X,1);\nend\n\n% For a single data point there is no need to proceed\nif n==1\n sca=0;\nelse\n \n % Check loc\n if nargin<2 | isempty(loc)==1\n % If you don't give loc, it is supposed the LMS location\n loc=LMSloc(X);\n else\n % loc must be a scalar/vector\n if min(size(loc))>1\n error('loc must be a scalar/vector.');\n end\n % loc must have the length of the columns of X\n if length(loc)~=size(X,2);\n error('loc must have the length of the columns of X.');\n end\n end\n\n % Check p\n if nargin<3 | isempty(p)==1\n % If p is omitted give it the value of 1\n p=1;\n else\n % p must be a scalar\n if sum(size(p))>2\n error('p must be a scalar.');\n end \n % p must be an integrer greater than 1\n if round(p)-p~=0 | p<1\n error('p must be an integrer greater than or equal to 1.');\n end\n end\n\n % Calculate the scale parameter for every column\n for i=1:size(X,2)\n \n % The differences from the location\n r=X(:,i)-loc(i);\n \n % Estimate the preliminary scale parameter\n s=LMSsca(r,0,p);\n if s==0\n w=1:n;\n else\n w=find(abs(r)/s<=2.5);\n end\n sca(i)=sqrt(sum(r(w).^2)/(length(w)-p));\n end\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/801-lms-toolbox/RLSsca.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.8856314723088732, "lm_q1q2_score": 0.8203637292583082}} {"text": "function a = hankel ( n, x )\n\n%*****************************************************************************80\n%\n%% HANKEL returns a HANKEL matrix.\n%\n% Formula:\n%\n% A(I,J) = X(I+J-1)\n%\n% Example:\n%\n% N = 5, X = ( 1, 2, 3, 4, 5, 6, 7, 8, 9 )\n%\n% 1 2 3 4 5\n% 2 3 4 5 6\n% 3 4 5 6 7\n% 4 5 6 7 8\n% 5 6 7 8 9\n%\n% 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% A is a Hankel matrix: constant along anti-diagonals.\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% 10 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Input, real X(2*N-1), the vector that defines A.\n%\n% Output, real A(N,N), the matrix.\n%\n a = zeros ( n, n );\n\n for j = 1 : n\n a(1:n,j) = x(j:j+n-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/test_mat/hankel.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558356, "lm_q2_score": 0.8887588008585925, "lm_q1q2_score": 0.8203591732859754}} {"text": "function P = khatrirao(varargin)\n%KHATRIRAO Khatri-Rao product of matrices.\n%\n% KHATRIRAO(A,B) computes the Khatri-Rao product of matrices A and\n% B that have the same number of columns. The result is the\n% column-wise Kronecker product\n% [KRON(A(:,1),B(:,1)) ... KRON(A(:,n),B(:,n))]\n%\n% KHATRIRAO(A1,A2,...) computes the Khatri-Rao product of\n% multiple matrices that have the same number of columns.\n%\n% KHATRIRAO(C) computes the Khatri-Rao product of\n% the matrices in cell array C.\n%\n% KHATRIRAO(...,'r') computes the Khatri-Rao product in reverse\n% order.\n%\n% Examples\n% A = rand(5,2); B = rand(3,2); C = rand(2,2);\n% khatrirao(A,B) %<-- Khatri-Rao of A and B\n% khatrirao(B,A,'r') %<-- same thing as above\n% khatrirao({C,B,A}) %<-- passing a cell array\n% khatrirao({A,B,C},'r') %<-- same as above\n%\n% See also TENSOR, KTENSOR.\n%\n%MATLAB Tensor Toolbox.\n%Copyright 2012, Sandia Corporation.\n\n% This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others.\n% http://www.sandia.gov/~tgkolda/TensorToolbox.\n% Copyright (2012) Sandia Corporation. Under the terms of Contract\n% DE-AC04-94AL85000, there is a non-exclusive license for use of this\n% work by or on behalf of the U.S. Government. Export of this data may\n% require a license from the United States Government.\n% The full license terms can be found in the file LICENSE.txt\n\n\n%% Error checking on input and set matrix order\n% Note that this next if/else check forces A to be a cell array.\nif ischar(varargin{end}) && varargin{end} == 'r'\n if nargin == 2 && iscell(varargin{1})\n % Input is a single cell array\n A = varargin{1};\n else\n % Input is a sequence of matrices\n A = {varargin{1:end-1}};\n end\n matorder = length(A):-1:1;\nelse\n if nargin == 1 && iscell(varargin{1})\n % Input is a single cell array\n A = varargin{1};\n else\n % Input is a sequence of matrices\n A = varargin;\n end\n matorder = 1:length(A);\nend\n\n%% Error check on matrices and compute number of rows in result \n\n% N = number of columns (must be the same for every input)\nN = size(A{1},2); \n\n% After loop, M = number of rows in the result\nM = 1; \n\nfor i = matorder\n if ndims(A) ~= 2\n error('Each argument must be a matrix');\n end\n if (N ~= size(A{i},2))\n error('All matrices must have the same number of columns.')\n end\n M = M * size(A{i},1);\nend\n\n%% Computation\n\n% Preallocate\nP = zeros(M,N);\n\n% Loop through all the columns\nfor n = 1:N\n % Loop through all the matrices\n ab = A{matorder(1)}(:,n);\n for i = matorder(2:end)\n % Compute outer product of nth columns\n ab = A{i}(:,n) * ab(:).';\n end\n % Fill nth column of P with reshaped result\n P(:,n) = ab(:); \nend\n\n", "meta": {"author": "andrewssobral", "repo": "mtt", "sha": "0152a77df09f24af4c294f46845931e4e0e63b55", "save_path": "github-repos/MATLAB/andrewssobral-mtt", "path": "github-repos/MATLAB/andrewssobral-mtt/mtt-0152a77df09f24af4c294f46845931e4e0e63b55/libs/tensor_toolbox_2.5/khatrirao.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768620069626, "lm_q2_score": 0.8688267762381844, "lm_q1q2_score": 0.8203261392161943}} {"text": "function [rank,WT]=rankSetPartition(q,WT)\n%%RANKSETPARTITION Return the set partition with the given rank in the\n% lexicographic ordering of all set parititions having length(n).\n% The partition is a length-n vector q that specifies which\n% partition each item belongs to. The order of the items in the\n% partitions is not important.\n%\n%INPUTS: q The nX1 set partition vector that should be ranked. Paritions\n% are numbered in increasing order starting from 1. That is, the\n% first occurence of partition numbered i in q is always before\n% the first occurences of partitions numbered j>1.\n% WT The is, optionally, the Williamson table. It is the table T in\n% [1]. The table is a function of length(q). If omitted, then the\n% table will be computed and returned so that futue calls to the\n% function can use \n%\n%OUTPUTS: rank The rank of the set partition in lexicographic order.\n% 0<=rank2\n logdet = 2*sum(log(diag(R)));\n if nargout>3\n invA = inv_map(eye(size(A)));\n end\n end\nelse\n [L,T,p] = lu(A,'vector');\n P = sparse(p,1:length(p),1);\n % P*A = L*U\n % L is lower triangular, with unit diagonal and unit determinant\n % T is upper triangular, det(T) = prod(diag(T), may have negative values on diagonal\n % P is a permuation matrix: P' = inv(P) and det(P) is +1 or -1\n % \n\n inv_map = @(X) T\\(L\\(P*X));\n\n % inv(A)*X*inv(A)\n bi_inv_map = @(X) ((inv_map(X)/T)/L)*P;\n\n\n if nargout>2\n logdet = sum(log(diag(T)))-log(det(P));\n if nargout>3\n invA = T\\(L\\P);\n end\n end\nend\n\nfunction test_this()\ndim = 3;\nA = randn(dim)+sqrt(-1)*randn(dim);\n[inv_map,bi_inv_map,logdet,iA] = invchol_or_lu(A);\n[logdet,log(det(A))]\nX = randn(dim,3);\nY1 = A\\X,\nY2 = inv_map(X)\n\nZ1 = (A\\X)/A\nZ2 = bi_inv_map(X)\n\n\niA,\ninv(A)\n", "meta": {"author": "nesl", "repo": "asvspoof2019", "sha": "8b780369f7273345c22d979192119198bbf3db13", "save_path": "github-repos/MATLAB/nesl-asvspoof2019", "path": "github-repos/MATLAB/nesl-asvspoof2019/asvspoof2019-8b780369f7273345c22d979192119198bbf3db13/baseline/tDCF_v1/bosaris_toolkit.1.06/bosaris_toolkit/utility_funcs/Optimization_Toolkit/MV2DF/utils/invchol_or_lu.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693631290969, "lm_q2_score": 0.8633916047011595, "lm_q1q2_score": 0.8199365553675592}} {"text": "function [ u, v ] = uv_spiral ( n, x, y, c )\n\n%*****************************************************************************80\n%\n%% UV_SPIRAL computes a spiral velocity vector field.\n%\n% Discussion:\n%\n% Note that the continuous velocity field (U,V)(X,Y) that is discretely\n% sampled here satisfies the homogeneous continuity equation, that is,\n% it has zero divergence. In other words:\n%\n% dU/dX + dV/dY = 0.\n%\n% This is by construction, since we have\n%\n% U(X,Y) = 10 * d/dY ( PHI(X) * PHI(Y) )\n% V(X,Y) = -10 * d/dX ( PHI(X) * PHI(Y) )\n%\n% which guarantees zero divergence.\n%\n% The underlying function PHI is defined by\n%\n% PHI(Z) = ( 1 - cos ( C * pi * Z ) ) * ( 1 - Z )^2\n%\n% where C is a parameter.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 17 January 2015\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of evaluation points.\n%\n% Input, real X(N), Y(N), the coordinates of the evaluation points.\n%\n% Input, real C, a parameter, typically between 0 and 2 * PI.\n%\n% Output, real U(N), V(N), the velocity components.\n%\n u = zeros ( n, 1 );\n v = zeros ( n, 1 );\n\n u = 10.0 * ( 1.0 - cos ( c * pi * x ) ) ...\n .* ( 1.0 - x ).^2 ...\n .* ( ...\n c * pi * sin ( c * pi * y ) .* ( 1.0 - y ).^2 ...\n - ( 1.0 - cos ( c * pi * y ) ) ...\n .* 2.0 .* ( 1.0 - y ) ...\n );\n\n v = - 10.0 * ( 1.0 - cos ( c * pi * y ) ) ...\n .* ( 1.0 - y ).^2 ...\n .* ( ...\n c * pi * sin ( c * pi * x ) .* ( 1.0 - x ).^2 ...\n - ( 1.0 - cos ( c * pi * x ) ) ...\n .* 2.0 .* ( 1.0 - x ) ...\n );\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/spiral_data/uv_spiral.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.949669363129097, "lm_q2_score": 0.863391602943619, "lm_q1q2_score": 0.8199365536984768}} {"text": "function [RM,RN] = radius(lat)\n% radius: calculates meridian and normal radii of curvature.\n%\n% INPUT\n% lat, Nx1 latitude (rad).\n%\n% OUTPUT\n% RM, Nx1 meridian radius of curvature (North-South)(m).\n% RN, Nx1 normal radius of curvature (East-West) (m).\n%\n% Copyright (C) 2014, Rodrigo Gonzalez, all rights reserved.\n%\n% This file is part of NaveGo, an open-source MATLAB toolbox for\n% simulation of integrated navigation systems.\n%\n% NaveGo is free software: you can redistribute it and/or modify\n% it under the terms of the GNU Lesser General Public License (LGPL)\n% version 3 as published by the Free Software Foundation.\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 Lesser General Public License for more details.\n%\n% You should have received a copy of the GNU Lesser General Public\n% License along with this program. If not, see\n% .\n%\n% References:\n%\n%\tTitterton, D.H. and Weston, J.L. (2004). Strapdown\n% Inertial Navigation Technology (2nd Ed.). Institution\n% of Engineering and Technology, USA. Eq. 2.6 and 2.7.\n%\n% \tGroves, P. (2008). Principles of GNSS, Inertial, and\n% Multisensor Integrated Navigation Systems. Artech House, UK.\n% Eq. 2.65 and 2.66.\n%\n% \tR. Gonzalez, J. Giribet, and H. Patiño. An approach to\n% benchmarking of loosely coupled low-cost navigation systems,\n% Mathematical and Computer Modelling of Dynamical Systems, vol. 21,\n% issue 3, pp. 272-287, 2015. Eq. 11.\n%\n% Version: 006\n% Date: 2021/03/19\n% Author: Rodrigo Gonzalez \n% URL: https://github.com/rodralez/navego\n\na = 6378137.0; % WGS84 Equatorial radius in meters\ne = 0.0818191908425; % WGS84 eccentricity\n\ne2 = e^2;\nden = 1 - e2 .* (sin(lat)).^2;\n\n% Meridian radius of curvature: radius of curvature for North-South motion.\nRM = a .* (1-e2) ./ (den).^(3/2);\n\n% Normal radius of curvature: radius of curvature for East-West motion.\n% AKA transverse radius.\nRN = a ./ sqrt(den);\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/ins/radius.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8723473862936942, "lm_q1q2_score": 0.8199309540632551}} {"text": "function diameter = polygon_diameter_2d ( n, v )\n\n%*****************************************************************************80\n%\n%% POLYGON_DIAMETER_2D computes the diameter of a polygon in 2D.\n%\n% Discussion:\n%\n% The diameter of a polygon is the maximum distance between any\n% two points on the polygon. It is guaranteed that this maximum\n% distance occurs between two vertices of the polygon. It is\n% sufficient to check the distance between all pairs of vertices.\n% This is an N^2 algorithm. There is an algorithm by Shamos which\n% can compute this quantity in order N time instead.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 February 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of vertices of the polygon.\n%\n% Input, real V(2,N), the vertices.\n%\n% Output, real DIAMETER, the diameter of the polygon.\n%\n diameter = 0.0;\n\n for i = 1 : n\n\n for j = i + 1 : n\n diameter = max ( diameter, ...\n sqrt ( ( v(1,i) - v(1,j) ).^2 + ( v(2,i) - v(2,j) ).^2 ) );\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/geometry/polygon_diameter_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.872347369700144, "lm_q1q2_score": 0.819930941403292}} {"text": "function [ w, t ] = circle_rule ( nt )\n\n%*****************************************************************************80\n%\n%% CIRCLE_RULE computes a quadrature rule for the unit circle.\n%\n% Discussion:\n%\n% The unit circle is the region:\n%\n% x * x + y * y = 1.\n%\n% The integral I(f) is then approximated by\n%\n% Q(f) = 2 * pi * sum ( 1 <= i <= NT ) W(i) * F ( cos(T(i)), sin(T(i)) ).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 06 April 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NT, the number of angles to use.\n%\n% Output, real W(NT), the weights for the rule.\n%\n% Output, real T(NT), the angles for the rule.\n%\n w(1:nt) = 1.0 / nt;\n for it = 1 : nt\n t(it) = 2.0 * pi * ( it - 1 ) / nt;\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/circle_rule/circle_rule.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951607140232, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.8199100563772138}} {"text": "function [axis, theta] = rotation3dAxisAndAngle(mat)\n%ROTATION3DAXISANDANGLE Determine axis and angle of a 3D rotation matrix.\n%\n% [AXIS, ANGLE] = rotation3dAxisAndAngle(MAT)\n% Where MAT is a 4-by-4 matrix representing a rotation, computes the\n% rotation axis (containing the points that remain invariant under the\n% rotation), and the rotation angle around that axis.\n% AXIS has the format [DX DY DZ], constrained to unity, and ANGLE is the\n% rotation angle in radians.\n%\n% Note: this method use eigen vector extraction. It would be more precise\n% to use quaternions, see:\n% http://www.mathworks.cn/matlabcentral/newsreader/view_thread/160945\n%\n% \n% Example\n% origin = [1 2 3];\n% direction = [4 5 6];\n% line = [origin direction];\n% angle = pi/3;\n% rot = createRotation3dLineAngle(line, angle);\n% [axis angle2] = rotation3dAxisAndAngle(rot);\n% angle2\n% angle2 =\n% 1.0472\n%\n% See also\n% transforms3d, vectors3d, angles3d, eulerAnglesToRotation3d\n%\n\n% ------\n% Author: David Legland\n% e-mail: david.legland@inra.fr\n% Created: 2010-08-11, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2010 INRA - Cepia Software Platform.\n\n% extract the linear part of the rotation matrix\nA = mat(1:3, 1:3);\n\n% extract eigen values and eigen vectors\n[V, D] = eig(A - eye(3));\n\n% we need the eigen vector corresponding to eigenvalue==1\n[dummy, ind] = min(abs(diag(D)-1)); %#ok\n\n% extract corresponding eigen vector\nvector = V(:, ind)';\n\n% compute rotation angle\nt = [A(3,2)-A(2,3) , A(1,3)-A(3,1) , A(2,1)-A(1,2)];\ntheta = atan2(dot(t, vector), trace(A)-1);\n\n% If angle is negative, invert both angle and vector direction\nif theta<0\n theta = -theta; \n vector = -vector; \nend\n\n% try to get a point on the line\n% seems to work, but not sure about stability\n[V, D] = eig(mat-eye(4)); %#ok\norigin = V(1:3,4)'/V(4, 4);\n\n% create line corresponding to rotation axis\naxis = [origin vector];\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/z_geom3d/geom3d/rotation3dAxisAndAngle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.8774767746654976, "lm_q1q2_score": 0.8199100502833214}} {"text": "function k = pascal_to_i4 ( i, j )\n\n%*****************************************************************************80\n%\n%% PASCAL_TO_I4 converts Pacal triangle coordinates to a linear index.\n%\n% Discussion:\n%\n% We describe the grid points in a Pascal triangle in two ways:\n%\n% As a linear index K:\n%\n% 1\n% 2 3\n% 4 5 6\n% 7 8 9 10\n%\n% As elements (I,J) of Pascal's triangle:\n%\n% 0,0\n% 1,0 0,1\n% 2,0 1,1 0,2\n% 3,0 2,1 1,2 0,3\n%\n% Example:\n%\n% K I J\n%\n% 1 0 0\n% 2 1 0\n% 3 0 1\n% 4 2 0\n% 5 1 1\n% 6 0 2\n% 7 3 0\n% 8 2 1\n% 9 1 2\n% 10 0 3\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 13 April 2015\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer I, J, the row and column indices. I and J must\n% be nonnegative.\n%\n% Output, integer K, the linear index of the (I,J) element.\n%\n if ( i < 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PASCAL_TO_I4 - Fatal error!\\n' );\n fprintf ( 1, ' I < 0.\\n' );\n fprintf ( 1, ' I = %d\\n', i );\n error ( 'PASCAL_TO_I4 - Fatal error!' );\n elseif ( j < 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PASCAL_TO_I4 - Fatal error!\\n' );\n fprintf ( 1, ' J < 0.\\n' );\n fprintf ( 1, ' J = %d\\n', j );\n error ( 'PASCAL_TO_I4 - Fatal error!' );\n end\n\n d = i + j;\n\n k = ( d * ( d + 1 ) ) / 2 + j + 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/i4lib/pascal_to_i4.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.8872046026642944, "lm_q1q2_score": 0.8199028724925196}} {"text": "function integral = ball01_monomial_integral ( e )\n\n%*****************************************************************************80\n%\n%% BALL01_MONOMIAL_INTEGRAL returns monomial integrals in the unit ball.\n%\n% Discussion:\n%\n% The integration region is \n%\n% X^2 + Y^2 + Z^2 <= 1.\n%\n% The monomial is F(X,Y,Z) = X^E(1) * Y^E(2) * Z^E(3).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 02 January 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Gerald Folland,\n% How to Integrate a Polynomial Over a Sphere,\n% American Mathematical Monthly,\n% Volume 108, Number 5, May 2001, pages 446-448.\n%\n% Parameters:\n%\n% Input, integer E(3), the exponents of X, Y and Z in the \n% monomial. Each exponent must be nonnegative.\n%\n% Output, real INTEGRAL, the integral.\n%\n if ( any ( e(1:3) < 0 ) )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BALL01_MONOMIAL_INTEGRAL - Fatal error!\\n' );\n fprintf ( 1, ' All exponents must be nonnegative.\\n' );\n error ( 'BALL01_MONOMIAL_INTEGRAL - Fatal error!' );\n end\n%\n% Integrate over the surface.\n%\n if ( all ( e(1:3) == 0 ) )\n\n integral = 2.0 * sqrt ( pi ^ 3 ) / gamma ( 1.5 );\n\n elseif ( any ( mod ( e(1:3), 2 ) == 1 ) )\n\n integral = 0.0;\n\n else\n\n integral = 2.0;\n\n for i = 1 : 3\n integral = integral * gamma ( 0.5 * ( e(i) + 1 ) );\n end\n\n integral = integral / gamma ( 0.5 * ( sum ( e(1:3) + 1 ) ) );\n\n end\n%\n% The surface integral is now adjusted to give the volume integral.\n%\n r = 1.0;\n s = sum ( e(1:3) ) + 3;\n\n integral = integral * r ^ s / 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/ball_monte_carlo/ball01_monomial_integral.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8872045922259088, "lm_q1q2_score": 0.8199028665531618}} {"text": "%%\n% Author: Yash Bansod \n%\n% GitHub: \n%\n% Demonstrates the calculation of Jacobian for a 3DOF 2D Planar Robot\n\n\n%% Clear the environment and the command line\nclear;\nclc;\nclose all;\n\n%% Calculation of Jacobian for 3DOF 2D Planar Robot\nsyms t1 t2 t3 L1 L2 L3\norgX = 0;\norgY = 0;\n\nX(1)= orgX+ L1*cos(t1);\nY(1)= orgY+ L1*sin(t1);\nX(2)= X(1)+ L2*cos(t1 + t2);\nY(2)= Y(1)+ L2*sin(t1 + t2);\nX(3)= X(2)+ L3*cos(t1 + t2 + t3);\nY(3)= Y(2)+ L3*sin(t1 + t2 + t3);\n\nJacob = [diff(X(3),t1) , diff(X(3), t2) , diff(X(3), t3);\n diff(Y(3), t1), diff(Y(3), t2) , diff(Y(3), t3)]", "meta": {"author": "YashBansod", "repo": "Robotics-Planning-Dynamics-and-Control", "sha": "ee8984dd5f090b803c87ac9fdf4f9be625787b2b", "save_path": "github-repos/MATLAB/YashBansod-Robotics-Planning-Dynamics-and-Control", "path": "github-repos/MATLAB/YashBansod-Robotics-Planning-Dynamics-and-Control/Robotics-Planning-Dynamics-and-Control-ee8984dd5f090b803c87ac9fdf4f9be625787b2b/4_Planar_3DOF_Manipulator_Trajectory/PLANAR_JACOB_3DOF.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.971563964485063, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.8198980752618225}} {"text": "function fx = p06_fx ( x )\n\n%*****************************************************************************80\n%\n%% P06_FX evaluates exp ( x ) - 2 - 1 / ( 10 * x )^2 + 2 / ( 100 * x )^3.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 July 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X(*), the point at which F is to be evaluated.\n%\n% Output, real FX(*), the value of the function at X.\n%\n fx = exp ( x ) - 2.0 - 1.0 ./ ( 10.0 * x ).^2 + 2.0 ./ ( 100.0 * x ).^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_zero/p06_fx.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.8791467801752451, "lm_q1q2_score": 0.8197633208479019}} {"text": "%% RATE OF CONVERGENCE OF LINEAR ELEMENT FOR POISSON EQUATION\n%\n% This example is to show the rate of convergence of linear finite element\n% approximation of the Poisson equation on the unit cube with the\n% following boundary conditions:\n%\n% - Non-empty Dirichlet boundary condition.\n% - Pure Neumann boundary condition.\n% - Robin boundary condition.\n%\n% The basis, data structure and numerical test is summarized in Poisson3femrate.\n%\n% See also Poisson3P2femrate, Poissonfemrate\n%\n% Copyright (C) Long Chen. See COPYRIGHT.txt for details.\n\nclear variables\n\n%% Setting\n[node,elem] = cubemesh([0,1,0,1,0,1],0.5); \nmesh = struct('node',node,'elem',elem);\noption.L0 = 1;\noption.maxIt = 4;\noption.elemType = 'P1';\noption.printlevel = 1;\noption.plotflag = 1;\n\n%% Non-empty Dirichlet boundary condition.\nfprintf('Mixed boundary conditions. \\n'); \npde = sincosdata3;\nmesh.bdFlag = setboundary3(node,elem,'Dirichlet','~(x==0)','Neumann','x==0');\n% bdFlag = setboundary3(node,elem,'Dirichlet');\nfemPoisson3(mesh,pde,option);\n\n%% Pure Neumann boundary condition.\nfprintf('Pure Neumann boundary condition. \\n');\noption.plotflag = 0;\npde = sincosdata3Neumann;\nmesh.bdFlag = setboundary3(node,elem,'Neumann');\nfemPoisson3(mesh,pde,option);\n\n%% Robin boundary condition.\nfprintf('Robin boundary condition. \\n');\npde = sincosRobindata3;\nmesh.bdFlag = setboundary3(node,elem,'Robin');\nfemPoisson3(mesh,pde,option);\n\n%% Conclusion\n%\n% The optimal rate of convergence of the H1-norm (1st order) and L2-norm\n% (2nd order) is observed. The 2nd order convergent rate between two\n% discrete functions ||DuI-Duh|| is known as superconvergence.\n%\n% MGCG converges uniformly in all cases.\n%\n% Note that for Neumann and Robin boundary condition, the order of the error in the\n% maximum norm is not close to 2. Neumann problem is around 1.5 and Robin\n% is near 1.3. ", "meta": {"author": "lyc102", "repo": "ifem", "sha": "29f31c812001ca8d93dad08e67208ca60e8716d4", "save_path": "github-repos/MATLAB/lyc102-ifem", "path": "github-repos/MATLAB/lyc102-ifem/ifem-29f31c812001ca8d93dad08e67208ca60e8716d4/example/fem/Poisson/Poisson3femrate.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.8947894534772125, "lm_q1q2_score": 0.8197252184194792}} {"text": "%% Optimizing the operation of a Hydroelectric Dam\n%\n% This demo maximizes the revenue generated from a hydroelectric dam using\n% Quadratic Programming. We compute the optimal flow rate to the turbine\n% as well as the optimal spill flow rate.\n%\n% This problem is constrained such that:\n%\n% 1) 0 < Turbine Flow < 25,000 CFS\n% 2) 0 < Spill Flow\n% 3) Max change in Turbine and Spill Flow < 500 CFS\n% 4) Combined Turbine and Spill Flow > 1000 CFS\n% 5) 50000 < Reservoir Storage < 100000 Acre-Feet\n% 6) The final reservoir level must equal the initial level (90000 AF)\n%\n% Two solvers are used to solve this problem: FMINCON and QUADPROG\n% FMINCON is used first as it takes less time to set-up the problem for \n% ths solver. Supplying the Gradient and Hessian to the FMINCON algorithm\n% significantly speeds up the solution of the problem. \n% QUADPROG ionterior-point-convex is used third to provide a faster \n% algorithm for solving this type of problem. This solver is also better \n% suited for handling a larger version of the same problem.\n%\n% Copyright (c) 2012, MathWorks, Inc.\n\n%% 1 - Load data\n% Two variables are loaded from data set:\n% inFlow - flow rate into the reservoir measured hourly (CFS)\n% price - price of electricity measured hourly ($/MWh)\nload('FlowAndPriceData.mat');\n\n%% 2 - Define Starting Point and Constants\n% We wish to find the vector x of optimal decision variables. \n% For this problem:\n% x = [turbineFlow(1) ... turbineFlow(N) spillFlow(1) ... spillFlow(N)]\n\n% Our initial starting point is turbineFlow = inFlow and spillFlow = 0\nx0 = [inFlow; zeros(size(inFlow))];\n\nstor0 = 90000; % initial vol. of water stored in the reservoir (Acre-Feet)\n\nk1 = 0.00003; % K-factor coefficient\nk2 = 9; % K-factor offset\n\nMW2kW = 1000; % MW to kW\nC2A = 1.98347/24; % Convert from CFS to AF/HR\n\nC = [C2A k1 k2 MW2kW]; % Vector of constants\n\nN = length(inFlow);\n\n%% 3 - Define Linear Inequality Constraints and Bounds\nDefineConstraints;\n\n%% 4 - Objective function\n% Use symbolic math for creating the objective function and then convert\n% into a MATLAB function that can be evaluated.\n%% 4.1 - Derive Objective Function using Symbolic Math\n% First define the decision variables as X, which is a vector consisting\n% of [TurbineFlow, SpillFlow] and all the parameters as symbolic objects\nX = sym('x',[2*N,1]); % turbine flow and spill flow\nF = sym('F',[N,1]); % flow into the reservoir\nP = sym('P',[N,1]); % price\ns0 = sym('s0'); % initial storage\nc = sym({'c1','c2','c3','c4'}.','r'); % constants\n\n%%\n% Total out flow equation\nTotFlow = X(1:N)+X(N+1:end);\n\n%%\n% Storage Equations\nS = cell(N,1);\nS{1} = s0 + c(1)*(F(1)-TotFlow(1));\n\nfor ii = 2:N\n S{ii} = S{ii-1} + c(1)*(F(ii)-TotFlow(ii));\nend\n\n%%\n% K factor equation\nk = c(2)*([s0; S(1:end-1)]+ S)/2+c(3);\n\n% MWh equation\nMWh = k.*X(1:N)/c(4);\n\n%%\n% Revenue equation\nR = P.*MWh;\n\n%%\n% Total Revenue (Minus sign changes from maximization to minimization)\ntotR = -sum(R);\n\n%% 4.2 - Create Function File that can be Evaluated in MATLAB\n% Create a function that when evaluated returns the value at a point\n\n% Perform substitutions so that X is the only remaining variable \ntotR = subs(totR,[c;s0;P;F],[C';stor0;price;inFlow]);\n\n% Generate a MATLAB file from the equation\nmatlabFunction(totR,'vars',{X},'file','objFcn');\n\n%% 5 - Optimize with FMINCON\noptions = optimset('MaxFunEvals',Inf,'MaxIter',5000,...\n 'Algorithm','interior-point','Display','iter');\n\ntic\n[x1, fval1] = fmincon(@objFcn,x0,A,b,Aeq,beq,LB,UB,[],options);\ntoc\n\n% Visualize Results\nplotResults(price, x1, N);\n\n%% 6 - Optimize with FMINCON with supplied Gradient and Hessian\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Let's see if we can speed up the optimization by supplying the gradient\n% and Hessian. Passing these to the algorithm allows it to make more \n% accurate decisions because it no longer has to approximate the gradient\n% and hessian (approximation also takes longer as it requires many \n% objective function evaluations).\n\n%% 6.1 - Gradient\n% Use the GRADIENT function from Symbolic Math to calculate the gradient\ngradObj = gradient(totR,X);\n\n% Create a function that when evaluated returns the gradient at a point\nmatlabFunction(gradObj,'vars',{X},'file','grad');\n\n% The optimization routine expects two return arguments for a user-supplied\n% gradient. The first argument is the value of the objective function and\n% the second argument is the gradient. The DEAL function is used to return\n% multiple output arguments through a function handle.\nValAndGrad = @(x) deal(objFcn(x),grad(x));\n\n%% 6.2 - Hessian\n% Use the HESSIAN function from Symbolic Math to calculate the Hessian\nhessObj = hessian(totR,X);\n\n% Create a function that when evaluated returns the Hessian at a point\nmatlabFunction(hessObj,'vars',{X},'file','Hess');\n\n% The Hessian function has two input arguments (the current point and the\n% Lagrange Multipliers) and returns the value of the Hessian at the current\n% point.\nhfcn = @(x,lambda) Hess(x);\n\n%% 6.3 - Optimize\noptions = optimset('Disp','iter','Algorithm','interior-point',...\n 'MaxFunEvals',500,'MaxIter',5000,...\n 'GradObj','on','Hessian','user-supplied',...\n 'HessFcn',hfcn);\n\ntic\n[x2,fval2] = fmincon(ValAndGrad,x0,A,b,Aeq,beq,LB,UB,[],options);\ntoc\n\n% Visualize Results\nplotResults(price, x2, N);\n\n%% 7 - Optimize using the QUADPROG Solver\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% QUADPROG minimizes functions of the type (1/2) * x' * H * x + f' * x\n% First perform some substitutions into the revenue equation\nRsub = subs(R,[c;s0;P;F],[C';stor0;price;inFlow]);\n\n% Total revenue (minus sign to flip maximization to minimization)\nRtot = -sum(Rsub);\n\n%% 7.2 - Calculate and evaluate the linear component\nfsym = gradient(Rtot,X);\nf = double(subs(fsym,X,zeros(size(X))));\n\n%% 7.1 - Calculate and evaluate the quadratic matrix\nH = 0.5.*double(hessian(Rtot,X));\n\n%% 7.3 - Optimize\nqpoptions = optimset('Algorithm','interior-point-convex','Disp','iter');\n\ntic\n[x3,fval3] = quadprog(H,f,A,b,Aeq,beq,LB,UB,[],qpoptions);\ntoc\n\n% Visualize Results\nplotResults(price, x3, 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/35856-optimization-in-matlab-an-introduction-to-quadratic-programming/HydroelectricDamOptimization/HydroelectricDamOptimization.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086368, "lm_q2_score": 0.8947894541786198, "lm_q1q2_score": 0.8197252170126269}} {"text": "function TDD = divdiff(X, Y)\n%\n% TDD = divdiff(X, Y)\n%\n% DIVDIFF\n% Newton's Method for Divided Differences.\n%\n% The following formula is solved:\n% Pn(x) = f(x0) + f[x0,x1](x-x0) + f[x0,x1,x2](x-x0)(x-x1) + ...\n% + f[x0,x1,..,xn](x-x0)(x-x1)..(x-x[n-1])\n% where f[x0,x1] = (f(x1-f(x0))/(x1-x0)\n% f[x0,x1,..,xn] = (f[x1,..,xn]-f[x0,..,x_[n-1]])/(xn-x0)\n%\n% NOTE: f^(n+1)(csi)/(n+1)! aprox. = f[x0,x1,..,xn,x_[n+1]]\n%\n% Input::\n%\tX = [ x0 x1 .. xn ] - object vector\n%\tY = [ y0 y1 .. yn ] - image vector\n%\n% Output:\n% TDD - table of divided differences\n%\n% Example:\n% TDD = divdiff( [ 1.35 1.37 1.40 1.45 ], [ .1303 .1367 .1461 .1614 ])\n%\n% Author:\tTashi Ravach\n% Version:\t1.0\n% Date: 22/05/2006\n%\n\n if nargin ~= 2\n error('divdiff: invalid input parameters'); \n end\n\n [ p, m ] = size(X); % m points, polynomial order <= m-1\n if p ~= 1 || p ~=size(Y, 1) || m ~= size(Y, 2)\n error('divdiff: input vectors must have the same dimension'); \n end\n\n TDD = zeros(m, m);\n TDD(:, 1) = Y';\n for j = 2 : m\n for i = 1 : (m - j + 1)\n TDD(i,j) = (TDD(i + 1, j - 1) - TDD(i, j - 1)) / (X(i + j - 1) - X(i));\n end\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/28215-newtons-method-for-divided-differences/divdiff.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475794701961, "lm_q2_score": 0.8688267779364222, "lm_q1q2_score": 0.8196056379452135}} {"text": "function [detjacobian,invjacobian]=Jacobian(nnel,dhdr,dhds,xcoord,ycoord)\n\n%------------------------------------------------------------------------\n% Purpose:\n% determine the Jacobian for two-dimensional mapping\n%\n% Synopsis:\n% [detjacobian,invjacobian]=Jacobian(nnel,dhdr,dhds,xcoord,ycoord) \n%\n% Variable Description:\n% jacobian - Jacobian for one-dimension\n% nnel - number of nodes per element \n% dhdr - derivative of shape functions w.r.t. natural coordinate r\n% dhds - derivative of shape functions w.r.t. natural coordinate s\n% xcoord - x axis coordinate values of nodes\n% ycoord - y axis coordinate values of nodes\n%------------------------------------------------------------------------\n\n jacobian=zeros(2,2);\n\n for i=1:nnel\n jacobian(1,1) = jacobian(1,1)+dhdr(i)*xcoord(i);\n jacobian(1,2) = jacobian(1,2)+dhdr(i)*ycoord(i);\n jacobian(2,1) = jacobian(2,1)+dhds(i)*xcoord(i);\n jacobian(2,2) = jacobian(2,2)+dhds(i)*ycoord(i);\n end\n\n detjacobian = det(jacobian) ; % Determinant of Jacobian matrix\n invjacobian = inv(jacobian) ; % Inverse of Jacobian matrix", "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/32029-plate-bending/Plate Bending/Jacobian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422186079557, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.8194453690059017}} {"text": "function KM = computeKernelMatrix(P1, P2, kType, kParam)\n%COMPUTEKERNELMATRIX computes the kernel matrix between two sets of patterns\n%\n% KM = computeKernelMatrix(P1, P2, kType, kParam) computes kernel matrix\n% KM between sets of patterns P1 and P2. kType is the type of the kernel\n% function (Gauss, Linear, Quickrbf, Poly, or Sigmoid). KPARAM is the\n% kernel parameter, for instance the width of the Gaussian kernel.\n%\n% Function inputs:\n% patterns1, patterns2 - Two matrixes of patterns (train and test, or train and train)\n% kernelType - Kernel function choice. Can be Gauss, Linear, Quickrbf, Poly, or Sigmoid.\n% kernelMatrix - The kernel matrix\n%\n% This file is part of ORCA: https://github.com/ayrna/orca\n% Original authors: Pedro Antonio Gutiérrez, María Pérez Ortiz, Javier Sánchez Monedero\n% Citation: If you use this code, please cite the associated paper http://www.uco.es/grupos/ayrna/orreview\n% Copyright:\n% This software is released under the The GNU General Public License v3.0 licence\n% available at http://www.gnu.org/licenses/gpl-3.0.html\n%\nNf1 = size(P1, 2);\nNf2 = size(P2, 2);\nKM = zeros(Nf1, Nf2);\n\nswitch upper(kType)\n case {'GAUSS','GAUSSIAN','RBF'}\n \n for i = 1:Nf2\n KM(:,i) = exp(-kParam*sum((P1-P2(:,i)*ones(1,Nf1)).^2)');\n \n end\n \n case {'QUICKRBF'}\n d = pdistalt(P1,P2,'euclidean');\n KM = exp(-kParam*d.^2);\n \n case {'POLYNOMIAL', 'POLY', 'LINEAR'}\n if strcmpi(kType, 'LINEAR')\n kParam = 1;\n bias = 0;\n else\n bias = 1;\n end\n KM = ((P1' * P2 + bias)/size(P1,1)).^kParam;\n \n case 'SIGMOID'\n \n if (length(kParam) ~= 2)\n error('This kernel needs two parameters to operate!')\n end\n \n KM = zeros(Nf1, Nf2);\n for i = 1:Nf2\n KM(:,i) = tanh(P1'*P2(:,i)*kParam(1)+kParam(2));\n end\n \n otherwise\n error('Unknown kernel. Can be Gauss, Linear, Quickrbf, Poly, or Sigmoid.')\n \nend\n", "meta": {"author": "ayrna", "repo": "orca", "sha": "eaa629e687d04d73628782e16e92d330acb43faf", "save_path": "github-repos/MATLAB/ayrna-orca", "path": "github-repos/MATLAB/ayrna-orca/orca-eaa629e687d04d73628782e16e92d330acb43faf/src/Algorithms/computeKernelMatrix.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191322715435, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.8194422852228374}} {"text": "function X = lyap(A, B, C)\n%LYAP Solve continuous-time Lyapunov equations.\n%\n% X = LYAP(A,C) solves the special form of the Lyapunov matrix \n% equation:\n%\n% A*X + X*A' = -C\n%\n% X = LYAP(A,B,C) solves the general form of the Lyapunov matrix\n% equation (also called Sylvester equation):\n%\n% A*X + X*B = -C\n%\n% See also DLYAP.\n\n%\tS.N. Bangert 1-10-86\n%\tCopyright (c) 1986-98 by The MathWorks, Inc.\n%\t$Revision: 1.4 $ $Date: 1997/12/01 22:11:32 $\n%\tLast revised JNL 3-24-88, AFP 9-3-95\n\nni = nargin;\n\nif ni==2,\n C = B;\n B = A';\nend\n\n[ma,na] = size(A);\n[mb,nb] = size(B);\n[mc,nc] = size(C);\n\n% A and B must be square and C must have the rows of A and columns of B\nif (ma ~= na) | (mb ~= nb) | (mc ~= ma) | (nc ~= mb)\n error('Dimensions do not agree.')\nelseif ma==0,\n X = [];\n return\nend\n\n% Perform schur decomposition on A (and convert to complex form)\n[ua,ta] = schur(A);\n[ua,ta] = rsf2csf(ua,ta);\nif ni==2,\n % Schur decomposition of A' can be calculated from that of A.\n j = ma:-1:1;\n ub = ua(:,j);\n tb = ta(j,j)';\nelse\n % Perform schur decomposition on B (and convert to complex form)\n [ub,tb] = schur(B);\n [ub,tb] = rsf2csf(ub,tb);\nend\n\n% Check all combinations of ta(i,i)+tb(j,j) for zero\np1 = diag(ta).'; % Use .' instead of ' in case A and B are not real\np1 = p1(ones(mb,1),:);\np2 = diag(tb);\np2 = p2(:,ones(ma,1));\nsum = abs(p1) + abs(p2);\nif any(any(sum == 0)) | any(any(abs(p1 + p2) < 1000*eps*sum))\n error('Solution does not exist or is not unique.');\nend\n\n% Transform C\nucu = -ua'*C*ub;\n\n% Solve for first column of transformed solution\ny = zeros(ma,mb);\nema = eye(ma);\ny(:,1) = (ta+ema*tb(1,1))\\ucu(:,1);\n\n% Solve for remaining columns of transformed solution\nfor k=2:mb,\n km1 = 1:(k-1);\n y(:,k) = (ta+ema*tb(k,k))\\(ucu(:,k)-y(:,km1)*tb(km1,k));\nend\n\n% Find untransformed solution \nX = ua*y*ub';\n\n% Ignore complex part if real inputs (better be small)\nif isreal(A) & isreal(B) & isreal(C),\n X = real(X);\nend\n\n% Force X to be symmetric if ni==2 and C is symmetric\nif (ni==2) & isequal(C,C'),\n X = (X+X')/2;\nend\n\n% end lyap\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/3680-automatic-spectral-analysis/AutomaticSpectra/Vectors/lyap.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191271831559, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.8194422773846955}} {"text": "function DeriveDynamicsDP(P)\n\n%FUNCTION:\n% This function is used to derive the analytic equations of motion for a\n% forced double pendulum. This also does the kimenatics and energy\n% calculations. \n\n\n%State Naming Conventions:\n% th = absolute angle of the first link measured wrt the positive horizontal axis (i)\n% phi = absolute angle of the second link measured wrt the positive horizontal axis (i)\n% Dth = first time derivative of th\n% Dphi = first time derivative of phi\n\n%NOTE: It might be faster to use the jacobian command to find the symbolic\n%coeffieints of the mass matrix and then invert the system, rather than\n%symbolically inverting the matrix.\n%\n\n% Define the angles and derivatives\n th = sym('th'); \n Dth = sym('Dth');\n DDth = sym('DDth');\n\n phi = sym('phi');\n Dphi = sym('Dphi');\n DDphi = sym('DDphi');\n \n% Define the scalar parameters\n g = sym('g'); %gravity\n L = sym('L'); %Lenght of each link\n m1 = sym('m1'); %mass of the link\n m2 = sym('m2'); %mass of the link\n \n% Known Vectors\n F1_x = sym('F1_x');\n F1_y = sym('F1_y');\n F1 = [F1_x;F1_y]; %External force at CoM of first link\n\n F2_x = sym('F2_x');\n F2_y = sym('F2_y');\n F2 = [F2_x;F2_y]; %External force at CoM of 2nd link\n\n M1 = sym('M1'); %Input torque on link on\n M2 = sym('M2'); %Input torque between links 1 and 2\n\n% UNIT VECTORS:\n i = [1;0];\n j = [0;1];\n\n a1 = cos(th)*i + sin(th)*j; %The direction along the first link \n b1 = -sin(th)*i + cos(th)*j;\n Da1 = Dth*b1;\n Db1 = -Dth*a1;\n DDa1 = DDth*b1 + Dth*Db1;\n DDb1 = -DDth*a1 -Dth*Da1;\n\n a2 = cos(phi)*i + sin(phi)*j; %The direction along the second link \n b2 = -sin(phi)*i + cos(phi)*j;\n Da2 = Dphi*b2;\n Db2 = -Dphi*a2;\n DDa2 = DDphi*b2 + Dphi*Db2;\n DDb2 = -DDphi*a2 -Dphi*Da2;\n \n%Weights\n W1 = -m1*g*j; %weight of the first link\n W2 = -m2*g*j; %weight of the second link\n\n%Kinematic vectors \n r_P1_O = L*a1; %Position of the point mass 1\n v_P1_O = L*Da1;\n a_P1_O = L*DDa1;\n\n r_P2_O = L*a1 + L*a2; %Position of point mass 2\n v_P2_O = L*Da1 + L*Da2;\n a_P2_O = L*DDa1 + L*DDa2;\n \n r_P2_P1 = L*a2; %Relative position of the tip with respect to the mid joint\n \n \n%Momentum balance for both links about the origin\n % = Moment from weight 1 + moment from weight 2 + Control torque 1\n Sum_M_O = Cross(r_P1_O,F1+W1) + Cross(r_P2_O,F2+W2) + M1;\n % = translation mass 1 + translation mass 2\n Sum_DH_O = Cross(r_P1_O,m1*a_P1_O) + Cross(r_P2_O,m2*a_P2_O);\n\n%Momentum balance for second link about central pivot\n % moment from weight 2 + control moment\n Sum_M_P1 = Cross(r_P2_P1,F2+W2) + M2;\n % translation mass 2 + \n Sum_DH_P1 = Cross(r_P2_P1,m2*a_P2_O);\n\n%Simplify\n AMB_1 = simplify(Sum_M_O - Sum_DH_O);\n AMB_2 = simplify(Sum_M_P1 - Sum_DH_P1);\n\n% Solve the system of equations:\n Soln = solve( AMB_1, ... %AMB for system\n AMB_2, ... %AMB for second link\n DDth,... %acceleration of first joint\n DDphi ); %acceleration of second joint\n\n Soln.DDth = simplify(Soln.DDth); %Simplify the result \n Soln.DDphi = simplify(Soln.DDphi); %Simplify the result \n\n%Write the results to a file -- these are scripts! \nif P.misc.CppFlag\n WriteDynamicsFile_Cpp %Call a script that write the dynamics to a file\nelse\n WriteDynamicsFile_Matlab; %Call a script that write the dynamics to a file\nend\nWriteKinematicsFile_Matlab; %Call a script that writes the equations for kinetics\n\n\n \nend", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/DoublePendulum/DeriveDynamicsDP.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191259110588, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.8194422762935312}} {"text": "function [xi,w]=firstOrderTriangleCubPoints()\n%%FIRSTORDERTRIANGLECUBPOINTS Obtain first-order cubature points for\n% integration over a triangle in 2D. The points and weights are for the\n% triangle with vertices (1,0), (0,1), (0,0), but can be transformed to\n% any triangle using transformSimplexTriPoints.\n%\n%INPUTS: None\n%\n%OUTPUTS: xi A 2XnumCubPoints set of points for the standard triangle.\n% w A 1XnumCubPoints set of cubature weights. This sums to the\n% volume of the triangle (1/2).\n%\n%This function implements the points given in [1] (3 points).\n%\n%EXAMPLE:\n%Given the vertices of the simplex, we compare a first-order moment\n%computed using these cubature points to one computed using\n%monomialIntSimplex. The results are the same within typical finite\n%precision limits.\n% [xi,w]=firstOrderTriangleCubPoints();\n% alpha=[1;0];\n% theMoment=findMomentFromSamp(alpha,xi,w)\n% intVal=monomialIntSimplex(alpha)\n%\n%REFERENCES:\n%[1] F. D. Witherden and P. E. Vincent, \"On the identification of symmetric\n% quadrature rules for finite element methods,\" Computer and Mathematics\n% with Applications, vol. 69, no. 10, pp. 1232-1241, May 2015.\n%\n%October 2022 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nM=[-0.33333333333333333333333333333333333333, -0.33333333333333333333333333333333333333, 2];\nw=M(:,3);\nxi=M(:,1:2)';\n%Transform the points to the standard triangle.\nv1=[-1,-1, 1;\n -1, 1,-1];\nv2=[1,0,0;\n 0,1,0];\n[A,d]=affineTransBetweenTriangles(v1,v2);\nxi=bsxfun(@plus,A*xi,d);\nw=w/4;\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/Numerical_Integration/Cubature_Points/Simplex/Triangles/firstOrderTriangleCubPoints.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.8887587993853654, "lm_q1q2_score": 0.8193661411663347}} {"text": "%% Structured grid\n% This is a sample code showing how to use ConstructProjector3D().\n% This example is going to setup a transformation matrix based on forth\n% order polynomials in 3D. \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;\nzMin=0;\nzMax=2*pi;\n\nnx=20;\nny=20;\nnz=20;\n\ndx=(xMax-xMin)/(nx-1);\ndy=(yMax-yMin)/(ny-1);\ndz=(zMax-zMin)/(nz-1);\n\nnPoly=2; % We gonna fit a fourth order polynomial, \n % i.e. sum_{n,m,t=0}^{n,m,t=nPoly} x^n*y^m*z^t \nnInterp=27:37;\n\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.\n% disp('- Turning the warnings off')\n% warning('OFF','MATLAB:nearlySingularMatrix');\n\n%% Generating the Source Grid\ndisp('- Generating the source grid.')\n[xn,yn,zn]=meshgrid(linspace(xMin,xMax,nx),linspace(yMin,yMax,ny),linspace(zMin,zMax,nz));\n\n%% Finding the cell centers\ndisp('- Generating the destination grid')\nxc=xn(1:ny-1,1:nx-1,1:nz-1)+dx/2;\nyc=yn(1:ny-1,1:nx-1,1:nz-1)+dy/2;\nzc=zn(1:ny-1,1:nx-1,1:nz-1)+dz/2;\n\n% figure\n% plot3(xn(:),yn(:),zn(:),'k.','MarkerSize',20);\n% hold on\n% plot3(xc(:),yc(:),zc(:),'b.','MarkerSize',20);\n% axis tight;\n% axis square;\n% title('Source Grid, black dots, & the destination grid, blue dots.', ...\n% 'FontName','Arial','FontSize',12,'FontWeight','Bold');\n\n%% Generarting some Data\ndisp('- Generating some data and interpolating')\nF1=@(x,y,z) (sqrt(x.^2+y.^2+z.^2));\nVn=F1(xn,yn,zn);\nVc_Analytic=F1(xc,yc,zc);\n\n%% Generating the interpolant\ndisp('- Generating the interpolant and testing nInterp')\nRMSE=zeros(size(nInterp));\nfor i=1:numel(nInterp)\n disp(['-- nInterp= ' num2str(nInterp(i))])\n P=ConstructProjector3D(xn(:),yn(:),zn(:),xc(:),yc(:),zc(:),nPoly,nInterp(i));\n % Interpolating\n Vc_interp=P*Vn(:);\n\n % Calculating the RMSE\n RMSE(i)=sqrt(mean( (Vc_interp-Vc_Analytic(:)).^2 ));\n disp([' RMSE= ' num2str(RMSE(i))])\nend\n%% plotting\n\nfigure\nplot(nInterp,RMSE,'b.-')\nxlabel('nInterp');\nylabel('RMSE');\naxis tight\n\ndisp('All done!')\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_nInterpEffect_3D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947101574299, "lm_q2_score": 0.867035763237924, "lm_q1q2_score": 0.819344209777148}} {"text": "function value = torus_volume_3d ( r1, r2 )\n\n%*****************************************************************************80\n%\n%% TORUS_VOLUME_3D returns the volume of a torus in 3D.\n%\n% Integration region:\n%\n% Points (X,Y,Z) such that:\n%\n% ( SQRT ( X**2 + Y**2 ) - R1 )**2 + Z**2 = R2**2.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 20 May 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R1, R2, the two radii that define the torus.\n%\n% Output, real TORUS_VOLUME_3D, the volume of the torus.\n%\n value = 2.0 * pi * pi * r1 * r2 * 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/stroud/torus_volume_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9489172615983308, "lm_q2_score": 0.863391611731321, "lm_q1q2_score": 0.8192872038910544}} {"text": "function theta = circle3dPosition(point, circle)\n%CIRCLE3DPOSITION Return the angular position of a point on a 3D circle\n%\n% POS = circle3dPosition(POINT, CIRCLE)\n% Returns angular position of point on the circle, in degrees, between 0\n% and 360.\n% with POINT: [xp yp zp]\n% and CIRCLE: [X0 Y0 Z0 R THETA PHI] or [X0 Y0 Z0 R THETA PHI PSI]\n% (THETA being the colatitude, and PHI the azimut)\n%\n% See also:\n% circles3d, circle3dOrigin, circle3dPoint\n%\n% ---------\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 21/02/2005\n%\n\n% HISTORY\n% 27/06/2007: change 3D angle convention\n% 2011-06-21 use degrees for angles\n\n\n% get center and radius\nxc = circle(:,1);\nyc = circle(:,2);\nzc = circle(:,3);\n\n% get angle of normal\ntheta = circle(:,5);\nphi = circle(:,6);\n\n% find origin of the circle\nori = circle3dOrigin(circle);\n\n% normal vector of the supporting plane (cartesian coords)\nvn = sph2cart2d([theta phi]);\n\n% create plane containing the circle\nplane = createPlane([xc yc zc], vn);\n\n% find position of point on the circle plane\npp0 = planePosition(ori, plane);\npp = planePosition(point, plane);\n\n% compute angles in the planes\ntheta0 = mod(atan2(pp0(:,2), pp0(:,1)) + 2*pi, 2*pi);\ntheta = mod(atan2(pp(:,2), pp(:,1)) + 2*pi - theta0, 2*pi);\n\n% convert to degrees\ntheta = theta * 180 / 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/geom3d/circle3dPosition.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172601537141, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.8192871976405033}} {"text": "function [varargout] = dcblock(varargin);\n%\n% DCBLOCK determines the filter coefficient a for the dc blocking/high- \n% pass filter y(t) = x(t) - x(t-1) + a*y(t-1).\n% \n% [a] = dcblock(Fc) returns the filter coefficient a for \n% normalized cut-on frequency Fc.\n%\n% [a] = dcblock(fc,fs)returns the filter coefficient a for cut-on \n% frequency fc, and sampling frequency fs, when both are given in\n% Hz.\n%\n% [aQ] = dcblock(fc,fs,B) returns the quantized filter\n% coefficient aQ when the quantization level B is given.\n%\n% dcblock(...) plots the frequency and phase response of the\n% filter.\n%\n% Note that if two parameters are passed to the function without\n% an output argument, the plot routine always interprets the\n% first as fc and the second as fs.\n%\n% SYNTAX [a] = dcblock(Fc);\n% [a] = dcblock(fc,fs);\n% [aQ] = dcblock(fc,fs,B);\n% [Fc,fc] = dcblock(a,fs);\n% dcblock(Fc)\n% dcblock(fc,fs)\n% dcblock(fc,fs,B)\n%\n% INPUT Fc Normalized frequency cut-on of the filter.\n% Fc = fc[Hz]/(fs[Hz]/2); fs/2 is the Nyquist frequency.\n% Note that 0 < Fc < 1/3;\n%\n% fc filter cut-on frequency in Hz (or other reciprocal\n% units of frequency e.g. 1/metre).\n%\n% fs sampling frequency in Hz (or other reciprocal\n% units of frequency e.g. 1/metre).\n%\n% B quantization level for fixed point processing e.g. B is\n% 16 for 16-bit operation.\n%\n% OUTPUT a filter coefficient; 0 < a < 1 for floating point\n% operation.\n%\n% aQ quantized filter coefficient a; 0 < aQ < 2^(B-1) - 1.\n% The quantization level is set by B which is assumed to \n% be signed integer.\n%\n% EXAMPLES (1) Calculate the filter coefficient a when the normalized\n% frequency is 1E-5:\n%\n% >> format long % set display format \n% >> a = dcblock(1E-5) % Fc = 0.00001\n% >> a = 0.99994558749947 % filter coefficient\n%\n% (2) Calculate the normalized and true cut-on frequency when the\n% coefficient a is 0.9987 and the sampling frequency is 1MHz:\n%\n% >> [Fc,fc] = dcblock(0.9987,1E6) % a = 0.9987; fs = 1MHz\n% >> Fc = 2.3906E-004 % this output is normalized \n% >> fc = 119.5323 % this output is in Hz\n%\n% Note the difference in inputs between [Fc,fc] = dcblock(a,fs), \n% the function call [a] = dcblock(fc,fs), and its plot facility\n% dcblock(fc,fs). You can plot the filter response using \n%\n% >> dcblock(119.5323,1E6) % fc = 119.5323; fs = 1E6\n%\n% (3) Carry out filtering operation using the dc blocking filter\n% with cut-on frequency of 70Hz and sampling rate of 10kHz. \n%\n% t = -0.1:1/10000:0.1-1/10000; % set up time base\n% s = sin(2*pi*2.5*t+pi/6)+0.01*randn(size(t))+1.25;\n% x = gauspuls(t,250,0.6) + s; % noisy Gaussian test pulse\n% p = dcblock(70,10000); % get filter coefficient\n% b = [1 -1]; % set up differentiator\n% a = [1 -p]; % set up integrator\n% y = filter(b,a,x); % filter test data\n% plot(t,x,t,y) % plot results to screen\n% legend('Original','DC Filtered','location','northwest');\n%\n% The forward pass of the filter creates a distortion in the\n% Gaussian pulse. This distortion can be removed by using the \n% filtfilt form of the filter. If you now try\n%\n% y2 = filtfilt(b,a,x); % filter test data\n% plot(t,x,t,y,t,y2) % plot results to screen\n% legend('Original','DC Filtered','Undistorted','location','northwest');\n%\n% you will notice that the symmetry of the Gaussian pulse has\n% been restored.\n%\n% See also FILTER, FILTFILT, SPTOOL, FDATOOL.\n\n% Author: J M De Freitas\n% QinetiQ Ltd, Winfrith Technology Centre\n% Winfrith, Dorchester DT2 8XJ, UK. \n%\n% Email jdefreitas@qinetiq.com\n%\n% Revision 1.0\n% \n% Date 11 October 2006.\n%\n\n\n% Perform checks on input and output\nLin = nargin;\nLout = nargout;\nif Lin > 3\n error('dcblock error: Too many input arguments.');\nend\nif Lin < 1\n errror('dcblock error: No input argument used.');\nend\nif Lout > 2\n error('dcblock error: Too many output arguments.');\nend\n\n% Calculate a when Fc is given and plot response if required\nif Lin == 1\n Fc = varargin{1};\n if (Fc < 0)|(Fc > 1/3)\n error('dcblock error: Normalized cut-on frequency must be between 0 and 1/3.');\n end\n a = coef(Fc);\n if Lout == 1\n varargout{1} = a;\n elseif Lout == 0\n PlotResp(1,a);\n end\nend\n\n% Calculate a when fc and fs are given and plot response if required\n% or Fc and fc when a and fs are given\nif Lin == 2\n if (Lout == 1)|(Lout == 0)\n fc = varargin{1};\n fs = varargin{2};\n Fc = 2*fc/fs;\n if (Fc < 0)|(Fc > 1/3)\n error('dcblock error: Cut-on frequency must be between 0 and fs/6.');\n end\n a = coef(Fc);\n if Lout == 1\n varargout{1} = a;\n else\n PlotResp(fs/2,a);\n end\n elseif Lout == 2\n a = varargin{1};\n fs = varargin{2};\n if (a < 0)|(a > 1)\n error('dcblock error: Filter coefficient a must be between 0 and 1.');\n end\n Fc = atan(sqrt(3)*(1-a^2)/(1+4*a+a^2))/pi; \n varargout{1} = Fc;\n varargout{2} = Fc*fs/2;\n end\nend\n\n% Calculate a when B, fc and fs are given and plot if required\nif Lin == 3\n fc = varargin{1};\n fs = varargin{2};\n B = floor(varargin{3});\n Fc = 2*fc/fs;\n if (Fc < 0)|(Fc > 1/3)\n error('dcblock error: Cut-on frequency fc must be between 0 and fs/6.');\n return\n end\n if (B <= 2)|(B > 300)\n error('dcblock error: Quantization level B must be between 2 and 300.');\n return\n end\n a = coef(Fc);\n if Lout == 1\n varargout{1} = floor(a*(2^(B-1)-1));\n elseif Lout == 0\n aQ = floor(a*(2^(B-1)-1))/(2^(B-1)-1);\n PlotResp(fs/2,aQ);\n end\nend\n\n\nfunction a = coef(Fc);\n% get up coefficient\n a = (sqrt(3) - 2*sin(pi*Fc))/(sin(pi*Fc) + sqrt(3)*cos(pi*Fc));\n\nfunction PlotResp(Fn,a);\n% Plot frequency and phase response\n f = 0.000001:0.000001:1-0.000001;\n h = (1+a)*sin(pi*f/2)./sqrt(1+a^2-2*a*cos(pi*f));\n phi = atan((1-a)*(sin(pi*f)./(1-cos(pi*f)))/(1+a));\n indigo = [.48 .06 .89];\n subplot(2,1,1);\n loglog(Fn*f,h,'LineWidth',1.5,'Color',indigo);\n title('\\bf Frequency Response: IIR DC Blocking Filter','Color','k');\n if Fn == 1\n xlabel('Normalized Frequency');\n else\n xlabel('Frequency (Hz)');\n end\n ylabel('Magnitude ');\n minY = min(get(gca,'YTick'));\n minX = min(get(gca,'XTick'));\n maxX = max(get(gca,'XTick'));\n if minY >= 0.1 \n TickY = [0.1 1]; \n else\n for j = 1:abs(log10(minY))+1 TickY(j) = 10^(log10(minY)+j-1); end \n end\n for j = 1:(log10(maxX)-log10(minX))+1 TickX(j) = 10^(log10(minX)+j-1); end\n ylim([TickY(1) 1.1]);\n set(gca,'XGrid','on','YGrid','on','XMinorGrid','on',...\n 'YMinorGrid','on','GridLineStyle','-',...\n 'MinorGridLineStyle','-','Xtick',TickX,'Ytick',TickY,...\n 'Color',[0.835 0.918 0.918]);\n subplot(2,1,2);\n loglog(Fn*f,phi*180/pi,'LineWidth',1.5,'Color',indigo);\n title('\\bf Phase Response: IIR DC Blocking Filter','Color','k');\n if Fn == 1\n xlabel('Normalized Frequency');\n else\n xlabel('Frequency (Hz)');\n end\n ylabel('Phase (degree) ');\n ylim([0.1 100]);\n minX = min(get(gca,'XTick'));\n maxX = max(get(gca,'XTick'));\n for j = 1:(log10(maxX)-log10(minX))+1 \n TickX2(j) = minX*10^(j-1) ;\n end\n set(gca,'XGrid','on','YGrid','on','XMinorGrid','on',...\n 'YMinorGrid','on','GridLineStyle','-',...\n 'MinorGridLineStyle','-','Xtick',TickX2,'YTick',[0.1 1 10 100],...\n 'Color',[0.835 0.918 0.918]);\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/13792-the-dc-blocking-filter/dcblock.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979619, "lm_q2_score": 0.8824278587245935, "lm_q1q2_score": 0.8192537951390519}} {"text": "% Script file: calc_roots2.m\n%\n% Purpose: \n% This program solves for the roots of a quadratic equation \n% of the form a*x**2 + b*x + c = 0. It calculates the answers\n% regardless of the type of roots that the equation possesses.\n%\n% Record of revisions:\n% Date Programmer Description of change\n% ==== ========== =====================\n% 02/24/07 S. J. Chapman Original code \n%\n% Define variables:\n% a -- Coefficient of x^2 term of equation\n% b -- Coefficient of x term of equation\n% c -- Constant term of equation\n% discriminant -- Discriminant of the equation\n% x1 -- First solution of equation \n% x2 -- Second solution of equation \n\n% Prompt the user for the coefficients of the equation\ndisp ('This program solves for the roots of a quadratic ');\ndisp ('equation of the form A*X^2 + B*X + C = 0. ');\na = input ('Enter the coefficient A: ');\nb = input ('Enter the coefficient B: ');\nc = input ('Enter the coefficient C: ');\n\n% Calculate discriminant\ndiscriminant = b^2 - 4 * a * c;\n\n% Solve for the roots\nx1 = ( -b + sqrt(discriminant) ) / ( 2 * a );\nx2 = ( -b - sqrt(discriminant) ) / ( 2 * a );\n\n% Display results\ndisp ('The roots of this equation are:');\nfprintf ('x1 = (%f) +i (%f)\\n', real(x1), imag(x1));\nfprintf ('x2 = (%f) +i (%f)\\n', real(x2), imag(x2));\n", "meta": {"author": "101Hub", "repo": "Matlab101", "sha": "07273f68f1147a110443aeb121fa10962234f298", "save_path": "github-repos/MATLAB/101Hub-Matlab101", "path": "github-repos/MATLAB/101Hub-Matlab101/Matlab101-07273f68f1147a110443aeb121fa10962234f298/assets/《Matlab编程》源码/chap6/calc_roots2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9683812345563902, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.8191947836850346}} {"text": "function f=dctresample(f,L,dim)\n%DCTRESAMPLE Resample signal using Fourier interpolation\n% Usage: h=dctresample(f,L);\n% h=dctresample(f,L,dim);\n%\n% `dctresample(f,L)` returns a discrete cosine interpolation of the signal *f*\n% to length *L*. If the function is applied to a matrix, it will apply\n% to each column.\n%\n% `dctresample(f,L,dim)` does the same along dimension *dim*.\n%\n% If the input signal is not a periodic signal (or close to), this method\n% will give much better results than |fftresample| at the endpoints, as\n% this method assumes than the signal is even a the endpoints.\n%\n% The algorithm uses a DCT type iii.\n%\n% See also: fftresample, middlepad, dctiii\n\n% AUTHOR: Peter L. Søndergaard\n \n% ------- Checking of input --------------------\ncomplainif_argnonotinrange(nargin,2,3,mfilename);\n\nif nargin<3\n dim=[];\nend;\n\n[f,L,Ls,W,dim,permutedsize,order]=assert_sigreshape_pre(f,L,dim,'DCTRESAMPLE');\n\nwasreal=isreal(f);\n\n% The 'dim=1' below have been added to avoid dct and middlepad being\n% smart about choosing the dimension.\nf=dctiii(postpad(dctii(f,[],1),L))*sqrt(L/Ls);\n\nf=assert_sigreshape_post(f,dim,permutedsize,order);\n\nif wasreal\n f=real(f);\nend;\n\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/fourier/dctresample.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.8740772450055545, "lm_q1q2_score": 0.8191946296048239}} {"text": "function f1 = p07_f1 ( x )\n\n%*****************************************************************************80\n%\n%% P07_F1 evaluates the first derivative for problem 7.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 26 February 2002\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the value of the variable.\n%\n% Output, real F1, the first derivative of the\n% objective function.\n%\n f1 = ( 1.0 - 2.0 * x * x + cos ( x ) ...\n - 2.0 * x * sin ( x ) ) * exp ( - x * x );\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_min/p07_f1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.8757869932689566, "lm_q1q2_score": 0.8191643122538808}} {"text": "function inside = sphere_imp_contains_point_3d ( r, center, p )\n\n%*****************************************************************************80\n%\n%% SPHERE_IMP_CONTAINS_POINT_3D: point in implicit sphere in 3D?\n%\n% Discussion:\n%\n% An implicit sphere in 3D satisfies the equation:\n%\n% sum ( ( P(1:DIM_NUM) - CENTER(1:DIM_NUM) )**2 ) = R**2\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 February 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R, the radius of the sphere.\n%\n% Input, real CENTER(3), the center of the sphere.\n%\n% Input, real P(3), the point to be checked.\n%\n% Output, logical INSIDE, is TRUE if the point is inside the sphere.\n%\n dim_num = 3;\n \n if ( sum ( ( p(1:dim_num) - center(1:dim_num) ).^2 ) <= r * r )\n inside = 1;\n else\n inside = 0;\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/sphere_imp_contains_point_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346511643776, "lm_q2_score": 0.8757869867849166, "lm_q1q2_score": 0.8191643030322855}} {"text": "function er4OC\n%EG4OC Example 4 of optimal control tutorial.\n% This example is from the following reference:\n% S.N.Avvakumov and Yu.N.Kiselev, \"Boundary value problem for ordinary\n% differential equations with applications to optimal control\". \n% Example 5 on page 8\n\nglobal mu;\nmu = 0.5;\nsolinit = bvpinit(linspace(0,1,10),[2;2;0;-1],4);\n\nsol = bvp4c(@ode,@bc,solinit);\n\nfigure(1)\nlines = {'k-.','r--','b-'};\nut = sol.y(4,:)./sqrt(mu*sol.y(3,:).^2+sol.y(4,:).^2);\nt = sol.parameters*sol.x;\nplot(t,ut,lines{1});\n% axis([-0.1 1.1 0 1.7]);\ntitle('Smoothed control');\nxlabel('t');\nylabel('u');\ndrawnow; hold on;\n\nfigure(2)\nplot(sol.y(1,:),sol.y(2,:),lines{1});\n% axis([-0.1 1.1 0 1.7]);\ntitle('Admissible trajectories');\nxlabel('x_1');\nylabel('x_2');\ndrawnow; hold on;\n\n% the solution for one value of mu is used as guess for the next.\nfor i=2:3\n if i==2\n mu = 0.3;\n else\n mu = .1;\n end;\n % After creating function handles, the new value of mu \n % will be used in nested functions.\n sol = bvp4c(@ode,@bc,sol);\n figure(2)\n plot(sol.y(1,:),sol.y(2,:),lines{i});\n drawnow;\n \n figure(1)\n ut = sol.y(4,:)./sqrt(mu*sol.y(3,:).^2+sol.y(4,:).^2);\n t = sol.parameters*sol.x;\n plot(t,ut,lines{i});\n drawnow;\n \nend\nfigure(1); legend('mu = 0.5', 'mu = 0.3', 'mu = 0.1', ...\n 'Location', 'NorthWest'); hold off;\nfigure(2); legend('mu = 0.5', 'mu = 0.3', 'mu = 0.1', ...\n 'Location', 'NorthWest'); hold off;\n \n% print -djpeg90 -f1 -r300 eg4_trajectory.jpg;\n% print -djpeg90 -f2 -r300 eg4_control.jpg\n\n% --------------------------------------------------------------------------\nfunction dydt = ode(t,y,T)\nglobal mu;\nterm = sqrt(mu*y(3)^2+y(4)^2);\ndydt = T*[ y(2) + mu*y(3)/term\n y(4)/term\n 0\n -y(3)];\n\n% --------------------------------------------------------------------------\n% boundary conditions, with 4 states and 1 parameters, 5 conditions are\n% needed: x1(0) =2, x2(0) = 2; x1(1) = 0; x2(1) = 0; x3(1)^2+x4(1)^2 = 1;\nfunction res = bc(ya,yb,T)\nres = [ya(1)-2\n ya(2)-2\n yb(1)\n yb(2)\n yb(3)^2+yb(4)^2-1];", "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/25889-an-optimal-control-tutorial-for-beginners/er4OC.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.8976952886860979, "lm_q1q2_score": 0.8190896510369865}} {"text": "function [v,unv] = statmoments(p,n)\n%STATMOMENTS Computes statistical central moments of image histogram.\n% [W,UNV] = STATMOMENTS(P,N) computes up to the Nth statistical\n% central moment of a histogram whose components are in vector\n% P. The length of P must equal 256 or 65536. \n%\n% The program outputs a vector V with V(1) = mean, V(2) = variance,\n% V(3) = 3rd moment, . . . V(N) = Nth central moment. The random\n% variable values are normalized to the range [0,1], so all\n% moments also are in this range. \n% \n% The program also outputs a vector UNV containing the same moments\n% as V, but using un-normalized random variable values (e.g., 0 to\n% 255 if length(P) = 2^8). For example, if length(P) = 256 and V(1)\n% = 0.5, then UNV(1) would have the value UNV(1) = 127.5 (half of\n% the [0,255] range). \n%\n% Copyright 2002-2020 Gatesmark\n%\n% This function, and other functions in the DIPUM Toolbox, are based \n% on the theoretical and practical foundations established in the \n% book Digital Image Processing Using MATLAB, 3rd ed., Gatesmark \n% Press, 2020.\n%\n% Book website: http://www.imageprocessingplace.com\n% License: https://github.com/dipum/dipum-toolbox/blob/master/LICENSE.txt\n\nLp = length(p);\nif (Lp ~= 256) && (Lp ~= 65536)\n error('P must be a 256- or 65536-element vector.');\nend\nG = Lp - 1;\n\n% Make sure the histogram has unit area, and convert it to a\n% column vector.\np = p/sum(p); p = p(:);\n\n% Form a vector of all the possible values of the\n% random variable.\nz = 0:G;\n\n% Now normalize the z's to the range [0,1].\nz = z./G;\n\n% The mean.\nm = z*p;\n\n% Center random variables about the mean.\nz = z - m;\n\n% Compute the central moments.\nv = zeros(1,n);\nv(1) = m;\nfor j = 2:n\n v(j) = (z.^j)*p;\nend\n\nif nargout > 1\n % Compute the uncentralized moments.\n unv = zeros(1,n);\n unv(1)=m.*G;\n for j = 2:n\n unv(j) = ((z*G).^j)*p;\n end\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/statmoments.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.8976952893703477, "lm_q1q2_score": 0.8190896452488179}} {"text": "function s = legendre_integral ( p )\n\n%*****************************************************************************80\n%\n%% LEGENDRE_INTEGRAL evaluates a monomial Legendre integral.\n%\n% Discussion:\n%\n% To test a Legendre quadrature rule, we use it to approximate the\n% integral of a monomial:\n%\n% integral ( -1 <= x <= +1 ) x^p dx\n%\n% This routine is given the value of the exponent, and returns the\n% exact value of the integral.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 16 May 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer P, the power.\n%\n% Output, real S, the value of the exact integral.\n%\n\n%\n% Get the exact value of the integral.\n%\n if ( mod ( p, 2 ) == 0 )\n \n s = 2.0 / ( p + 1 );\n\t\n else\n \n s = 0.0;\n\t\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/exactness/legendre_integral.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.877476793890012, "lm_q1q2_score": 0.8190638721304091}} {"text": "function value = torus_square_area_3d ( r1, r2 )\n\n%*****************************************************************************80\n%\n%% TORUS_SQUARE_AREA_3D returns the area of a square torus in 3D.\n%\n% Integration region:\n%\n% Points (X,Y,Z) such that:\n%\n% R1 - R2 <= SQRT ( X**2 + Y**2 ) <= R1 + R2,\n% -R2 <= Z <= R2.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 20 May 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R1, R2, the two radii that define the torus.\n%\n% Output, real TORUS_SQUARE_AREA_3D, the area of the torus.\n%\n value = 16.0E+00 * pi * r1 * 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/stroud/torus_square_area_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8774767890838836, "lm_q1q2_score": 0.8190638708941295}} {"text": "function mean = genlogistic_mean ( a, b, c )\n\n%*****************************************************************************80\n%\n%% GENLOGISTIC_MEAN returns the mean of the Generalized Logistic PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 08 October 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A, B, C, the parameters of the PDF.\n% 0.0 < B,\n% 0.0 < C.\n%\n% Output, real MEAN, the mean of the PDF.\n%\n mean = a + b * ( euler_constant ( ) + digamma ( c ) );\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/genlogistic_mean.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897426182321, "lm_q2_score": 0.8705972667296309, "lm_q1q2_score": 0.8190489784907058}} {"text": "function [R,subgrad,data] = risk_svm(data,W)\n% RISK_SVM evaluates SVM risk term given by L1-hinge loss.\n% \n% Synopsis:\n% [R,subgrad,data] = risk_svm(data)\n% [R,subgrad,data] = risk_svm(data,W)\n%\n% Description:\n% Let the risk term be defined as\n%\n% R(W) = 1/m sum_{i=1}^m max(0, 1-data.y(i)*(W'*[data.X(:,i);data.X0]))\n%\n% This function returns value R and subgradient SUBGRAD of the \n% risk R(W) at W.\n%\n\nif nargin < 2\n % evaluates the risk and the subgradient of at W = 0\n\n nExamples = size(data.X,2);\n R = 1;\n if data.X0 == 0\n subgrad = -data.X*data.y(:)/nExamples;\n else \n subgrad = [-data.X*data.y(:)/nExamples; ...\n -data.X0*sum(data.y)/nExamples];\n end\n \nelse\n \n nExamples = size(data.X,2);\n \n if data.X0 == 0\n dfce = 1 - (W'*data.X).*reshape(data.y,1,nExamples);\n\n idx = find(dfce>0); \n R = sum(dfce(idx))/nExamples;\n \n subgrad = -data.X(:,idx)*reshape(data.y(idx),length(idx),1)/nExamples;\n else\n \n dfce = 1 - (W(1:end-1)'*data.X + W(end)*data.X0).*(data.y(:)');\n idx = find(dfce>0);\n \n R = sum(dfce(idx))/nExamples;\n subgrad = [-data.X(:,idx)*reshape(data.y(idx),length(idx),1)/nExamples; ...\n -data.X0*sum(data.y(idx))/nExamples];\n end\n \nend\n \nreturn;\n% EOF", "meta": {"author": "uricamic", "repo": "flandmark", "sha": "ecf122f93f73504fe7d8faccca525c6b1e98fdcd", "save_path": "github-repos/MATLAB/uricamic-flandmark", "path": "github-repos/MATLAB/uricamic-flandmark/flandmark-ecf122f93f73504fe7d8faccca525c6b1e98fdcd/learning/bmrm/risk_svm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542840900507, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.8190340752327563}} {"text": "% compute abscissas and weight factors for Gaussian-Hermite quadrature\n%\n% CALL: [x,w] = gauher(N)\n% \n% x = base points (abscissas)\n% w = weight factors\n% N = number of base points (abscissas) (integrates an up to (2N-1)th order\n% polynomial exactly)\n%\n% p(x)=exp(-x^2/2)/sqrt(2*pi), a =-Inf, b = Inf \n%\n% The Gaussian Quadrature integrates a (2n-1)th order\n% polynomial exactly and the integral is of the form\n% b N\n% Int ( p(x)* F(x) ) dx = Sum ( w_j* F( x_j ) )\n% a j=1\t\t \n%\n% this procedure uses the coefficients a(j), b(j) of the\n% recurrence relation\n%\n% b p (x) = (x - a ) p (x) - b p (x)\n% j j j j-1 j-1 j-2\n%\n% for the various classical (normalized) orthogonal polynomials,\n% and the zero-th moment\n%\n% 1 = integral w(x) dx\n%\n% of the given polynomial's weight function w(x). Since the\n% polynomials are orthonormalized, the tridiagonal matrix is\n% guaranteed to be symmetric.\n\nfunction [x,w]=gauher(N)\n if N==20 % return precalculated values\n x=[ -7.619048541679757;-6.510590157013656;-5.578738805893203;\n -4.734581334046057;-3.943967350657318;-3.18901481655339 ;\n -2.458663611172367;-1.745247320814127;-1.042945348802751;\n -0.346964157081356; 0.346964157081356; 1.042945348802751;\n 1.745247320814127; 2.458663611172367; 3.18901481655339 ;\n 3.943967350657316; 4.734581334046057; 5.578738805893202;\n 6.510590157013653; 7.619048541679757];\n w=[ 0.000000000000126; 0.000000000248206; 0.000000061274903;\n 0.00000440212109 ; 0.000128826279962; 0.00183010313108 ;\n 0.013997837447101; 0.061506372063977; 0.161739333984 ;\n 0.260793063449555; 0.260793063449555; 0.161739333984 ;\n 0.061506372063977; 0.013997837447101; 0.00183010313108 ;\n 0.000128826279962; 0.00000440212109 ; 0.000000061274903;\n 0.000000000248206; 0.000000000000126 ];\n else\n b = sqrt( (1:N-1)/2 )'; \n [V,D] = eig( diag(b,1) + diag(b,-1) );\n w = V(1,:)'.^2;\n x = sqrt(2)*diag(D);\n end\n", "meta": {"author": "benfulcher", "repo": "hctsa", "sha": "919f2aed7cc8e1a3a03304c1ade573fa664c73f8", "save_path": "github-repos/MATLAB/benfulcher-hctsa", "path": "github-repos/MATLAB/benfulcher-hctsa/hctsa-919f2aed7cc8e1a3a03304c1ade573fa664c73f8/Toolboxes/gpml/util/gauher.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966717067252, "lm_q2_score": 0.8652240930029117, "lm_q1q2_score": 0.8190182467170263}} {"text": "function cPoly=composePolys(a,b)\n%%COMPOSEPOLYS Compose two polynomials given as power series. This means,\n% for polynomials A(x) and B(x) in a scalar x, evaluate the\n% composition C(x)=A(B(x)). C(x) itself is a polynomial. Thus,\n% the output of the function is the set of coefficients of C\n% (subject to finite precision limitations in the recursion).\n%\n%INPUTS: a Coefficients for a power series of the form\n% y(z)=a(end)+a(end-1)*z+a(end-2)*z^2+...\n% into which the power series in b is to be substituted. The\n% ordering of the coefficients is the same as in Matlab's polyval\n% function.\n% b Coefficients for the power series that is substitued into a.\n%\n%OUTPUTS: c Coefficients for the power series that represents the\n% substitution of the polynomial b into a.\n%\n%The substitution is performed by explicitly evaluating power of b (via\n%repeated convolutions), multiplying the powers by the appropriate value in\n%a and summing the results.\n%\n%February 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\norderA=length(a)-1;\norderB=length(b)-1;\n\n%The order of the output.\nprodOrder=orderA*orderB;\n\n%Zero-pad b so that it is the same length as the length of the output. This\n%simplifies assignments in the loop.\nb=[zeros(prodOrder-orderB,1);b(:)];\n\n%bProd will hold powers of b. Right now, it is just initialized to 1 (b^0).\nbProd=[zeros(prodOrder,1);1];\n\n%Initialize the output with the zeroth-order term.\ncPoly=zeros(prodOrder+1,1);\ncPoly=cPoly+a(end)*bProd;\nfor curPow=1:orderA\n %Get the polynomial for the next power of b. The convolution operation\n %is equivalent to polynomial multiplication. The extra leading terms\n %(which are all zeros) are just thrown out.\n bProd=conv(b,bProd);\n bProd=bProd((prodOrder+1):end);\n \n %Add in the next power term.\n cPoly=cPoly+a(end-curPow)*bProd;\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/Polynomials/composePolys.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8872045937171068, "lm_q1q2_score": 0.8189245905078747}} {"text": "function result = ball_unit_f1_nd ( func, n )\n\n%*****************************************************************************80\n%\n%% BALL_UNIT_F1_ND approximates an integral inside a unit ball in ND.\n%\n% Integration region:\n%\n% Points X(1:N) such that:\n%\n% Sum ( X(1:N)**2 ) <= 1.\n%\n% Discussion:\n%\n% An (N+1)*2**N point 5-th degree formula is used, Stroud number SN:5-6.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 25 November 2004\n%\n% Author:\n%\n% MATLAB version by John Burkardt\n%\n% Reference:\n%\n% Arthur H Stroud,\n% Approximate Calculation of Multiple Integrals,\n% Prentice Hall, 1971.\n%\n% Parameters:\n%\n% Input, external FUNC, the name of the user supplied\n% function which evaluates F at the N-vector X, of the form\n% function value = func ( n, x )\n%\n% Input, integer N, the dimension of the space.\n%\n% Output, real RESULT, the approximate integral of the function.\n%\n u2 = ( 1.0E+00 - 2.0E+00 * sqrt ( 1.0E+00 / ( n + 4 ) ) ) / ( n + 2 );\n u = sqrt ( u2 );\n x(1:n) = - u;\n\n w = 1.0E+00 / ( ( n + 1 ) * 2^n );\n\n quad = 0.0E+00;\n ihi = 2^n;\n\n for i = 1 : ihi\n\n itemp = i - 1;\n\n for j = 1 : n\n\n if ( mod ( itemp, 2 ) == 1 )\n x(j) = - abs ( x(j) );\n else\n x(j) = abs ( x(j) );\n end\n\n itemp = floor ( itemp / 2 );\n\n end\n\n quad = quad + w * feval ( func, n, x );\n\n end\n\n temp = sqrt ( n + 4 );\n\n t = sqrt ( 2.0E+00 * ( n + 1 ) / ( n + 2 ) ) / ( n * temp );\n\n y = ( 1.0E+00 + 2.0E+00 / ( n * temp ) ) / ( n + 2 );\n v = sqrt ( y - t );\n u = sqrt ( y + ( n - 1 ) * t );\n\n khi = 2^n;\n\n for i = 1 : n\n\n x(1:n) = - v;\n\n x(i) = - u;\n\n for k = 1 : khi\n\n ktemp = k - 1;\n\n for j = 1 : n\n\n if ( mod ( ktemp, 2 ) == 1 )\n x(j) = - abs ( x(j) );\n else\n x(j) = abs ( x(j) );\n end\n\n ktemp = floor ( ktemp / 2 );\n\n end\n\n quad = quad + w * feval ( func, n, x );\n\n end\n\n x(i) = - v;\n\n end\n\n volume = ball_unit_volume_nd ( n );\n result = quad * 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/stroud/ball_unit_f1_nd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552538, "lm_q2_score": 0.8872045862611166, "lm_q1q2_score": 0.8189245855039986}} {"text": "function [OUT, W] = CrossWeightAverage(DATA,WEIGHT)\n% =======================================================================\n% Compute the weighted average of DATA, computing the weights form the\n% matrix WEIGHT. Note that if there are NaNs in DATA the weights are \n% rescaled. WEIGHTS cannot contain NaN\n% =======================================================================\n% [average, weight] = CrossWeightAverage(DATA,WEIGHT)\n% -----------------------------------------------------------------------\n% INPUT \n%\t- DATA: panel of time series DATA(T,N) of T observation x N series \n% (NaN are accepted and weights rescaled)\n% - WEIGHT: time series of WEIGHTS (TxN). You can also provide a (1xN) \n% matrix in this case the code would automatically compute fixed \n% weights\n% -----------------------------------------------------------------------\n% OUTPUT \n%\t- average : weighted average vector (T x 1) [double]\n%\t- weight : matrix of weights (T x N) [double]\n% -----------------------------------------------------------------------\n% EXAMPLE 1: foreign variables as in GVAR (example with fixed weights)\n% x = [1 NaN 3 ; \n% 2 3 4 ; \n% 3 4 5 ; \n% 4 5 6];\n% w = [0 .4 .6];\n% [average, weight] = CrossWeightAverage(x,w)\n% -----------------------------------------------------------------------\n% EXAMPLE 2: weighted average (with time-varying weights)\n% x = [ 1 NaN 3 ;\n% 2 3 4 ;\n% 3 4 5 ; \n% 4 5 6];\n% w = [.4 .2 .4 ; \n% .3 .4 .3 ;\n% .4 .3 .3 ;\n% .5 .3 .2];\n% [average, weight] = CrossWeightAverage(x,w)\n% =======================================================================\n% VAR Toolbox 3.0\n% Ambrogio Cesa-Bianchi\n% ambrogiocesabianchi@gmail.com\n% March 2012. Updated November 2020\n% -----------------------------------------------------------------------\n\n\n\n%% Preliminaries\n% Check inputs\n[r1, c1] = size(DATA);\n[r2, c2] = size(WEIGHT);\nif r2==1 && c2==c1 \n % Create a matrix of fixed weights\n aux = [];\n for ii=1:r1\n aux = [aux; WEIGHT];\n end\n WEIGHT = aux;\nend\n\n% Re-Check inputs\n[r1, c1] = size(DATA);\n[r2, c2] = size(WEIGHT);\nif r1~=r2 || c1~=c2\n disp(' ')\n disp('The matrices of data and weights are not conformable.')\n return\nend\n\n%% Cross section weihgted average\n[nobs, nvars] = size(DATA);\nnans = isnan(DATA);\nWEIGHT(nans) = NaN;\n\nOUT(1:nobs,1) = NaN;\nW(1:nobs,1:nvars) = NaN;\n\nfor ii=1:nobs\n aux_weight = WEIGHT(ii,:)./nansum(WEIGHT(ii,:));\n W(ii,:) = aux_weight;\n aux_weight(nans(ii,:)) = 0;\n DATA(ii,nans(ii,:)) = 0;\n if sum(nans(ii,:))==nvars\n OUT(ii,1) = NaN;\n else\n OUT(ii,1) = DATA(ii,:) * aux_weight';\n end\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/Stats/CrossWeightAverage.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625069680097, "lm_q2_score": 0.8791467595934565, "lm_q1q2_score": 0.8188922446837231}} {"text": "clear all, close all, clc\n\n% Define domain\ndx = 0.001;\nL = pi;\nx = (-1+dx:dx:1)*L;\nn = length(x); nquart = floor(n/4);\n\n% Define hat function\nf = 0*x;\nf(nquart:2*nquart) = 4*(1:nquart+1)/n;\nf(2*nquart+1:3*nquart) = 1-4*(0:nquart-1)/n;\nplot(x,f,'-k','LineWidth',1.5), hold on\n\n% Compute Fourier series\nCC = jet(20);\nA0 = sum(f.*ones(size(x)))*dx;\nfFS = A0/2;\nfor k=1:20\n A(k) = sum(f.*cos(pi*k*x/L))*dx; % Inner product\n B(k) = sum(f.*sin(pi*k*x/L))*dx;\n fFS = fFS + A(k)*cos(k*pi*x/L) + B(k)*sin(k*pi*x/L);\n plot(x,fFS,'-','Color',CC(k,:),'LineWidth',1.2)\nend\n\n\n%% Plot amplitudes\nfigure\nclear ERR\nclear A\nfFS = A0/2;\nA(1) = A0/2;\nERR(1) = norm(f-fFS);\nkmax = 100;\nfor k=1:kmax\n A(k+1) = sum(f.*cos(pi*k*x/L))*dx;\n B(k+1) = sum(f.*sin(pi*k*x/L))*dx;\n% plot(x,B(k)*sin(2*k*pi*x/L),'k-','LineWidth',1.2);\n fFS = fFS + A(k+1)*cos(k*pi*x/L) + B(k+1)*sin(k*pi*x/L);\n ERR(k+1) = norm(f-fFS)/norm(f);\nend\nthresh = median(ERR)*sqrt(kmax)*4/sqrt(3);\nr = max(find(ERR>thresh));\nr = 7;\nsubplot(2,1,1)\nsemilogy(0:1:kmax,A,'k','LineWidth',1.5)\nhold on\nsemilogy(r,A(r+1),'bo','LineWidth',1.5)\nxlim([0 kmax])\nylim([10^(-7) 1])\nsubplot(2,1,2)\nsemilogy(0:1:kmax,ERR,'k','LineWidth',1.5)\nhold on\nsemilogy(r,ERR(r+1),'bo','LineWidth',1.5)\n", "meta": {"author": "dynamicslab", "repo": "databook_matlab", "sha": "d390d39d18489a4804ee87a143ae8db8a1f3010b", "save_path": "github-repos/MATLAB/dynamicslab-databook_matlab", "path": "github-repos/MATLAB/dynamicslab-databook_matlab/databook_matlab-d390d39d18489a4804ee87a143ae8db8a1f3010b/CH02/CH02_SEC01_1_FourierSines.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.8840392939666335, "lm_q1q2_score": 0.8188888939291817}} {"text": "function isMonge=isMongeMatrix(A)\n%%ISMONGEMATRIX Determine whether a matrix is a Monge matrix. An n1Xn2\n% matrix is a Monge matrix if A(i1,j1)+A(i2,j2)<=A(i1,j2)+A(i2,j1)\n% for all 1<=i1A(i1,j2)+A(i2,j1))\n isMonge=false;\n return;\n end\n end\n end\n end\nend\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/isMongeMatrix.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8962513807543223, "lm_q1q2_score": 0.8188838414589773}} {"text": "function a = bivand2 ( n, alpha, beta )\n\n%*****************************************************************************80\n%\n%% BIVAND2 returns a bidimensional Vandermonde2 matrix.\n%\n% Discussion:\n%\n% N = 3, ALPHA = ( 1, 2, 3 ), BETA = ( 10, 20, 30 )\n%\n% (x,y) | (1,10) (2,10) (3,10) (1,20) (2,20) (3,20) (1,30) (2,30) (3,30)\n% --------+---------------------------------------------------------------\n% 1 | 1 1 1 1 1 1 1 1 1 \n% x | 1 2 3 1 2 1 1 2 3\n% x^2 | 1 4 9 1 4 1 1 4 9\n% y | 10 10 10 20 20 20 30 30 30\n% x y | 10 20 30 20 40 60 30 60 90\n% x^2y | 10 40 90 20 80 180 30 120 270\n% y^2 | 100 100 100 400 400 400 900 900 900\n% x y^2 | 100 200 300 400 800 1200 900 1800 2700\n% x^2y^2 | 100 400 900 400 1600 3600 900 3600 8100\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 May 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the data vectors.\n%\n% Input, real ALPHA(N), BETA(N), the values that define A.\n%\n% Output, real A(N^2,N^2), the matrix.\n%\n nn = n * n;\n a = zeros ( nn, nn );\n\n i = 0\n for iy = 1 : n\n for ix = 1 : n\n i = i + 1;\n j = 0;\n for jy = 1 : n\n for jx = 1 : n\n j = j + 1;\n a(i,j) = alpha(jx) ^ ( ix - 1 ) * beta(jy) ^ ( iy - 1 );\n end\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/vandermonde/bivand2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.8962513668985002, "lm_q1q2_score": 0.8188838414393977}} {"text": "function x = u1_to_sphere_unit_2d ( u )\n\n%*****************************************************************************80\n%\n%% U1_TO_SPHERE_UNIT_2D maps a point in the unit interval onto the unit sphere in 2D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 06 July 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real U, a point in the unit interval.\n%\n% Output, real X(2), the corresponding point on the circle.\n%\n angle = 2.0 * pi * u(1);\n\n x(1) = cos ( angle );\n x(2) = sin ( angle );\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/halton/u1_to_sphere_unit_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8962513703624558, "lm_q1q2_score": 0.8188838403909464}} {"text": "function [J, grad] = costFunction(theta, X, y)\n%COSTFUNCTION Compute cost and gradient for logistic regression\n% J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the\n% parameter for logistic regression and the gradient of the cost\n% w.r.t. to the parameters.\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \n% J = 0;\n% grad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n% Note: grad should have the same dimensions as theta\n%\n\ntemp1 = -1 * (y .* log(sigmoid(X * theta)));\ntemp2 = (1 - y) .* log(1 - sigmoid(X * theta));\n\nJ = sum(temp1 - temp2) / m;\n\ngrad = (X' * (sigmoid(X * theta) - y)) * (1/m);\n\n% =============================================================\n\nend\n", "meta": {"author": "rieder91", "repo": "MachineLearning", "sha": "f6708f216326cb5c9e9e5c3afc912060bfa10486", "save_path": "github-repos/MATLAB/rieder91-MachineLearning", "path": "github-repos/MATLAB/rieder91-MachineLearning/MachineLearning-f6708f216326cb5c9e9e5c3afc912060bfa10486/Exercise 2/ex2/costFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9566341987633822, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.8187364744811119}} {"text": "function a = r8vec_even ( n, alo, ahi )\n\n%*****************************************************************************80\n%\n%% R8VEC_EVEN returns N real values, evenly spaced between ALO and AHI.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 24 January 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of values.\n%\n% Input, real ALO, AHI, the low and high values.\n%\n% Output, real A(N), N evenly spaced values.\n% Normally, A(1) = ALO and A(N) = AHI.\n% However, if N = 1, then A(1) = 0.5*(ALO+AHI).\n%\n if ( n == 1 )\n\n a(1) = 0.5 * ( alo + ahi );\n\n else\n\n a(1:n) = ( (n-1:-1:0) * alo + (0:n-1) * ahi ) / ( n - 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/quadrature_golub_welsch/r8vec_even.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009457116781, "lm_q2_score": 0.8947894668039496, "lm_q1q2_score": 0.8186437293917816}} {"text": "function price = Price_Exchange_Option_Margrabe_2D( S0_1, S0_2, T, rho, sigma_1, sigma_2, q_1, q_2)\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% About: calcuates Price of 2D Exchange option, (S_1(T) - S_2(T)), using Magrabe Formula Under 2D Diffusion\n% Author: Justin Lars Kirkby\n%\n% -----------------\n% Params\n% -----------------\n% S0_1 = initial asset price of first asset, e.g. S0_1 = 100\n% S0_2 = initial asset price of second asset, e.g. S0_2 = 100\n% T = time to maturity in years (e.g. T=1)\n% rho = instantaneous correlation between S_1 and S_2\n% sigma_1 = volatility of first asset (annualized), e.g. sigma = 0.2\n% sigma_2 = volatility of second asset (annualized), e.g. sigma = 0.2\n% q_1 = dividend yield of first asset, e.g. q_1 = 0.02\n% q_2 = dividend yield of second asset, e.g. q_2 = 0.02\n% \n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nsig = sqrt(sigma_1^2 - 2*rho*sigma_1*sigma_2 + sigma_2^2);\nd1 = (log(S0_1/S0_2) + 0.5*sig^2*T)/(sig*sqrt(T));\nd2 = d1 - sig*sqrt(T);\nprice = exp(-q_1*T)*S0_1*normcdf(d1) - exp(-q_2*T)*S0_2*normcdf(d2);\n\nend\n\n", "meta": {"author": "jkirkby3", "repo": "PROJ_Option_Pricing_Matlab", "sha": "3859a390f395e452ad61440f95a5714dd8fb4d90", "save_path": "github-repos/MATLAB/jkirkby3-PROJ_Option_Pricing_Matlab", "path": "github-repos/MATLAB/jkirkby3-PROJ_Option_Pricing_Matlab/PROJ_Option_Pricing_Matlab-3859a390f395e452ad61440f95a5714dd8fb4d90/Analytical/BlackScholes/Price_Exchange_Option_Margrabe_2D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.97482116415135, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.8185904478535179}} {"text": "function trans = createRotation(varargin)\n%CREATEROTATION Create the 3*3 matrix of a rotation.\n%\n% TRANS = createRotation(THETA);\n% Returns the rotation corresponding to angle THETA (in radians)\n% The returned matrix has the form :\n% [cos(theta) -sin(theta) 0]\n% [sin(theta) cos(theta) 0]\n% [0 0 1]\n%\n% TRANS = createRotation(POINT, THETA);\n% TRANS = createRotation(X0, Y0, THETA);\n% Also specifies origin of rotation. The result is similar as performing\n% translation(-X0, -Y0), rotation(THETA), and translation(X0, Y0).\n%\n% Example\n% % apply a rotation on a polygon\n% poly = [0 0; 30 0;30 10;10 10;10 20;0 20];\n% trans = createRotation([10 20], pi/6);\n% polyT = transformPoint(poly, trans);\n% % display the original and the rotated polygons\n% figure; hold on; axis equal; axis([-10 40 -10 40]);\n% drawPolygon(poly, 'k');\n% drawPolygon(polyT, 'b');\n%\n% See also:\n% transforms2d, transformPoint, createRotation90, createTranslation\n%\n\n% ---------\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 06/04/2004.\n%\n\n% HISTORY\n% 22/04/2009: rename as createRotation\n\n% default values\ncx = 0;\ncy = 0;\ntheta = 0;\n\n% get input values\nif length(varargin)==1\n % only angle\n theta = varargin{1};\nelseif length(varargin)==2\n % origin point (as array) and angle\n var = varargin{1};\n cx = var(1);\n cy = var(2);\n theta = varargin{2};\nelseif length(varargin)==3\n % origin (x and y) and angle\n cx = varargin{1};\n cy = varargin{2};\n theta = varargin{3};\nend\n\n% compute coefs\ncot = cos(theta);\nsit = sin(theta);\ntx = cy*sit - cx*cot + cx;\nty = -cy*cot - cx*sit + cy;\n\n% create transformation matrix\ntrans = [cot -sit tx; sit cot ty; 0 0 1];\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/private/createRotation.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.885631484383387, "lm_q1q2_score": 0.8184490918085509}} {"text": "function [ i, j ] = i4_to_pascal ( k )\n\n%*****************************************************************************80\n%\n%% I4_TO_PASCAL converts a linear index to Pascal triangle coordinates.\n%\n% Discussion:\n%\n% We describe the grid points in Pascal's triangle in two ways:\n%\n% As a linear index K:\n%\n% 1\n% 2 3\n% 4 5 6\n% 7 8 9 10\n%\n% As elements (I,J) of Pascal's triangle:\n%\n% 0,0\n% 1,0 0,1\n% 2,0 1,1 0,2\n% 3,0 2,1 1,2 0,3\n%\n% Example:\n%\n% K I J\n%\n% 1 0 0\n% 2 1 0\n% 3 0 1\n% 4 2 0\n% 5 1 1\n% 6 0 2\n% 7 3 0\n% 8 2 1\n% 9 1 2\n% 10 0 3\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 April 2015\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer K, the linear index of the (I,J) element.\n% 1 <= K.\n%\n% Output, integer I, J, the Pascal indices.\n%\n if ( k <= 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'I4_TO_PASCAL - Fatal error!\\n' );\n fprintf ( 1, ' K must be positive.\\n' );\n error ( 'I4_TO_PASCAL - Fatal error!' );\n end\n\n d = i4_to_pascal_degree ( k );\n\n j = k - ( d * ( d + 1 ) ) / 2 - 1;\n i = d - j;\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/i4lib/i4_to_pascal.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450965, "lm_q2_score": 0.9032942151647514, "lm_q1q2_score": 0.8183753614576424}} {"text": "%GENDATL Generation of Lithuanian classes\n% \n% A = GENDATL(N,S)\n%\t\n% INPUT\n% N Number of objects per class (optional; default: [50 50])\n% S Standard deviation for the data generation (optional; default: 1)\n%\n% OUTPUT\n% A Dataset\n%\n% DESCRIPTION \n% Generation of Lithuanian classes, a 2-dimensional, 2-class dataset A\n% of N objects according to the definition given by Raudys. \n% The data is uniformly distributed along two sausages and is superimposed\n% by a normal distribution with standard deviation S in all directions. \n% Class priors are P(1) = P(2) = 0.5.\n% \n% SEE ALSO (PRTools Guide)\n% DATASETS, PRDATASETS\n\n% Copyright: M. Skurichina, R.P.W. Duin, duin@ph.tn.tudelft.nl\n% Faculty of Applied Sciences, Delft University of Technology\n% P.O. Box 5046, 2600 GA Delft, The Netherlands\n\n% $Id: gendatl.m,v 1.3 2007/06/19 11:44:14 duin Exp $\n\nfunction a = gendatl(N,s)\n\t\tif nargin < 1, \n\t\tprwarning(3,'Class cardinalities are not specified, assuming [50 50].');\n\t\tN = [50 50]; \n\tend\n\tif nargin < 2, \n\t\tprwarning(4,'Standard deviation for the data generation is not specified, assuming 1.');\n\t\ts = 1; \n\tend\n\tif (length(N) == 1),\n\t\tN(2) = N(1);\n\tend;\n\n\tu1\t= 2*pi/3*(rand(N(1),1)-0.5*ones(N(1),1));\n\tu2\t= 2*pi/3*(rand(N(2),1)-0.5*ones(N(2),1));\n\ta \t= [[10*cos(u1) + s*randn(N(1),1) 10*sin(u1) + s*randn(N(1),1)]; ...\n\t\t\t\t[6.2*cos(u2) + s*randn(N(2),1) 6.2*sin(u2) + s*randn(N(2),1)]];\n\tlab = genlab(N);\n\ta \t= prdataset(a,lab,'name','Lithuanian Classes');\n\ta = setlablist(a,[1 2]');\n\ta = setprior(a,[0.5 0.5]);\nreturn;\n", "meta": {"author": "marianux", "repo": "ecg-kit", "sha": "c8e3de47c54a9214138143676d2aa546b0540dd2", "save_path": "github-repos/MATLAB/marianux-ecg-kit", "path": "github-repos/MATLAB/marianux-ecg-kit/ecg-kit-c8e3de47c54a9214138143676d2aa546b0540dd2/common/prtools/gendatl.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.8824278788223264, "lm_q1q2_score": 0.8183312276466898}} {"text": "function An = slnormalize(A, p, d)\n%SLNORMALIZE Normalize the sub-arrays\n%\n% $ Syntax $\n% - An = slnormalize(A)\n% - An = slnormalize(A, p)\n% - An = slnormalize(A, [], d)\n% - An = slnormalize(A, p, d)\n%\n% $ Arguments $\n% - A: the input array\n% - p: the order of the norm (default = 2)\n% - d: the dimension of subarrays (default = 1, column vectors)\n% - An: the normalized array\n%\n% $ Description $\n% - An = slnormalize(A) normalizes the column vectors of A by 2nd-order.\n%\n% - An = slnormalize(A, p) normalizes the column vectors of a by\n% pth-order.\n%\n% - An = slnormalize(A, [], d) normalizes the subarrays of A along \n% dimensions specified by d by 2nd-order.\n%\n% - An = slnormalize(A, p, d) normalizes the subarrays of A along\n% dimensions specified by d by pth-order.\n%\n% $ Remarks $\n% # Normalize an array by pth order means dividing the elements of \n% the array by its p-th norm.\n% # p can be inf or -inf. If p = inf, then the Lp norm is simply the\n% maximum magnitude value; while if p = -inf, then the Lp norm is the \n% minimum magnitude value.\n%\n% $ History $\n% - Created by Dahua Lin on Nov 19th, 2005\n% - Modified by Dahua Lin on Sep 10th, 2006\n% - replace slmul by slmulvec to increase efficiency\n%\n\n%% parse and verify input arguments\nif nargin < 2 || isempty(p)\n p = 2;\nend\nif nargin < 3 || isempty(d)\n d = 1;\nend\nif ~isscalar(p)\n error('sltoolbox:notscalar', 'p should be a scalar');\nend\nif p == 0\n error('sltoolbox:zeroerr', 'p should not be zero');\nend\n\n%% compute\nnrms = slnorm(A, p, d);\nnrms = slenforce(nrms, 'positive');\nAn = slmulvec(A, 1 ./ nrms);\n\n\n\n", "meta": {"author": "lmthang", "repo": "nmt.hybrid", "sha": "50d5c025f18ed280ff0fd2e2adce327f4170a2c3", "save_path": "github-repos/MATLAB/lmthang-nmt.hybrid", "path": "github-repos/MATLAB/lmthang-nmt.hybrid/nmt.hybrid-50d5c025f18ed280ff0fd2e2adce327f4170a2c3/code/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/core/slnormalize.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632956467158, "lm_q2_score": 0.8824278649085117, "lm_q1q2_score": 0.8183312129720524}} {"text": "function [ mO ] = ImageConvFrequencyDomain( mI, mH, convShape )\n% ----------------------------------------------------------------------------------------------- %\n% [ mO ] = ImageConvFrequencyDomain( mI, mH, convShape )\n% Applies Image Convolution in the Frequency Domain.\n% Input:\n% - mI - Input Image.\n% Structure: Matrix (numRows x numCols).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - mH - Filtering Kernel.\n% Structure: Matrix.\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - convShape - Convolution Shape.\n% Sets the convolution shape.\n% Structure: Scalar.\n% Type: 'Single' / 'Double'.\n% Range: {1, 2, 3}.\n% Output:\n% - mI - Output Image.\n% Structure: Matrix.\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% References:\n% 1. MATLAB's 'conv2()' - https://www.mathworks.com/help/matlab/ref/conv2.html.\n% Remarks:\n% 1. For the transformation the (0, 0) of the image and the kernel is\n% the top left corner of teh matrix (i = 1, j = 1). Hence it can be\n% thought that a shifting is needed (To center the kernel).\n% 1. The function supports single channel image only.\n% TODO:\n% 1. \n% Release Notes:\n% - 1.0.000 29/04/2021 Royi Avital RoyiAvital@yahoo.com\n% * First release version.\n% ----------------------------------------------------------------------------------------------- %\n\nCONV_SHAPE_FULL = 1;\nCONV_SHAPE_SAME = 2;\nCONV_SHAPE_VALID = 3;\n\nnumRows = size(mI, 1);\nnumCols = size(mI, 2);\n\nnumRowsKernel = size(mH, 1);\nnumColsKernel = size(mH, 2);\n\nswitch(convShape)\n case(CONV_SHAPE_FULL)\n numRowsFft = numRows + numRowsKernel - 1;\n numColsFft = numCols + numColsKernel - 1;\n firstRowIdx = 1;\n firstColIdx = 1;\n lastRowIdx = numRowsFft;\n lastColdIdx = numColsFft;\n case(CONV_SHAPE_SAME)\n numRowsFft = numRows + numRowsKernel;\n numColsFft = numCols + numColsKernel;\n firstRowIdx = ceil((numRowsKernel + 1) / 2);\n firstColIdx = ceil((numColsKernel + 1) / 2);\n lastRowIdx = firstRowIdx + numRows - 1;\n lastColdIdx = firstColIdx + numCols - 1;\n case(CONV_SHAPE_VALID)\n numRowsFft = numRows;\n numColsFft = numCols;\n firstRowIdx = numRowsKernel;\n firstColIdx = numColsKernel;\n lastRowIdx = numRowsFft;\n lastColdIdx = numColsFft;\nend\n\nmO = ifft2(fft2(mI, numRowsFft, numColsFft) .* fft2(mH, numRowsFft, numColsFft), 'symmetric');\nmO = mO(firstRowIdx:lastRowIdx, firstColIdx:lastColdIdx);\n\n\nend\n\n", "meta": {"author": "RoyiAvital", "repo": "StackExchangeCodes", "sha": "d2a934616995fa8a9f4df1ca29029402435b9e6f", "save_path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes", "path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes/StackExchangeCodes-d2a934616995fa8a9f4df1ca29029402435b9e6f/SignalProcessing/Q74803/ImageConvFrequencyDomain.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951552333004, "lm_q2_score": 0.8757870029950159, "lm_q1q2_score": 0.8183311326148348}} {"text": "%\n% Written by M. Harper Langston - 5/10/00\n% harper@cims.nyu.edu\n%\n% Using Lemma 10.5, form the orthogonal matrix, Q, the block matrix of \n% matrices of eigenvectors of a TST block matrix. Then use this to form Gamma\n% See Iselres page 246 or Lemma 10.5 for more info for Q.\n% Gamma will be transformed into a plain tridiagonal matrix, using the method\n% in Iserles, page 247 and 249.\nfunction [Gam] = Form_Gamma(m,N)\nfor j = 1:m\n for k = 1:m\n Q(j,k) = sqrt(2/(m+1))*sin(pi*j*k/(m+1));\n end\nend\n% Now, form Gamma. As per Iserles, page 247, we can rearrange columns into\n% rows of the vectors, so Gamma will be tridiagonal. The only difference is\n% that in the problem, Gamma*t = c, solving for t, c must be converted and\n% then t will have to be converted back. See Iselres, pages 247 and 249\n% for more informtion.\nif N==9 | N==10\n\tS = (diag((-10/3)*ones(m,1)) + diag((2/3)*ones(m-1,1),1) + diag((2/3)*ones(m-1,1),-1));\n T = (diag((2/3)*ones(m,1)) + diag((1/6)*ones(m-1,1),1) + diag((1/6)*ones(m-1,1),-1));\nelseif N==5\n S = (diag((-4)*ones(m,1)) + diag((1)*ones(m-1,1),1) + diag((1)*ones(m-1,1),-1));\n T = diag((1)*ones(m,1));\nelseif N==101 % N = 101 is called by Modified_Right.m only, to speed up\n % the modified 9=point scheme\n S = (diag((2/3)*ones(m,1)) + diag((1/12)*ones(m-1,1),1) + diag((1/12)*ones(m-1,1),-1));\n T = (diag((1/12)*ones(m,1)));\nelse\n error('Must either use 5 or 9-point scheme (N=5 or N=9 in poisson.m)');\nend\n% inv(Q) = Q, so don't need to invert Q to diagonalize S and T\nGS = diag(Q*S*Q);\nGT = diag(Q*T*Q);\nGam = sparse(zeros(size(Q)));\nfor j = 1:m\n temp = (j-1)*m +1;\n Gam(temp:j*m,temp:j*m) = diag(GS(j)*ones(m,1)) ...\n\t + diag((GT(j))*ones(m-1,1),1) + diag((GT(j))*ones(m-1,1),-1);\nend\nGam = sparse(Gam);\n%\n% Written by M. Harper Langston - 5/10/00\n% harper@cims.nyu.edu\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/21472-2d-fast-poisson-solver/Form_Gamma.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951552333004, "lm_q2_score": 0.8757869867849167, "lm_q1q2_score": 0.8183311174681966}} {"text": "function chebyshev_polynomial_test01 ( )\n\n%*****************************************************************************80\n%\n%% CHEBYSHEV_POLYNOMIAL_TEST01 tests T_PROJECT_COEFFICIENTS_DATA.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 April 2012\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'CHEBYSHEV_POLYNOMIAL_TEST01:\\n' );\n fprintf ( 1, ' T_PROJECT_COEFFICIENTS_DATA estimates the Chebyshev polynomial\\n' );\n fprintf ( 1, ' coefficients for a function given as data (x,fx).\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Here, we use fx = f(x) = x^2 for the data.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Since T(0,x) = 1 and T(2,x) = 2*x^2 - 1, the correct expansion is\\n' );\n fprintf ( 1, ' f(x) = 1/2 T(0,x) + 0 T(1,x) + 1/2 T(2,x) + 0 * all other polys.\\n' );\n%\n% Data in [0,1];\n%\n a = 0.0;\n b = 1.0;\n m = 20;\n seed = 123456789;\n [ x, seed ] = r8vec_uniform_01 ( m, seed );\n d = x.^2;\n\n r8vec2_print ( m, x, d, ' Data ( X, D ):' );\n\n n = 4;\n c = t_project_coefficients_data ( a, b, m, n, x, d );\n \n r8vec_print ( n, c, ' Coefficients of Chebyshev expansion of degree 4.' );\n%\n% Compare Chebyshev expansion and original function.\n%\n d2 = t_project_value ( m, n, x, c );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' I X(I) Data(I) Chebyshev(X(I))\\n' );\n fprintf ( 1, '\\n' );\n for i = 1 : m\n fprintf ( 1, ' %2d %12g %12g %12g\\n', i, x(i), d(i), d2(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/chebyshev_polynomial/chebyshev_polynomial_test01.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.9073122182277756, "lm_q1q2_score": 0.818323649687513}} {"text": "function f = local ( m, x )\n\n%*****************************************************************************80\n%\n%% LOCAL computes the local function.\n%\n% Discussion:\n%\n% This function has a local minimizer:\n%\n% X* = ( 0.2858054412..., 0.2793263206...), F(X*) = 5.9225...\n%\n% and a global minimizer:\n%\n% X* = ( -21.02667179..., -36.75997872...), F(X*) = 0.\n%\n% Suggested starting point for local minimizer:\n%\n% X = ( 1, 1 ), F(X) = 3.33 * 10^6.\n%\n% Suggested starting point for global minimizer:\n%\n% X = ( -15, -35), F(X) = 1.49 * 10^8.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 04 January 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% David Himmelblau,\n% Applied Nonlinear Programming,\n% McGraw Hill, 1972,\n% ISBN13: 978-0070289215,\n% LC: T57.8.H55.\n%\n% Parameters:\n%\n% Input, integer M, the number of variables.\n%\n% Input, real X(M), the argument of the function.\n%\n% Output, real F, the value of the function at X.\n%\n f = ( x(1)^2 + 12.0 * x(2) - 1.0 )^2 ...\n + ( 49.0 * x(1)^2 + 49.0 * x(2)^2 + 84.0 * x(1) + 2324.0 * x(2) - 681.0 )^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/compass_search/local.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913343093499, "lm_q2_score": 0.8705972751232809, "lm_q1q2_score": 0.8182859953492136}} {"text": "function [J, grad] = lrCostFunction(theta, X, y, lambda)\n%LRCOSTFUNCTION Compute cost and gradient for logistic regression with %regularization\n% J = LRCOSTFUNCTION(theta, X, y, lambda) computes the cost of using\n% theta as the parameter for regularized logistic regression and the\n% gradient of the cost w.r.t. to the parameters.\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly\nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n% Hint: The computation of the cost function and gradients can be\n% efficiently vectorized. For example, consider the computation\n%\n% sigmoid(X * theta)\n%\n% Each row of the resulting matrix will contain the value of the\n% prediction for that example. You can make use of this to vectorize\n% the cost function and gradient computations.\n%\n% Hint: When computing the gradient of the regularized cost function,\n% there're many possible vectorized solutions, but one solution\n% looks like:\n% grad = (unregularized gradient for logistic regression)\n% temp = theta;\n% temp(1) = 0; % because we don't add anything for j = 0\n% grad = grad + YOUR_CODE_HERE (using the temp variable)\n%\n\n% Cost function\nh = sigmoid(X * theta);\ntheta1 = [0; theta(2:size(theta)) ];\n\ncost = (1 / m) * sum( (-y .* log(h)) - ((1 - y) .* log(1 - h)) );\nreg_cost = (lambda / (2 * m)) .* (theta1' * theta);\n\nJ = cost + reg_cost;\n\ngrad = (1 / m) * X' * (h - y);\nreg_grad = (lambda / m) .* theta1;\n\ngrad = grad + reg_grad;\n\n\n\n% =============================================================\n\ngrad = grad(:);\n\nend\n", "meta": {"author": "fewtime", "repo": "ML", "sha": "fd9679e9d6648d01e36047e97434f38c8d2d6168", "save_path": "github-repos/MATLAB/fewtime-ML", "path": "github-repos/MATLAB/fewtime-ML/ML-fd9679e9d6648d01e36047e97434f38c8d2d6168/coursera-machine-learning/machine-learning-ex3/ex3/lrCostFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8705972566572504, "lm_q1q2_score": 0.8182859838540355}} {"text": "function [ X,i ] = gmm_sample(nbSamples,Priors,Mu,Sigma )\n%GMM_SAMPLE Samples points from a Gaussian Mixture Model\n%\n% input -----------------------------------------------------------------\n%\n% o nbSamples : (1 x 1), number of samples to return\n%\n% o Priors : (1 x K), gmm weights\n% \n% o Mu : (D x K), gmm means\n%\n% o Sigma : (D x D x K), gmm covariance\n% \n% output ----------------------------------------------------------------\n%\n% o X : (D x N), N samples of dimension D\n%\n% o i : (N x 1), index of Gaussian center from which the data\n% points were sampled form.\n\nD = size(Mu,1);\nX = zeros(D,nbSamples);\n \ni = discretesample(Priors', nbSamples);\n \nif D == 1\n \n for v=1:nbSamples\n \n X(v) = normrnd(Mu(i(v)), sqrt(Sigma(i(v))) ); \n \n end \nelse\n \n for v = 1:nbSamples\n j = i(v);\n X(:,v) = mvnrnd(Mu(:,j),Sigma(:,:,j));\n end\n \nend\n\n\nend\n\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/gmmbox/GMMfunctions/GMM_functions/gmm_sample.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632316144275, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.8182823173733184}} {"text": "function pSum=polySum(p1,p2)\n%%POLYSUM Add together two vectors representing 1D polynomials as power\n% series. The format of the polynomial vectors is the same as that\n% used in Matlab's polyval function: The coefficients are ordered\n% y(z)=p(end)+p(end-1)*z+p(end-2)*z^2+...\n%\n%INPUTS: p1,p2 Coefficients for the two power series. The number of terms\n% in the different series can be different. Thus p1 and p2 do\n% not have the same length. p1(1) is the coefficient of the\n% highest order term. p(end) is the additive constant term. p1\n% and p2 can be row or column vectors.\n%\n%OUTPUTS: pSum A column vector holding the sum of p1 and p2. The first\n% element corresponds to the highest term, as used in Matlab's\n% polyval function. Note that the vector is not shortened when\n% the sum of high order terms equals zero (terms cancel).\n%\n%Polynomials are summed by adding corresponding terms.\n%\n%As an example, consider adding \n%x^2-3*x+2\n%to\n%x^5+3*x^3-4*x^2+1\n%This is done as\n% p1=[1;-3;2];\n% p2=[1;0;3;-4;0;1];\n% pSum=polySum(p1,p2)\n%One will see that the result is pSum'=[1,0,3,-3,-3,3], which corresponds\n%to x^5+3*x^3-3*x^2-3*x+3.\n%\n%August 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\npSum=[zeros(length(p1)-length(p2),1);p2(:)]+[zeros(length(p2)-length(p1),1);p1(:)];\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/polySum.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.9005297847831081, "lm_q1q2_score": 0.8182374769466134}} {"text": "function y = sumlogs(x,dim)\n%SUMLOGS Sum of elements where numbers are represented by their logarithms.\n%\n% Description\n% C=SUMLOGS(A) computes C=log(sum(exp(A))) in such a fashion\n% that it works even when elements have large magnitude.\n%\n% C=SUMLOGS(A,DIM) sums along the dimension DIM. \n%\n% See also SUM\n%\n% Copyright (c) 2013 Aki Vehtari\n\n% This software is distributed under the GNU General Public\n% License (version 3 or later); please refer to the file\n% License.txt, included with the software, for details.\n\nif nargin<2\n dim=find(size(x)>1,1);\nend\nmaxx=max(x(:));\ny=maxx+log(sum(exp(x-maxx),dim));\n", "meta": {"author": "gpstuff-dev", "repo": "gpstuff", "sha": "114937ec0a201306489a66cbba38283e722fb998", "save_path": "github-repos/MATLAB/gpstuff-dev-gpstuff", "path": "github-repos/MATLAB/gpstuff-dev-gpstuff/gpstuff-114937ec0a201306489a66cbba38283e722fb998/misc/sumlogs.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533088603708, "lm_q2_score": 0.8774767810736693, "lm_q1q2_score": 0.8182061279602901}} {"text": "\n\nfunction call_price=bs_european_call(S, K, r, sigma, time)\n\n\n%--------------------------------------------------------------------------\n%\n% DESCRIPTION:\n%\n% European put option using Black-Scholes' formula\n%\n%\n% Reference:\n%\n% John Hull, \"Options, Futures and other Derivative Securities\",\n% Prentice-Hall, second edition, 1993.\n%\n%--------------------------------------------------------------------------\n%\n% INPUTS:\n%\n% S: spot price\n% K: strike price\n% r: interest rate\n% sigma: volatility\n% time: time to maturity\n%\n%--------------------------------------------------------------------------\n%\n% OUTPUT:\n%\n% call_price: price of a call option\n%\n%--------------------------------------------------------------------------\n%\n% Author: Paolo Z., February 2012\n%\n%--------------------------------------------------------------------------\n\n\ntime_sqrt = sqrt(time);\n\nd1 = (log(S/K)+r*time)/(sigma*time_sqrt)+0.5*sigma*time_sqrt;\nd2 = d1-(sigma*time_sqrt);\n\ncall_price = S*normcdf(d1)-K*exp(-r*time)*normcdf(d2);\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/35351-option-pricing-package/bs_european_call.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9559813488829418, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.8181777321633398}} {"text": "function P = xyz2polar(X)\n% XYZ2POLAR Transformation of cartesian coordinates to polar coordinates.\n% ------------------------------------------------------------------------------\n% DESCRIPTION/NOTES\n% Transformation of cartesian coordinates [x, y, z] to polar coordinates\n% [distance, horizontal angle, vertical angle].\n% ------------------------------------------------------------------------------\n% INPUT\n% X\n% Matrix of cartesian coordinates x, y and z. Each point in a row.\n% ------------------------------------------------------------------------------\n% OUTPUT\n% P\n% Matrix of polar coordinates distace, horizontal angle and vertical angle.\n% Each point in a row.\n% Horizontal angle is defined mathematically positive starting from x-axis.\n% Vertical angle is defined as angle between point and zenith.\n% ------------------------------------------------------------------------------\n% EXAMPLES\n% Transformation of randomly generated points into polar coordinates and back.\n% X1 = [rand(10,1)*10 rand(10,1)*5 rand(10,1)];\n% P = xyz2polar(X1);\n% X2 = polar2xyz(P);\n% Diff = X1-X2;\n% ------------------------------------------------------------------------------\n% philipp.glira@gmail.com\n% ------------------------------------------------------------------------------\n\n% Input parsing ----------------------------------------------------------------\n\np = inputParser;\np.addRequired('X', @(x) isreal(x) && size(x,2) == 3);\np.parse(X);\np = p.Results;\n% Clear required inputs to avoid confusion\nclear X\n\n% Distance ---------------------------------------------------------------------\n\nd = sqrt(p.X(:,1).^2 + p.X(:,2).^2 + p.X(:,3).^2);\n\n% Vertical angle ---------------------------------------------------------------\n\nva = acosg(p.X(:,3) ./ d); % always positive [0,200]\n\n% Horizontal angle -------------------------------------------------------------\n\n% Compute all 4 solutions for the horizontal angle\nhSol(:,1) = acosg( p.X(:,1) ./ (d.*sing(va)) ); % sol1: always positive [ 0,200]\nhSol(:,2) = 400 - hSol(:,1); % sol2: always positive [ 200,400]\nhSol(:,3) = asing( p.X(:,2) ./ (d.*sing(va)) ); % sol3: can be negative [-100,100]\nhSol(:,4) = 200 - hSol(:,3); % sol4: always positive [ 100,300]\n\n% Eliminate complex part (occure if argument of acosg/asing is not in range\n% [-1, 1]); should be the case just for few points\nhSol = real(hSol);\n\n% If some values of sol3 are negativ, transform them into positive range\nidxNeg = hSol(:,3) < 0;\nhSol(idxNeg,3) = hSol(idxNeg,3) + 400; % now positive\n\n% Compute the differences between the solutions\n% Pairs for comparisons: 1,3 1,4 2,3 2,4\ndiff = [hSol(:,1)-hSol(:,3), hSol(:,1)-hSol(:,4), hSol(:,2)-hSol(:,3), hSol(:,2)-hSol(:,4)];\n% Find for each point the pair with the lowest difference\n[~, idx] = min(abs(diff), [], 2); \n\n% If pair 1 (1,3) take column 1 of hSol (i.e. sol1)\n% If pair 2 (1,4) take column 1 of hSol (i.e. sol1)\n% If pair 3 (2,3) take column 2 of hSol (i.e. sol2)\n% If pair 4 (2,4) take column 2 of hSol (i.e. sol2)\nidx(idx == 2) = 1;\nidx(idx == 3) = 2;\nidx(idx == 4) = 2;\n\n% Convert subscripts to linear indices to access the elements\nidxLin = sub2ind(size(hSol), [1:size(hSol,1)]', idx);\n\n% Get values\nha = hSol(idxLin);\n\n% Output -----------------------------------------------------------------------\n\nP = [d ha va];\n\nend", "meta": {"author": "pglira", "repo": "Point_cloud_tools_for_Matlab", "sha": "4768f45e7d3527c52e911eb0450c31ca19b58f72", "save_path": "github-repos/MATLAB/pglira-Point_cloud_tools_for_Matlab", "path": "github-repos/MATLAB/pglira-Point_cloud_tools_for_Matlab/Point_cloud_tools_for_Matlab-4768f45e7d3527c52e911eb0450c31ca19b58f72/functions/xyz2polar.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551546097941, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.8181660681743175}} {"text": "function p = norm_density(x, mu, sigma)\n% Compute density of normal distribution function\n%\n% file: \tnorm_density.m, (c) Matthew Roughan, Tue Jul 21 2009\n% directory: /home/mroughan/src/matlab/NUMERICAL_ROUTINES/\n% created: \tTue Jul 21 2009 \n% author: \tMatthew Roughan \n% email: \tmatthew.roughan@adelaide.edu.au\n% \n% Calculate normal density in 1D.\n% \n% INPUTS:\n% x = a vector of points at which to calculate the normal CDF \n% mu = mean of the normal\n% sigma = std dev. of the normal\n%\n%\np = exp( -(x-mu).^2 / (2*sigma^2) ) / (sigma * sqrt(2*pi) );\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/24867-gaussianmixturemodel-m/norm_density.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541626630937, "lm_q2_score": 0.8688267660487572, "lm_q1q2_score": 0.818134340882926}} {"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% X.shape=[nm, n]; Theta.shape=[nu, n]\n% Y.shape=[nm, nu];\nJ = 1.0 / 2 * sum(sum(R.*(X*Theta'-Y).^2));\nJ = J + lambda/2*sum(sum(Theta.^2)) + lambda/2*sum(sum(X.^2));\n\n% X_grad.shape=[nm, n]; Theta.grad.shape=[nu, 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\n\n\n\n\n\n% =============================================================\n\ngrad = [X_grad(:); Theta_grad(:)];\n\nend\n", "meta": {"author": "imLogM", "repo": "Machine_Learning_AndrewNg", "sha": "1d499e8e2738032dc85e869ba55c32eb24da288d", "save_path": "github-repos/MATLAB/imLogM-Machine_Learning_AndrewNg", "path": "github-repos/MATLAB/imLogM-Machine_Learning_AndrewNg/Machine_Learning_AndrewNg-1d499e8e2738032dc85e869ba55c32eb24da288d/machine-learning-ex8/ex8/cofiCostFunc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464796, "lm_q2_score": 0.8918110375304408, "lm_q1q2_score": 0.8180606385907441}} {"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 S = (1 / m) * (X' * (X * theta - y));\n theta = theta - alpha .* S;\n\n\n\n\n\n\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": "Ayatans", "repo": "Machine-Learning-homework", "sha": "4550cfc0426c9da8072dff165130fff40d138c10", "save_path": "github-repos/MATLAB/Ayatans-Machine-Learning-homework", "path": "github-repos/MATLAB/Ayatans-Machine-Learning-homework/Machine-Learning-homework-4550cfc0426c9da8072dff165130fff40d138c10/machine-learning-ex1/ex1/gradientDescentMulti.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.8179396351977082}} {"text": "function cdf = empirical_discrete_cdf ( x, a, b, c )\n\n%*****************************************************************************80\n%\n%% EMPIRICAL_DISCRETE_CDF evaluates the Empirical Discrete CDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 09 October 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the CDF.\n%\n% Input, integer A, the number of values.\n% 0 < A.\n%\n% Input, real B(A), the weights of each value.\n% 0 <= B(1:A) and at least one value is nonzero.\n%\n% Input, real C(A), the values.\n% The values must be distinct and in ascending order.\n%\n% Output, real CDF, the value of the CDF.\n%\n cdf = 0.0;\n\n bsum = sum ( b(1:a) );\n\n for i = 1 : a\n\n if ( x < c(i) )\n return\n end\n\n cdf = cdf + b(i) / bsum;\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/prob/empirical_discrete_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629194, "lm_q2_score": 0.8670357512127872, "lm_q1q2_score": 0.8179160786016539}} {"text": "function h = orientedGaussianKernel(size, sigma, theta)\n%ORIENTEDGAUSSIANKERNEL Oriented Gaussian kernel for directional filtering\n%\n% H = orientedGaussianKernel(SIZE, SIGMA, THETA)\n% THETA is in degrees.\n%\n% Example\n% orientedGaussianKernel\n%\n% See also\n% imDirectionalFilter, orientedLaplacianKernel, imfilter\n\n% ------\n% Author: David Legland\n% e-mail: david.legland@grignon.inra.fr\n% Created: 2012-12-04, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2012 INRA - Cepia Software Platform.\n\n% ensure size is a vector\nif length(size) == 1\n size = [size size];\nend\n\n% ensure sigma is a vector\nif length(sigma) == 1\n sigma = [sigma sigma];\nend\n\n% compute reference for each axis\nnx = round((size(1) - 1) / 2);\nny = round((size(2) - 1) / 2);\n\n% create 3D grid\n[x, y] = meshgrid(-nx:nx, -ny:ny);\n\n% precompute angles\ncot = cosd(-theta);\nsit = sind(-theta);\n\n% Apply rotation by -theta\nx2 = x * cot - y * sit;\ny2 = x * sit + y * cot;\n\n% compute gaussian function for each point of the grid\nsx2 = 2 * sigma(1) ^ 2;\nsy2 = 2 * sigma(2) ^ 2;\nh = exp(-(x2.^2 / sx2)) .* exp(-(y2.^2 / sy2));\n\n% normalize intensities\nh = h / (sum(h(:)));\n\n", "meta": {"author": "mattools", "repo": "matImage", "sha": "94d892c7beac0db32daadf2646ce37f58e894caf", "save_path": "github-repos/MATLAB/mattools-matImage", "path": "github-repos/MATLAB/mattools-matImage/matImage-94d892c7beac0db32daadf2646ce37f58e894caf/matImage/imFilters/orientedGaussianKernel.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088005554476, "lm_q2_score": 0.880797068590724, "lm_q1q2_score": 0.8177397499830684}} {"text": "function [ v_weight, predecessor ] = bellman_ford ( v_num, e_num, source, ...\n e, e_weight )\n\n%*****************************************************************************80\n%\n% Purpose:\n%\n% BELLMAN_FORD finds shortest paths from a given vertex of a weighted directed graph.\n%\n% Discussion:\n%\n% The Bellman-Ford algorithm is used.\n%\n% Each edge of the graph has a weight, which may be negative. However,\n% it should not be the case that there is any negative loop, that is,\n% a circuit whose total weight is negative.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 November 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer V_NUM, the number of vertices.\n%\n% Input, integer E_NUM, the number of edges.\n%\n% Input, integer SOURCE, the vertex from which distances will \n% be calculated.\n%\n% Input, integer E(2,E_NUM), the edges, given as pairs of \n% vertex indices.\n%\n% Input, real E_WEIGHT(E_NUM), the weight of each edge.\n%\n% Output, real V_WEIGHT(V_NUM), the weight of each node, \n% that is, its minimum distance from SOURCE.\n%\n% Output, integer PREDECESSOR(V_NUM), a list of predecessors, \n% which can be used to recover the shortest path from any node back to SOURCE.\n% \n r8_big = 1.0E+30;\n%\n% Step 1: initialize the graph.\n%\n v_weight(1:v_num) = r8_big;\n v_weight(source) = 0.0;\n\n predecessor(1:v_num) = -1;\n%\n% Step 2: Relax edges repeatedly.\n%\n for i = 1 : v_num - 1\n for j = 1 : e_num\n u = e(2,j);\n v = e(1,j);\n t = v_weight(u) + e_weight(j);\n if ( t < v_weight(v) )\n v_weight(v) = t;\n predecessor(v) = u;\n end\n end\n end\n%\n% Step 3: check for negative-weight cycles\n%\n for j = 1 : e_num\n u = e(2,j);\n v = e(1,j);\n if ( v_weight(u) + e_weight(j) < v_weight(v) )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BELLMAN_FORD - Fatal error!\\n' );\n fprintf ( 1, ' Graph contains a cycle with negative weight.\\n' );\n error ( 'BELLMAN_FORD - Fatal error!' );\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/bellman_ford/bellman_ford.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.8902942312159383, "lm_q1q2_score": 0.8177176687013962}} {"text": "function [ mO ] = CompressImageSvd( mI, energyThr, blockRadius )\n% ----------------------------------------------------------------------------------------------- %\n% [ mO ] = CompressImageSvd( mI, energyThr, blockRadius )\n% Compresses the image using SVD.\n% Input:\n% - mI - Input Image.\n% Structure: Image Matrix (Signle Channel or RGB).\n% Type: 'Single' / 'Double'.\n% Range: [0, 1].\n% - energyThr - Energy Threshold.\n% Sets the threshold for Singular Value kept energy.\n% Structure: Scalar.\n% Type: 'Single' / 'Double'.\n% Range: [0, 1].\n% - blockRadius - Block Radius.\n% Sets the block radius for the compression.\n% Structure: Scalar.\n% Type: 'Single' / 'Double'.\n% Range: {1, 2, ...}.\n% Output:\n% - mO - Output Image.\n% Structure: Image Matrix (Signle Channel or RGB).\n% Type: 'Single' / 'Double'.\n% Range: [0, 1].\n% References\n% 1. SVD Wikipedia - https://en.wikipedia.org/wiki/Singular_value_decomposition.\n% Remarks:\n% 1. a\n% TODO:\n% 1. U.\n% Release Notes:\n% - 1.0.000 01/09/2017 Royi\n% * First release version.\n% ----------------------------------------------------------------------------------------------- %\n\nFALSE = 0;\nTRUE = 1;\n\nOFF = 0;\nON = 1;\n\nnumRows = size(mI, 1);\nnumCols = size(mI, 2);\nnumChan = size(mI, 3); %= energyThr, 1, 'first');\n \n vSingularValues(lastIdx + 1:end) = 0;\n % mS isn't necessarily square matrix. Hence only work on its main\n % diagonal.\n mS(1:length(vSingularValues), 1:length(vSingularValues)) = diag(vSingularValues);\n \n % Reconstruction of the image using \"Less Energy\".\n mColImage = mU * mS * mV.';\n \n % Restorig the original structure and the DC Level\n mO(:, :, ii) = col2im(mColImage, vBlockDim, vImageDim, 'distinct') + dcLevel;\n \nend\n\n\nend\n\n", "meta": {"author": "RoyiAvital", "repo": "StackExchangeCodes", "sha": "d2a934616995fa8a9f4df1ca29029402435b9e6f", "save_path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes", "path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes/StackExchangeCodes-d2a934616995fa8a9f4df1ca29029402435b9e6f/CodeReview/Q157459/CompressImageSvd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9643214491222696, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.8177134957153728}} {"text": "% this m-file calculates the real roots of the given polynomial using \n% newton raphson technique.this m-file calls the functions in the two m-files named as syn_division and\n% derivate.\n% coeff_function is the 1xn matrix conatining the coeff of the polynomial.\n% Keerthi Venkateswara Rao\nfunction [final_roots,functionvalue] = newton(coeff_function,initial_guess,error_tolerance,max_iterations)\niterations=0;\nmax_no_roots=size(coeff_function,2);\nfinal_roots=0;\nfunctionvalue=0; \nfor no_roots=1:max_no_roots-1\n fun_root_new=initial_guess;\n flag=1;\n coeff_der_function=derivate(coeff_function);\n order_fun=size(coeff_function,2);\n order_der_fun=size(coeff_der_function,2);\n while flag==1\n fun_root_old=fun_root_new;\n fx=0;\n dfx=0;\n nonzero=1;\n while nonzero==1\n powers=order_fun-1;\n for index=1:order_fun\n fx=fx+coeff_function(index)*fun_root_old^powers;\n powers=powers-1;\n end\n powers=order_der_fun-1;\n for index=1:order_der_fun\n dfx=dfx+coeff_der_function(index)*fun_root_old^powers;\n powers=powers-1;\n end\n if dfx==0\n fun_root_old=fun_root_old+1;\n else\n nonzero=0; \n end \n end\n iterations = iterations + 1;\n fun_root_new = fun_root_old - fx/dfx;\n if iterations >= max_iterations \n flag=0;\n elseif abs(fun_root_new-fun_root_old)<=error_tolerance \n flag=0;\n final_roots(no_roots)=fun_root_new;\n functionvalue(no_roots)=fx;\n end\n end\n coeff_function=syn_division(coeff_function,fun_root_new);\n end\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/4313-newton-raphson/newton.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620562254524, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.8176719784356788}} {"text": "function variance = bradford_variance ( a, b, c )\n \n%*****************************************************************************80\n%\n%% BRADFORD_VARIANCE returns the variance of the Bradford PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A, B, C, the parameters of the PDF.\n% A < B,\n% 0.0 < C.\n%\n% Output, real VARIANCE, the variance of the PDF.\n%\n variance = ( b - a )^2 * ...\n ( c * ( log ( c + 1.0 ) - 2.0 ) + 2.0 * log ( c + 1.0 ) ) ...\n / ( 2.0 * c * ( log ( c + 1.0 ) )^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/prob/bradford_variance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947055100816, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.8176321787571886}} {"text": "function p = triangle_circumcenter ( n, t )\n\n%*****************************************************************************80\n%\n%% TRIANGLE_CIRCUMCENTER computes the circumcenter of a triangle in ND.\n%\n% Discussion:\n%\n% Three ND points A, B and C lie on a circle.\n%\n% The circumcenter P has the formula\n%\n% P = ( Area ( PBC ) * A + Area ( APC) * B + Area ( ABP ) * C )\n% / ( Area ( PBC ) + Area ( APC ) + Area ( ABP ) )\n%\n% The details of the formula rely on information supplied\n% by Oscar Lanzi III.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 October 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the spatial dimension.\n%\n% Input, real T(N,3), the triangle vertices.\n%\n% Output, real P(N,1), the circumcenter of the triangle.\n%\n a = r8vec_normsq_affine ( n, t(1:n,2), t(1:n,3) );\n b = r8vec_normsq_affine ( n, t(1:n,3), t(1:n,1) );\n c = r8vec_normsq_affine ( n, t(1:n,1), t(1:n,2) );\n\n pbc = a * ( - a + b + c );\n apc = b * ( a - b + c );\n abp = c * ( a + b - c );\n\n p = zeros ( n, 1 );\n\n p(1:n,1) = ( pbc * t(1:n,1) + apc * t(1:n,2) + abp * t(1:n,3) ) ...\n / ( pbc + apc + abp );\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/triangle_circumcenter.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947086083138, "lm_q2_score": 0.8652240738888188, "lm_q1q2_score": 0.8176321715854625}} {"text": "function [logval val]=mndensity(x,mu,sigma,k)\n\n\n% function [logval val]=mndensity(x,mu,sigma,k)\n% computes the density of the multivariate normal distribution\n% uses the log of the density (a.2.1), split into several parts for computation ease\n% inputs: - vector 'x': the argument of the density function\n% - vector 'mu': the mean of the distribution\n% - matrix 'sigma': the covariance of the distribution\n% - integer 'k': the dimension of the argument vector\n% outputs: - scalar 'logval': the log of the density value\n% - scalar 'val': the density value\n\n\n\ntemp(1,1)=-(k/2)*log(2*pi);\ntemp(2,1)=-0.5*log(det(sigma));\ntemp(3,1)=-0.5*(x-mu)'*(sigma\\(x-mu));\n\n% temp(3,1)=-0.5*(x-mu)'*inv(sigma)*(x-mu);\n\nlogval=sum(temp);\nval=exp(logval);\n\n\n\n", "meta": {"author": "european-central-bank", "repo": "BEAR-toolbox", "sha": "f33aae80c40f7a2e78a54de99b2ce3663f59aa75", "save_path": "github-repos/MATLAB/european-central-bank-BEAR-toolbox", "path": "github-repos/MATLAB/european-central-bank-BEAR-toolbox/BEAR-toolbox-f33aae80c40f7a2e78a54de99b2ce3663f59aa75/tbx/bear/+bear/mndensity.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191271831558, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.8176109742318978}} {"text": "function n2 = dist2(x, c)\n%DIST2\tCalculates squared distance between two sets of points.\n%\n%\tDescription\n%\tD = DIST2(X, C) takes two matrices of vectors and calculates the\n%\tsquared Euclidean distance between them. Both matrices must be of\n%\tthe same column dimension. If X has M rows and N columns, and C has\n%\tL rows and N columns, then the result has M rows and L columns. The\n%\tI, Jth entry is the squared distance from the Ith row of X to the\n%\tJth row of C.\n% D(i,j) = norm(X(i,:)-C(j,:)).^2;\n%\n%\tSee also\n%\tGMMACTIV, KMEANS, RBFFWD\n%\n\n%\tCopyright (c) Christopher M Bishop, Ian T Nabney (1996, 1997)\n\n%\tDec 6, 2011: Modified by Da Kuang, with performance improvement.\n\n[ndata, dimx] = size(x);\n[ncentres, dimc] = size(c);\nif dimx ~= dimc\n\terror('Data dimension does not match dimension of centres')\nend\n\ntempx = full(sum(x.^2, 2));\ntempc = full(sum(c.^2, 2)');\n\nn2 = tempx(:, ones(1,ncentres)) + ...\n \t\ttempc(ones(1,ndata), :) - ...\n \t\t2.*(x*(c'));\n\n", "meta": {"author": "hiroyuki-kasai", "repo": "NMFLibrary", "sha": "ed44132dfe1b5495df685006b42259f0bd16bea3", "save_path": "github-repos/MATLAB/hiroyuki-kasai-NMFLibrary", "path": "github-repos/MATLAB/hiroyuki-kasai-NMFLibrary/NMFLibrary-ed44132dfe1b5495df685006b42259f0bd16bea3/auxiliary/similarity_matrix/dist2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.8740772368049822, "lm_q1q2_score": 0.817565097503379}} {"text": "function wval = lagrange_factor ( npol, xpol, nval, xval )\n\n%*****************************************************************************80\n%\n%% 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, integer NVAL, the number of evaluation points.\n%\n% Input, real XVA(NVAL), the points at which the Lagrange\n% factor is to be evaluated.\n%\n% Output, real WVAL(NVAL), the value of the Lagrange factor at XVAL.\n%\n wval = zeros ( nval, 1 );\n\n for ival = 1 : nval\n\n wval(ival) = prod ( xval(ival) - xpol(1:npol) );\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/sparse_grid_total_poly/lagrange_factor.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.8947894738180211, "lm_q1q2_score": 0.8175481419350211}} {"text": "function r=ksrlin(x,y,h,N)\n% KSRLIN Local linear kernel smoothing regression\n%\n% r=ksrlin(x,y) returns the local linear Gaussian kernel regression in\n% structure r such that r.f(r.x) = y(x) + e. The bandwidth and number of\n% samples are also stored in r.h and r.n respectively.\n%\n% r=ksrlin(x,y,h) performs the regression using the specified bandwidth, h.\n%\n% r=ksrlin(x,y,h,n) calculates the regression in n points (default n=100).\n%\n% Without output, ksrlin(x,y) or ksrlin(x,y,h) will display the regression\n% plot. \n%\n% Algorithm\n% The kernel regression is a non-parametric approach to\n% estimate the conditional expectation of a random variable:\n%\n% E(Y|X) = f(X)\n%\n% where f is a non-parametric function. The normal kernel regression is a\n% local constant estimator. The extension of local linear estimator is\n% obtained by solving the least squares problem:\n%\n% min sum (y-alpha-beta(x-X))^2 kerf((x-X)/h)\n%\n% The local linear estimator can be given an explicit formula\n%\n% f(x) = 1/n sum((s2-s1*(x-X)).*kerf((x-X)/h).*Y)/(s2*s0-s1^2)\n%\n%where si = sum((x-X)^i*kerf((x-X)/h))/n. Compare with local constant\n%estimator, the local linear estimator can improve the estimation near the\n%edge of the region over which the data have been collected.\n%\n% See also gkde, ksdensity, ksr\n\n% Reference:\n% Bowman, A.W. and Azzalini, A., Applied Smoothing Techniques for Data\n% Analysis, Clarendon Press, 1997 (p.50) \n\n% Example 1: smooth curve with noise\n%{\nx = 1:100;\ny = sin(x/10)+(x/50).^2;\nyn = y + 0.2*randn(1,100);\nr=ksrlin(x,yn);\nr1=ksr(x,yn); % downloadable from FEX ID 19195\nplot(x,y,'b-',x,yn,'co',r.x,r.f,'r--',r1.x,r1.f,'m-.','linewidth',2)\nlegend('true','data','local linear','local constant','location','northwest');\ntitle('Gaussian kernel regression')\n%}\n% Example 2: with missing data\n%{\nx = sort(rand(1,100)*99)+1;\ny = sin(x/10)+(x/50).^2;\ny(round(rand(1,20)*100)) = NaN;\nyn = y + 0.2*randn(1,100);\nr=ksrlin(x,yn);\nr1=ksr(x,yn); % downloadable from FEX ID 19195\nplot(x,y,'b-',x,yn,'co',r.x,r.f,'r--',r1.x,r1.f,'m-.','linewidth',2)\nlegend('true','data','local linear','local constant','location','northwest');\ntitle('Gaussian kernel regression with 20% missing data')\n%}\n\n% By Yi Cao at Cranfield University on 12 April 2008.\n%\n\n% Check input and output\nerror(nargchk(2,4,nargin));\nerror(nargoutchk(0,1,nargout));\nif numel(x)~=numel(y)\n error('x and y are in different sizes.');\nend\n\nx=x(:);\ny=y(:);\n% clean missing or invalid data points\ninv=(x~=x)|(y~=y)|(abs(x)==Inf)|(abs(y)==Inf);\nx(inv)=[];\ny(inv)=[];\n\n% Default parameters\nif nargin<4\n N=100;\nelseif ~isscalar(N)\n error('N must be a scalar.')\nend\nr.n=length(x);\nif nargin<3\n % optimal bandwidth suggested by Bowman and Azzalini (1997) p.31\n hx=median(abs(x-median(x)))/0.6745*(4/3/r.n)^0.2;\n hy=median(abs(y-median(y)))/0.6745*(4/3/r.n)^0.2;\n h=sqrt(hy*hx);\nelseif ~isscalar(h)\n error('h must be a scalar.')\nend\nr.h=h;\n\n% Gaussian kernel function\nkerf=@(z)exp(-z.*z/2)/sqrt(2*pi);\n\nr.x=linspace(min(x),max(x),N);\nr.f=zeros(1,N);\nfor k=1:N\n d=r.x(k)-x;\n z=kerf(d/h);\n s1=d.*z;\n s2=sum(d.*s1);\n s1=sum(s1);\n r.f(k)=sum((s2-s1*d).*z.*y)/(s2*sum(z)-s1*s1);\nend\n\n% Plot\nif ~nargout\n plot(r.x,r.f,'r',x,y,'bo')\n ylabel('f(x)')\n xlabel('x')\n title('Kernel Smoothing Regression');\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/19564-local-linear-kernel-regression/ksrlin.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676518712608, "lm_q2_score": 0.8947894625955064, "lm_q1q2_score": 0.8175481211649877}} {"text": "function cdf = half_normal_cdf ( x, a, b )\n\n%*****************************************************************************80\n%\n%% HALF_NORMAL_CDF evaluates the Half Normal CDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the CDF.\n%\n% Input, real A, B, the parameters of the PDF.\n% 0.0 < B.\n%\n% Output, real CDF, the value of the CDF.\n%\n if ( x <= a )\n cdf = 0.0;\n else\n cdf2 = normal_cdf ( x, a, b );\n cdf = 2.0 * cdf2 - 1.0;\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/prob/half_normal_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9489172601537142, "lm_q2_score": 0.8615382165412808, "lm_q1q2_score": 0.8175284839580695}} {"text": "function varargout = ackley(x)\n%ACKLEY Ackley's function\n\nif nargin == 0\n varargout{1} = [-8,-8]; % LB\n varargout{2} = [2,2]; % UB\n varargout{3} = [0,20]; % Zlim\n varargout{4} = [-26.5,60]; % view\n varargout{5} = [0,0]; % xmin\n varargout{6} = 'Ackley function'; % name\n varargout{7} = [-6,-5]; % default x0 \n return;\nend\n varargout{1} = -20 * exp(-0.2 * sqrt( sum(x .* x, 2)/ 2)) ...\n - exp(sum(cos(2*pi*x),2) / 2) ...\n + 20 + 2.7182818284590452353602874713526625;\n varargout{2} = [];\nend\n", "meta": {"author": "lacerbi", "repo": "optimviz", "sha": "2cc41c19ffeaaa9a23239f53d80691cf3599357d", "save_path": "github-repos/MATLAB/lacerbi-optimviz", "path": "github-repos/MATLAB/lacerbi-optimviz/optimviz-2cc41c19ffeaaa9a23239f53d80691cf3599357d/ackley.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.971129093889291, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.817521381881947}} {"text": "function [J, grad] = lrCostFunction(theta, X, y, lambda)\n%LRCOSTFUNCTION Compute cost and gradient for logistic regression with \n%regularization\n% J = LRCOSTFUNCTION(theta, X, y, lambda) computes the cost of using\n% theta as the parameter for regularized logistic regression and the\n% gradient of the cost w.r.t. to the parameters. \n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n\nhx = sigmoid(X * theta); %hypothesis, m * 1\n% Hint: The computation of the cost function and gradients can be\n% efficiently vectorized. For example, consider the computation\n%\n% sigmoid(X * theta)\n%\n% Each row of the resulting matrix will contain the value of the\n% prediction for that example. You can make use of this to vectorize\n% the cost function and gradient computations. \n%\nJ = 1 / m * sum(-y' * log(hx) - (1 - y)' * log(1 - hx)) + lambda / (2 * m) * theta(2:end)' * theta(2:end);\n\n% Hint: When computing the gradient of the regularized cost function, \n% there're many possible vectorized solutions, but one solution\n% looks like:\n% grad = (unregularized gradient for logistic regression)\n% temp = theta; \n% temp(1) = 0; % because we don't add anything for j = 0 \n% grad = grad + YOUR_CODE_HERE (using the temp variable)\n%\ngradf = (1 / m) * (X(:, 1)' * (hx - y));\ngradb = (1 / m) * (X(:, 2:end)' * (hx - y)) + lambda * theta(2:end) / m;\n\ngrad = [gradf;gradb];\nsize(grad)\n\n\n\n\n\n\n\n% =============================================================\n\ngrad = 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-ex3/ex3/lrCostFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308184368928, "lm_q2_score": 0.875787001374006, "lm_q1q2_score": 0.8174865774689306}} {"text": "function area = sphere_cap_area_nd ( ndim, r, h )\n\n%*****************************************************************************80\n%\n%% SPHERE_CAP_AREA_ND computes the area of a spherical cap in ND.\n%\n% Discussion:\n%\n% The spherical cap is a portion of the surface of the sphere:\n%\n% sum ( X(1:N)^2 ) = R^2\n%\n% which is no more than H units from the uppermost point on the sphere.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 18 July 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Thomas Ericson and Victor Zinoviev,\n% Codes on Euclidean Spheres,\n% Elsevier, 2001, pages 439-441.\n% QA166.7 E75\n%\n% Parameters:\n%\n% Input, integer NDIM, the dimension of the space.\n%\n% Input, real R, the radius of the sphere.\n%\n% Input, real H, the \"thickness\" of the spherical cap,\n% which is normally between 0 and 2 * R.\n%\n% Output, real AREA, the area of the spherical cap.\n%\n if ( h <= 0.0 )\n area = 0.0;\n return\n end\n\n if ( 2.0 * r <= h )\n area = sphere_area_nd ( ndim, r );\n return\n end\n%\n% For cases where R < H < 2 * R, work with the complementary region.\n%\n haver_sine = sqrt ( ( 2.0 * r - h ) * h );\n\n theta = r8_asin ( haver_sine / r );\n\n if ( ndim < 1 )\n\n area = -1.0;\n\n elseif ( ndim == 1 )\n\n area = 0.0;\n\n elseif ( ndim == 2 )\n\n area = 2.0 * theta * r;\n\n else\n\n ti = theta;\n\n tj = ti;\n ti = 1.0 - cos ( theta );\n\n for i = 2 : ndim-2\n tk = tj;\n tj = ti;\n ti = ( ( i - 1 ) * tk - cos ( theta ) * sin ( theta )^( i - 1 ) ) / i;\n end\n\n area = sphere_k ( ndim-1 ) * ti * r^( ndim - 1 );\n\n end\n%\n% Adjust for cases where R < H < 2R.\n%\n if ( r < h )\n area2 = sphere_area_nd ( ndim, r );\n area = area2 - area;\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/stroud/sphere_cap_area_nd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.8173367191433838}} {"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n%\n% \n% Problem 4\n% Inverse z-Transform computation of X(z)=(2z+3)/(z^2+5z+6)\n\n\n% a)in rational form\nsyms n z\nX=(2*z+3)/(z^2+5*z+6);\niztrans(X,n)\n\n\n% b) in partial fraction form \nnum=[ 2 3]\nden= [ 1 5 6];\n[R,P,K]=residue(num,den)\n\nX=3/(z+3)-1/(z+2)\niztrans(X,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/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/10/c108b.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966671870766, "lm_q2_score": 0.8633916134888614, "lm_q1q2_score": 0.8172836238058288}} {"text": "\n%\n% lellipf(phi, k, errtol)\n%\n% Inputs:\n%\n% phi Input angle vector size 1 or 1xN.\n% k Input parameter vector size 1 or 1xN.\n% errtol Error tolerance for Carlson's algorithms.\n%\n% Matlab function to compute Legendre's (incomplete) elliptic integral \n% F(phi, k). Uses a vectorized implementation of Carlson's Duplication Algorithms \n% for symmetric elliptic integrals as found in \"Computing Elliptic \n% Integrals by Duplication,\" by B. C. Carlson, Numer. Math. 33, 1-16 (1979)\n% and also found in ACM TOMS Algorithm 577. Section 4 in the paper cited\n% here describes how to convert between the symmetric elliptic integrals\n% and Legendre's elliptic integrals.\n%\n% Returns NaN's for any argument values outside input range.\n%\n\nfunction f = lellipf(phi, k, errtol)\n\n% Argument checking for vectorization:\nlphi = length(phi);\nlk = length(k);\nerrflag = logical(0);\nif (lphi ~= lk)\n if (lphi==1)\n phivec = phi * ones(1,lk);\n kvec = k;\n elseif (lk==1)\n kvec = k * ones(1,lphi);\n phivec = phi;\n else\n disp('Incompatible input vector dimensions in lellipf!');\n errflag = logical(1);\n end\nelse\n phivec = phi;\n kvec = k;\nend\n\nif ~errflag\n snphi = sin(phivec);\n csphi = cos(phivec);\n csphi2 = csphi .* csphi;\n onesvec = ones(1,length(phivec));\n y = onesvec - kvec.*kvec .* snphi.*snphi;\n f = snphi .* rf(csphi2, y, onesvec, errtol);\nelse\n f = NaN;\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/3705-ellipticintegrals-zip/Elliptic_Integrals/lellipf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966702001758, "lm_q2_score": 0.8633916064587, "lm_q1q2_score": 0.817283619752586}} {"text": "% Euclidean distance between polyhedra\n% Section 8.2.1, Boyd & Vandenberghe \"Convex Optimization\"\n% Joelle Skaf - 10/09/05\n%\n% Given two polyhedra C = {x | A1*x <= b1} and D = {x | A2*x <= b2}, the\n% distance between them is the optimal value of the problem:\n% minimize || x - y ||_2\n% s.t. A1*x <= b1\n% A2*y <= b2\n\n% Input data\nrandn('state',0);\nrand('state',0);\n\nn = 5;\nm1 = 2*n;\nm2 = 3*n;\nA1 = randn(m1,n);\nA2 = randn(m2,n);\nb1 = rand(m1,1);\nb2 = rand(m2,1) + A2*randn(n,1);\n\n% Solution via CVX\ncvx_begin\n variables x(n) y(n)\n minimize (norm(x - y))\n A1*x <= b1;\n A2*y <= b2;\ncvx_end\n\n% Displaying results\ndisp('------------------------------------------------------------------');\ndisp('The distance between the 2 polyhedra C and D is: ' );\ndisp(['dist(C,D) = ' num2str(cvx_optval)]);\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/Ch08_geometric_probs/eucl_dist_poly.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338101862455, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.8172760230785105}} {"text": "% Euclidean distance between polyhedra in 2D\n% Section 8.2.1, Boyd & Vandenberghe \"Convex Optimization\"\n% Joelle Skaf - 10/09/05\n% (a figure is generated)\n%\n% Given two polyhedra C = {x | A1*x <= b1} and D = {x | A2*x <= b2}, the\n% distance between them is the optimal value of the problem:\n% minimize || x - y ||_2\n% s.t. A1*x <= b1\n% A2*y <= b2\n% Note: here x is in R^2\n\n% Input data\nrandn('seed',0);\nn = 2;\nm = 2*n;\nA1 = randn(m,n);\nb1 = randn(m,1);\nA2 = randn(m,n);\nb2 = randn(m,1);\n\nfprintf(1,'Computing the distance between the 2 polyhedra...');\n% Solution via CVX\ncvx_begin\n variables x(n) y(n)\n minimize (norm(x - y))\n norm(x,1) <= 2; %#ok\n norm(y-[4;3],inf) <=1; %#ok\ncvx_end\n\nfprintf(1,'Done! \\n');\n\n% Displaying results\ndisp('------------------------------------------------------------------');\ndisp('The distance between the 2 polyhedra C and D is: ' );\ndisp(['dist(C,D) = ' num2str(cvx_optval)]);\ndisp('The optimal points are: ')\ndisp('x = '); disp(x);\ndisp('y = '); disp(y);\n\n%Plotting\nfigure;\nfill([-2; 0; 2; 0],[0;2;0;-2],'b', [3;5;5;3],[2;2;4;4],'r')\naxis([-3 6 -3 6])\naxis square\nhold on;\nplot(x(1),x(2),'k.')\nplot(y(1),y(2),'k.')\nplot([x(1) y(1)],[x(2) y(2)])\ntitle('Euclidean distance between 2 polyhedron in R^2');\nxlabel('x_1');\nylabel('x_2');\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/cvxbook/Ch08_geometric_probs/eucl_dist_poly_2D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542817548989, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.8171541706501743}} {"text": "function [out] = GLCM_Features1(glcmin,pairs)\n% \n% GLCM_Features1 helps to calculate the features from the different GLCMs\n% that are input to the function. The GLCMs are stored in a i x j x n\n% matrix, where n is the number of GLCMs calculated usually due to the\n% different orientation and displacements used in the algorithm. Usually\n% the values i and j are equal to 'NumLevels' parameter of the GLCM\n% computing function graycomatrix(). Note that matlab quantization values\n% belong to the set {1,..., NumLevels} and not from {0,...,(NumLevels-1)}\n% as provided in some references\n% http://www.mathworks.com/access/helpdesk/help/toolbox/images/graycomatrix\n% .html\n% \n% Although there is a function graycoprops() in Matlab Image Processing\n% Toolbox that computes four parameters Contrast, Correlation, Energy,\n% and Homogeneity. The paper by Haralick suggests a few more parameters\n% that are also computed here. The code is not fully vectorized and hence\n% is not an efficient implementation but it is easy to add new features\n% based on the GLCM using this code. Takes care of 3 dimensional glcms\n% (multiple glcms in a single 3D array)\n% \n% If you find that the values obtained are different from what you expect \n% or if you think there is a different formula that needs to be used \n% from the ones used in this code please let me know. \n% A few questions which I have are listed in the link \n% http://www.mathworks.com/matlabcentral/newsreader/view_thread/239608\n%\n% I plan to submit a vectorized version of the code later and provide \n% updates based on replies to the above link and this initial code. \n%\n% Features computed \n% Autocorrelation: [2] (out.autoc)\n% Contrast: matlab/[1,2] (out.contr)\n% Correlation: matlab (out.corrm)\n% Correlation: [1,2] (out.corrp)\n% Cluster Prominence: [2] (out.cprom)\n% Cluster Shade: [2] (out.cshad)\n% Dissimilarity: [2] (out.dissi)\n% Energy: matlab / [1,2] (out.energ)\n% Entropy: [2] (out.entro)\n% Homogeneity: matlab (out.homom)\n% Homogeneity: [2] (out.homop)\n% Maximum probability: [2] (out.maxpr)\n% Sum of sqaures: Variance [1] (out.sosvh)\n% Sum average [1] (out.savgh)\n% Sum variance [1] (out.svarh)\n% Sum entropy [1] (out.senth)\n% Difference variance [1] (out.dvarh)\n% Difference entropy [1] (out.denth)\n% Information measure of correlation1 [1] (out.inf1h)\n% Informaiton measure of correlation2 [1] (out.inf2h)\n% Inverse difference (INV) is homom [3] (out.homom)\n% Inverse difference normalized (INN) [3] (out.indnc) \n% Inverse difference moment normalized [3] (out.idmnc)\n%\n% The maximal correlation coefficient was not calculated due to\n% computational instability \n% http://murphylab.web.cmu.edu/publications/boland/boland_node26.html\n%\n% Formulae from MATLAB site (some look different from\n% the paper by Haralick but are equivalent and give same results)\n% Example formulae: \n% Contrast = sum_i(sum_j( (i-j)^2 * p(i,j) ) ) (same in matlab/paper)\n% Correlation = sum_i( sum_j( (i - u_i)(j - u_j)p(i,j)/(s_i.s_j) ) ) (m)\n% Correlation = sum_i( sum_j( ((ij)p(i,j) - u_x.u_y) / (s_x.s_y) ) ) (p[2])\n% Energy = sum_i( sum_j( p(i,j)^2 ) ) (same in matlab/paper)\n% Homogeneity = sum_i( sum_j( p(i,j) / (1 + |i-j|) ) ) (as in matlab)\n% Homogeneity = sum_i( sum_j( p(i,j) / (1 + (i-j)^2) ) ) (as in paper)\n% \n% Where:\n% u_i = u_x = sum_i( sum_j( i.p(i,j) ) ) (in paper [2])\n% u_j = u_y = sum_i( sum_j( j.p(i,j) ) ) (in paper [2])\n% s_i = s_x = sum_i( sum_j( (i - u_x)^2.p(i,j) ) ) (in paper [2])\n% s_j = s_y = sum_i( sum_j( (j - u_y)^2.p(i,j) ) ) (in paper [2])\n%\n% \n% Normalize the glcm:\n% Compute the sum of all the values in each glcm in the array and divide \n% each element by it sum\n%\n% Haralick uses 'Symmetric' = true in computing the glcm\n% There is no Symmetric flag in the Matlab version I use hence\n% I add the diagonally opposite pairs to obtain the Haralick glcm\n% Here it is assumed that the diagonally opposite orientations are paired\n% one after the other in the matrix\n% If the above assumption is true with respect to the input glcm then\n% setting the flag 'pairs' to 1 will compute the final glcms that would result \n% by setting 'Symmetric' to true. If your glcm is computed using the\n% Matlab version with 'Symmetric' flag you can set the flag 'pairs' to 0\n%\n% References:\n% 1. R. M. Haralick, K. Shanmugam, and I. Dinstein, Textural Features of\n% Image Classification, IEEE Transactions on Systems, Man and Cybernetics,\n% vol. SMC-3, no. 6, Nov. 1973\n% 2. L. Soh and C. Tsatsoulis, Texture Analysis of SAR Sea Ice Imagery\n% Using Gray Level Co-Occurrence Matrices, IEEE Transactions on Geoscience\n% and Remote Sensing, vol. 37, no. 2, March 1999.\n% 3. D A. Clausi, An analysis of co-occurrence texture statistics as a\n% function of grey level quantization, Can. J. Remote Sensing, vol. 28, no.\n% 1, pp. 45-62, 2002\n% 4. http://murphylab.web.cmu.edu/publications/boland/boland_node26.html\n%\n%\n% Example:\n%\n% Usage is similar to graycoprops() but needs extra parameter 'pairs' apart\n% from the GLCM as input\n% I = imread('circuit.tif');\n% GLCM2 = graycomatrix(I,'Offset',[2 0;0 2]);\n% stats = GLCM_features1(GLCM2,0)\n% The output is a structure containing all the parameters for the different\n% GLCMs\n%\n% [Avinash Uppuluri: avinash_uv@yahoo.com: Last modified: 11/20/08]\n\n% If 'pairs' not entered: set pairs to 0 \nif ((nargin > 2) || (nargin == 0))\n error('Too many or too few input arguments. Enter GLCM and pairs.');\nelseif ( (nargin == 2) ) \n if ((size(glcmin,1) <= 1) || (size(glcmin,2) <= 1))\n error('The GLCM should be a 2-D or 3-D matrix.');\n elseif ( size(glcmin,1) ~= size(glcmin,2) )\n error('Each GLCM should be square with NumLevels rows and NumLevels cols');\n end \nelseif (nargin == 1) % only GLCM is entered\n pairs = 0; % default is numbers and input 1 for percentage\n if ((size(glcmin,1) <= 1) || (size(glcmin,2) <= 1))\n error('The GLCM should be a 2-D or 3-D matrix.');\n elseif ( size(glcmin,1) ~= size(glcmin,2) )\n error('Each GLCM should be square with NumLevels rows and NumLevels cols');\n end \nend\n\n\nformat long e\nif (pairs == 1)\n newn = 1;\n for nglcm = 1:2:size(glcmin,3)\n glcm(:,:,newn) = glcmin(:,:,nglcm) + glcmin(:,:,nglcm+1);\n newn = newn + 1;\n end\nelseif (pairs == 0)\n glcm = glcmin;\nend\n\nsize_glcm_1 = size(glcm,1);\nsize_glcm_2 = size(glcm,2);\nsize_glcm_3 = size(glcm,3);\n\n% checked \nout.autoc = zeros(1,size_glcm_3); % Autocorrelation: [2] \nout.contr = zeros(1,size_glcm_3); % Contrast: matlab/[1,2]\nout.corrm = zeros(1,size_glcm_3); % Correlation: matlab\nout.corrp = zeros(1,size_glcm_3); % Correlation: [1,2]\nout.cprom = zeros(1,size_glcm_3); % Cluster Prominence: [2]\nout.cshad = zeros(1,size_glcm_3); % Cluster Shade: [2]\nout.dissi = zeros(1,size_glcm_3); % Dissimilarity: [2]\nout.energ = zeros(1,size_glcm_3); % Energy: matlab / [1,2]\nout.entro = zeros(1,size_glcm_3); % Entropy: [2]\nout.homom = zeros(1,size_glcm_3); % Homogeneity: matlab\nout.homop = zeros(1,size_glcm_3); % Homogeneity: [2]\nout.maxpr = zeros(1,size_glcm_3); % Maximum probability: [2]\n\nout.sosvh = zeros(1,size_glcm_3); % Sum of sqaures: Variance [1]\nout.savgh = zeros(1,size_glcm_3); % Sum average [1]\nout.svarh = zeros(1,size_glcm_3); % Sum variance [1]\nout.senth = zeros(1,size_glcm_3); % Sum entropy [1]\nout.dvarh = zeros(1,size_glcm_3); % Difference variance [4]\n%out.dvarh2 = zeros(1,size_glcm_3); % Difference variance [1]\nout.denth = zeros(1,size_glcm_3); % Difference entropy [1]\nout.inf1h = zeros(1,size_glcm_3); % Information measure of correlation1 [1]\nout.inf2h = zeros(1,size_glcm_3); % Informaiton measure of correlation2 [1]\n%out.mxcch = zeros(1,size_glcm_3);% maximal correlation coefficient [1]\n%out.invdc = zeros(1,size_glcm_3);% Inverse difference (INV) is homom [3]\nout.indnc = zeros(1,size_glcm_3); % Inverse difference normalized (INN) [3]\nout.idmnc = zeros(1,size_glcm_3); % Inverse difference moment normalized [3]\n\n% correlation with alternate definition of u and s\n%out.corrm2 = zeros(1,size_glcm_3); % Correlation: matlab\n%out.corrp2 = zeros(1,size_glcm_3); % Correlation: [1,2]\n\nglcm_sum = zeros(size_glcm_3,1);\nglcm_mean = zeros(size_glcm_3,1);\nglcm_var = zeros(size_glcm_3,1);\n\n% http://www.fp.ucalgary.ca/mhallbey/glcm_mean.htm confuses the range of \n% i and j used in calculating the means and standard deviations.\n% As of now I am not sure if the range of i and j should be [1:Ng] or\n% [0:Ng-1]. I am working on obtaining the values of mean and std that get\n% the values of correlation that are provided by matlab.\nu_x = zeros(size_glcm_3,1);\nu_y = zeros(size_glcm_3,1);\ns_x = zeros(size_glcm_3,1);\ns_y = zeros(size_glcm_3,1);\n\n% % alternate values of u and s\n% u_x2 = zeros(size_glcm_3,1);\n% u_y2 = zeros(size_glcm_3,1);\n% s_x2 = zeros(size_glcm_3,1);\n% s_y2 = zeros(size_glcm_3,1);\n\n% checked p_x p_y p_xplusy p_xminusy\np_x = zeros(size_glcm_1,size_glcm_3); % Ng x #glcms[1] \np_y = zeros(size_glcm_2,size_glcm_3); % Ng x #glcms[1]\np_xplusy = zeros((size_glcm_1*2 - 1),size_glcm_3); %[1]\np_xminusy = zeros((size_glcm_1),size_glcm_3); %[1]\n% checked hxy hxy1 hxy2 hx hy\nhxy = zeros(size_glcm_3,1);\nhxy1 = zeros(size_glcm_3,1);\nhx = zeros(size_glcm_3,1);\nhy = zeros(size_glcm_3,1);\nhxy2 = zeros(size_glcm_3,1);\n\n%Q = zeros(size(glcm));\n\nfor k = 1:size_glcm_3 % number glcms\n\n glcm_sum(k) = sum(sum(glcm(:,:,k)));\n glcm(:,:,k) = glcm(:,:,k)./glcm_sum(k); % Normalize each glcm\n glcm_mean(k) = mean2(glcm(:,:,k)); % compute mean after norm\n glcm_var(k) = (std2(glcm(:,:,k)))^2;\n \n for i = 1:size_glcm_1\n\n for j = 1:size_glcm_2\n\n out.contr(k) = out.contr(k) + (abs(i - j))^2.*glcm(i,j,k);\n out.dissi(k) = out.dissi(k) + (abs(i - j)*glcm(i,j,k));\n out.energ(k) = out.energ(k) + (glcm(i,j,k).^2);\n out.entro(k) = out.entro(k) - (glcm(i,j,k)*log(glcm(i,j,k) + eps));\n out.homom(k) = out.homom(k) + (glcm(i,j,k)/( 1 + abs(i-j) ));\n out.homop(k) = out.homop(k) + (glcm(i,j,k)/( 1 + (i - j)^2));\n % [1] explains sum of squares variance with a mean value;\n % the exact definition for mean has not been provided in \n % the reference: I use the mean of the entire normalized glcm \n out.sosvh(k) = out.sosvh(k) + glcm(i,j,k)*((i - glcm_mean(k))^2);\n \n %out.invdc(k) = out.homom(k);\n out.indnc(k) = out.indnc(k) + (glcm(i,j,k)/( 1 + (abs(i-j)/size_glcm_1) ));\n out.idmnc(k) = out.idmnc(k) + (glcm(i,j,k)/( 1 + ((i - j)/size_glcm_1)^2));\n u_x(k) = u_x(k) + (i)*glcm(i,j,k); % changed 10/26/08\n u_y(k) = u_y(k) + (j)*glcm(i,j,k); % changed 10/26/08\n % code requires that Nx = Ny \n % the values of the grey levels range from 1 to (Ng) \n end\n \n end\n out.maxpr(k) = max(max(glcm(:,:,k)));\nend\n% glcms have been normalized:\n% The contrast has been computed for each glcm in the 3D matrix\n% (tested) gives similar results to the matlab function\n\nfor k = 1:size_glcm_3\n \n for i = 1:size_glcm_1\n \n for j = 1:size_glcm_2\n p_x(i,k) = p_x(i,k) + glcm(i,j,k); \n p_y(i,k) = p_y(i,k) + glcm(j,i,k); % taking i for j and j for i\n if (ismember((i + j),[2:2*size_glcm_1])) \n p_xplusy((i+j)-1,k) = p_xplusy((i+j)-1,k) + glcm(i,j,k);\n end\n if (ismember(abs(i-j),[0:(size_glcm_1-1)])) \n p_xminusy((abs(i-j))+1,k) = p_xminusy((abs(i-j))+1,k) +...\n glcm(i,j,k);\n end\n end\n end\n \n% % consider u_x and u_y and s_x and s_y as means and standard deviations\n% % of p_x and p_y\n% u_x2(k) = mean(p_x(:,k));\n% u_y2(k) = mean(p_y(:,k));\n% s_x2(k) = std(p_x(:,k));\n% s_y2(k) = std(p_y(:,k));\n \nend\n\n% marginal probabilities are now available [1]\n% p_xminusy has +1 in index for matlab (no 0 index)\n% computing sum average, sum variance and sum entropy:\nfor k = 1:(size_glcm_3)\n \n for i = 1:(2*(size_glcm_1)-1)\n out.savgh(k) = out.savgh(k) + (i+1)*p_xplusy(i,k);\n % the summation for savgh is for i from 2 to 2*Ng hence (i+1)\n out.senth(k) = out.senth(k) - (p_xplusy(i,k)*log(p_xplusy(i,k) + eps));\n end\n\nend\n% compute sum variance with the help of sum entropy\nfor k = 1:(size_glcm_3)\n \n for i = 1:(2*(size_glcm_1)-1)\n out.svarh(k) = out.svarh(k) + (((i+1) - out.senth(k))^2)*p_xplusy(i,k);\n % the summation for savgh is for i from 2 to 2*Ng hence (i+1)\n end\n\nend\n% compute difference variance, difference entropy, \nfor k = 1:size_glcm_3\n% out.dvarh2(k) = var(p_xminusy(:,k));\n% but using the formula in \n% http://murphylab.web.cmu.edu/publications/boland/boland_node26.html\n% we have for dvarh\n for i = 0:(size_glcm_1-1)\n out.denth(k) = out.denth(k) - (p_xminusy(i+1,k)*log(p_xminusy(i+1,k) + eps));\n out.dvarh(k) = out.dvarh(k) + (i^2)*p_xminusy(i+1,k);\n end\nend\n\n% compute information measure of correlation(1,2) [1]\nfor k = 1:size_glcm_3\n hxy(k) = out.entro(k);\n for i = 1:size_glcm_1\n \n for j = 1:size_glcm_2\n hxy1(k) = hxy1(k) - (glcm(i,j,k)*log(p_x(i,k)*p_y(j,k) + eps));\n hxy2(k) = hxy2(k) - (p_x(i,k)*p_y(j,k)*log(p_x(i,k)*p_y(j,k) + eps));\n% for Qind = 1:(size_glcm_1)\n% Q(i,j,k) = Q(i,j,k) +...\n% ( glcm(i,Qind,k)*glcm(j,Qind,k) / (p_x(i,k)*p_y(Qind,k)) ); \n% end\n end\n hx(k) = hx(k) - (p_x(i,k)*log(p_x(i,k) + eps));\n hy(k) = hy(k) - (p_y(i,k)*log(p_y(i,k) + eps));\n end\n out.inf1h(k) = ( hxy(k) - hxy1(k) ) / ( max([hx(k),hy(k)]) );\n out.inf2h(k) = ( 1 - exp( -2*( hxy2(k) - hxy(k) ) ) )^0.5;\n% eig_Q(k,:) = eig(Q(:,:,k));\n% sort_eig(k,:)= sort(eig_Q(k,:),'descend');\n% out.mxcch(k) = sort_eig(k,2)^0.5;\n% The maximal correlation coefficient was not calculated due to\n% computational instability \n% http://murphylab.web.cmu.edu/publications/boland/boland_node26.html\nend\n\ncorm = zeros(size_glcm_3,1);\ncorp = zeros(size_glcm_3,1);\n% using http://www.fp.ucalgary.ca/mhallbey/glcm_variance.htm for s_x s_y\nfor k = 1:size_glcm_3\n for i = 1:size_glcm_1\n for j = 1:size_glcm_2\n s_x(k) = s_x(k) + (((i) - u_x(k))^2)*glcm(i,j,k);\n s_y(k) = s_y(k) + (((j) - u_y(k))^2)*glcm(i,j,k);\n corp(k) = corp(k) + ((i)*(j)*glcm(i,j,k));\n corm(k) = corm(k) + (((i) - u_x(k))*((j) - u_y(k))*glcm(i,j,k));\n out.cprom(k) = out.cprom(k) + (((i + j - u_x(k) - u_y(k))^4)*...\n glcm(i,j,k));\n out.cshad(k) = out.cshad(k) + (((i + j - u_x(k) - u_y(k))^3)*...\n glcm(i,j,k));\n end\n end\n % using http://www.fp.ucalgary.ca/mhallbey/glcm_variance.htm for s_x\n % s_y : This solves the difference in value of correlation and might be\n % the right value of standard deviations required \n % According to this website there is a typo in [2] which provides\n % values of variance instead of the standard deviation hence a square\n % root is required as done below:\n s_x(k) = s_x(k) ^ 0.5;\n s_y(k) = s_y(k) ^ 0.5;\n out.autoc(k) = corp(k);\n out.corrp(k) = (corp(k) - u_x(k)*u_y(k))/(s_x(k)*s_y(k));\n out.corrm(k) = corm(k) / (s_x(k)*s_y(k));\n% % alternate values of u and s\n% out.corrp2(k) = (corp(k) - u_x2(k)*u_y2(k))/(s_x2(k)*s_y2(k));\n% out.corrm2(k) = corm(k) / (s_x2(k)*s_y2(k));\nend\n% Here the formula in the paper out.corrp and the formula in matlab\n% out.corrm are equivalent as confirmed by the similar results obtained\n\n% % The papers have a slightly different formular for Contrast\n% % I have tested here to find this formula in the papers provides the \n% % same results as the formula provided by the matlab function for \n% % Contrast (Hence this part has been commented)\n% out.contrp = zeros(size_glcm_3,1);\n% contp = 0;\n% Ng = size_glcm_1;\n% for k = 1:size_glcm_3\n% for n = 0:(Ng-1)\n% for i = 1:Ng\n% for j = 1:Ng\n% if (abs(i-j) == n)\n% contp = contp + glcm(i,j,k);\n% end\n% end\n% end\n% out.contrp(k) = out.contrp(k) + n^2*contp;\n% contp = 0;\n% end\n% \n% end\n\n% GLCM Features (Soh, 1999; Haralick, 1973; Clausi 2002)\n% f1. Uniformity / Energy / Angular Second Moment (done)\n% f2. Entropy (done)\n% f3. Dissimilarity (done)\n% f4. Contrast / Inertia (done)\n% f5. Inverse difference \n% f6. correlation\n% f7. Homogeneity / Inverse difference moment\n% f8. Autocorrelation\n% f9. Cluster Shade\n% f10. Cluster Prominence\n% f11. Maximum probability\n% f12. Sum of Squares\n% f13. Sum Average\n% f14. Sum Variance\n% f15. Sum Entropy\n% f16. Difference variance\n% f17. Difference entropy\n% f18. Information measures of correlation (1)\n% f19. Information measures of correlation (2)\n% f20. Maximal correlation coefficient\n% f21. Inverse difference normalized (INN)\n% f22. Inverse difference moment normalized (IDN)\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/22187-glcm-texture-features/GLCM_Features1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.8840392924390587, "lm_q1q2_score": 0.8169776843413281}} {"text": "function fx = p54_fun ( n, x )\n\n%*****************************************************************************80\n%\n%% P54_FUN evaluates the integrand for problem 54.\n%\n% Discussion:\n%\n% The reference claims that this integrand is more closely approximated\n% by the trapezoid rule than by Gauss-Legendre quadrature.\n%\n% Points Trapezoid Gauss-Legendre\n% 4 1.91667 2.53883\n% 12 2.1594 2.25809\n%\n% However, the stated results hardly give one confindence in\n% the convergence of the trapezoid results, and I am unable to\n% confirm them, because my results for 4 points give good results\n% (about 1.14) for BOTH Trapezoid and Gauss-Legendre%\n%\n% Interval:\n%\n% 0 <= x <= 1\n%\n% Integrand:\n%\n% 2 / ( 2 + sin ( 10 * PI * x ) )\n%\n% Exact Integral:\n%\n% 2 / sqrt ( 3 ) = 1.1547...\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% Prem Kythe, Pratap Puri,\n% Computational Methods for Linear Integral Equations,\n% Birkhaeuser, 2002.\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(1:n) = 2.0 ./ ( 2.0 + sin ( 10.0 * pi * x(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/test_int/p54_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.8840392832736083, "lm_q1q2_score": 0.8169776703302055}} {"text": "% ............................................................. \n function [shape,naturalDerivatives]=shapeFunctionL2(xi)\n\n % shape function and derivatives for L2 elements\n % shape : Shape functions\n % naturalDerivatives: derivatives w.r.t. xi \n % xi: natural coordinates (-1 ... +1)\n \n shape=([1-xi,1+xi]/2);\n \n naturalDerivatives=[-1,1]/2;\n \n end % end function shapeFunctionL2\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/FEM/BarIsoParametric/shapeFunctionL2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9441768635777511, "lm_q2_score": 0.8652240947405565, "lm_q1q2_score": 0.8169245720640376}} {"text": "function [zProj,AProj]=projEllipsOntoSpace(z,A,gammaVal,d,T)\n%%PROJELLIPSONTOSPACE Determine the orthogonal projection of an ellipsoid\n% onto an affine space. The projection itself will be an\n% ellipsoid. For example, in 3D, the projection onto a\n% plane will be an ellipse.\n%\n%INPUTS: z The numDimX1 center of the ellipsoid.\n% A A numDimXnumDim symmetric, positive definite matrix that\n% specifies the size and shape of the ellipse or ellipsoid, where\n% a point zp is on the ellipse/ellipsoid if\n% (zp-z)'*A*(zp-z)=gammaVal.\n% gammaVal The threshold for declaring a point to be in the ellipsoid. If\n% an empty matrix is passed, the default value of 1 is used.\n% d,T A numDimX1 point d and a numDImXn matrix such that points in\n% the affine subspace are defined by x=d+T*t where t is an nX1\n% real vector, n 0\n tra = createTranslation(center);\n mat = tra * mat / tra; \nend\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/geom2d/createRotation90.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.8740772384450967, "lm_q1q2_score": 0.8167335480808084}} {"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\nJ = (1 / 2) * sum(sum((X * Theta' .* R - Y) .^ 2)) + ...\n (lambda / 2) * sum(sum(Theta .^ 2)) + (lambda / 2) * sum(sum(X .^ 2));\n\nX_grad = (X * Theta' .* R - Y) * Theta + lambda * X;\n\nTheta_grad = (X * Theta' .* R - Y)' * X + lambda * Theta;\n\n% =============================================================\n\ngrad = [X_grad(:); Theta_grad(:)];\n\nend\n", "meta": {"author": "JY-112553", "repo": "machine-learning", "sha": "db9c6e5a5175739821acd97787453472b8f46cac", "save_path": "github-repos/MATLAB/JY-112553-machine-learning", "path": "github-repos/MATLAB/JY-112553-machine-learning/machine-learning-db9c6e5a5175739821acd97787453472b8f46cac/machine-learning-ex8/ex8/cofiCostFunc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.8740772351648677, "lm_q1q2_score": 0.8167335402252038}} {"text": "function x = logistic_cdf_inv ( cdf, a, b )\n\n%*****************************************************************************80\n%\n%% LOGISTIC_CDF_INV inverts the Logistic CDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 13 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real CDF, the value of the CDF.\n% 0.0 <= CDF <= 1.0.\n%\n% Input, real A, B, the parameters of the PDF.\n% 0.0 < B.\n%\n% Output, real X, the corresponding argument.\n%\n if ( cdf < 0.0 | 1.0 < cdf )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LOGISTIC_CDF_INV - Fatal error!\\n' );\n fprintf ( 1, ' CDF < 0 or 1 < CDF.\\n' );\n error ( 'LOGISTIC_CDF_INV - Fatal error!' );\n end\n\n x = a - b * log ( ( 1.0 - cdf ) / cdf );\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/logistic_cdf_inv.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.8757869900269367, "lm_q1q2_score": 0.8166304799953148}} {"text": "function yval = spline_beta_val ( beta1, beta2, ndata, tdata, ydata, tval )\n\n%*****************************************************************************80\n%\n%% SPLINE_BETA_VAL evaluates a cubic beta spline approximant.\n%\n% Discussion:\n%\n% The cubic beta spline will approximate the data, but is not\n% designed to interpolate it.\n%\n% If BETA1 = 1 and BETA2 = 0, the cubic beta spline will be the\n% same as the cubic B spline approximant.\n%\n% With BETA1 = 1 and BETA2 large, the beta spline becomes more like\n% a linear spline.\n%\n% In effect, two \"phantom\" data values are appended to the data,\n% so that the spline will interpolate the first and last data values.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 11 February 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real BETA1, the skew or bias parameter.\n% BETA1 = 1 for no skew or bias.\n%\n% Input, real BETA2, the tension parameter.\n% BETA2 = 0 for no tension.\n%\n% Input, integer NDATA, the number of data values.\n%\n% Input, real TDATA(NDATA), the abscissas of the data.\n%\n% Input, real YDATA(NDATA), the data values.\n%\n% Input, real TVAL, a point at which the spline is to be evaluated.\n%\n% Output, real YVAL, the value of the function at TVAL.\n%\n\n%\n% Find the nearest interval [ TDATA(LEFT), TDATA(RIGHT) ] to TVAL.\n%\n [ left, right ] = r8vec_bracket ( ndata, tdata, tval );\n%\n% Evaluate the 5 nonzero beta spline basis functions in the interval,\n% weighted by their corresponding data values.\n%\n u = ( tval - tdata(left) ) / ( tdata(right) - tdata(left) );\n\n delta = ( ( 2.0E+00 ...\n * beta1 + 4.0E+00 ) ...\n * beta1 + 4.0E+00 ) ...\n * beta1 + 2.0E+00 + beta2;\n\n yval = 0.0E+00;\n%\n% Beta function associated with node LEFT - 1, (or \"phantom node\"),\n% evaluated in its 4th interval.\n%\n bval = 2.0E+00 * ( beta1 * ( 1.0E+00 - u ) )^3 / delta;\n\n if ( 0 < left-1 )\n yval = yval + ydata(left-1) * bval;\n else\n yval = yval + ( 2.0E+00 * ydata(1) - ydata(2) ) * bval;\n end\n%\n% Beta function associated with node LEFT,\n% evaluated in its third interval.\n%\n a = beta2 + ( 4.0E+00 + 4.0E+00 * beta1 ) * beta1;\n\n b = - 6.0E+00 * beta1 * ( 1.0E+00 - beta1 ) * ( 1.0E+00 + beta1 );\n\n c = ( ( - 6.0E+00 ...\n * beta1 - 6.0E+00 ) ...\n * beta1 + 0.0E+00 ) ...\n * beta1 - 3.0E+00 * beta2;\n\n d = ( ( + 2.0E+00 ...\n * beta1 + 2.0E+00 ) ...\n * beta1 + 2.0E+00 ) ...\n * beta1 + 2.0E+00 * beta2;\n\n bval = ( a + u * ( b + u * ( c + u * d ) ) ) / delta;\n\n yval = yval + ydata(left) * bval;\n%\n% Beta function associated with node RIGHT,\n% evaluated in its second interval.\n%\n a = 2.0E+00;\n\n b = 6.0E+00 * beta1;\n\n c = 3.0E+00 * beta2 + 6.0E+00 * beta1 * beta1;\n\n d = - 2.0E+00 * ( 1.0E+00 + beta2 + beta1 + beta1 * beta1 );\n\n bval = ( a + u * ( b + u * ( c + u * d ) ) ) / delta;\n\n yval = yval + ydata(right) * bval;\n%\n% Beta function associated with node RIGHT+1, (or \"phantom node\"),\n% evaluated in its first interval.\n%\n bval = 2.0E+00 * u^3 / delta;\n\n if ( right+1 <= ndata )\n yval = yval + ydata(right+1) * bval;\n else\n yval = yval + ( 2.0E+00 * ydata(ndata) - ydata(ndata-1) ) * bval;\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/spline/spline_beta_val.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428691, "lm_q2_score": 0.8688267796346599, "lm_q1q2_score": 0.8166218874025999}} {"text": "function [ f, g, H ] = opt10_fgh ( x, flag ) \n\n%*****************************************************************************80\n%\n%% OPT10_FGH evaluates F, G and H for test case #10.\n%\n% Discussion:\n%\n% This example is known as the Wood function.\n%\n% The optimizing value is \n%\n% X* = (1,1,1,1)\n%\n% for which\n%\n% F(X*) = 0.\n%\n% Modified:\n%\n% 09 January 2008\n%\n% Author:\n%\n% Jeff Borggaard,\n% Gene Cliff,\n% Virginia Tech.\n%\n% Reference:\n%\n% John Dennis, Robert Schnabel,\n% Numerical Methods for Unconstrained Optimization \n% and Nonlinear Equations,\n% SIAM, 1996,\n% ISBN13: 978-0-898713-64-0,\n% LC: QA402.5.D44.\n%\n% Parameters:\n%\n% Input, real X(4), the evaluation point.\n%\n% Input, string FLAG, indicates what must be computed.\n% 'f' means only the value of F is needed,\n% 'g' means only the value of G is needed,\n% 'all' means F, G and H (if appropriate) are needed.\n% It is acceptable to behave as though FLAG was 'all'\n% on every call.\n%\n% Output, real F, the optimization function.\n%\n% Output, real G(4,1), the gradient column vector.\n%\n% Output, real H(4,4), the Hessian matrix.\n%\n n = length ( x );\n\n if ( n ~= 4 )\n fprintf ( '\\n' );\n fprintf ( 'OPT10_FGH - Fatal error!\\n' );\n fprintf ( ' The input vector X should have length 4.\\n'), \n fprintf ( ' Instead, it has length = %d.\\n', n );\n keyboard\n end\n\n f = 100 * ( x(1)^2 - x(2) )^2 ...\n + ( 1 - x(1) )^2 ...\n + 90 * ( x(3)^2 - x(4) )^2 ...\n + ( 1 - x(3) )^2 ...\n + 10 * ( x(2) + x(4) - 2 )^2 ...\n + 0.1 * ( x(2) - x(4) )^2;\n\n g = zeros(n,1);\n \n g(1,1) = 100 * 2 * ( x(1)^2 - x(2) ) * 2 * x(1)...\n - 2 * ( 1 - x(1) );\n\n g(2,1) = - 100 * 2 * ( x(1)^2 - x(2) )...\n + 10 * 2 * ( x(2) + x(4) - 2 )...\n + 0.1 * 2 * ( x(2) - x(4) );\n\n g(3,1) = 90 * 2 * ( x(3)^2 - x(4) ) * 2 * x(3)...\n - 2 * ( 1 - x(3) );\n\n g(4,1) = - 90 * 2 * ( x(3)^2 - x(4) )...\n + 10 * 2 * ( x(2) + x(4) - 2 )...\n - 0.1 * 2 * ( x(2) - x(4) );\n\n H = zeros(n,n);\n\n H(1,1) = 1200 * x(1)^2 - 400 * x(2) + 2;\n H(1,2) = - 400 * x(1);\n H(1,3) = 0;\n H(1,4) = 0;\n\n H(2,1) = - 400 * x(1);\n H(2,2) = 220.2;\n H(2,3) = 0;\n H(2,4) = 19.8;\n\n H(3,1) = H(1,3);\n H(3,2) = H(2,3);\n H(3,3) = 1080 * x(3)^2 - 360 * x(4) + 2;\n H(3,4) = - 360 * x(3);\n\n H(4,1) = H(1,4);\n H(4,2) = H(2,4);\n H(4,3) = H(3,4);\n H(4,4) = 200.2;\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/entrust/opt10_fgh.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913343093499, "lm_q2_score": 0.8688267779364222, "lm_q1q2_score": 0.8166218814193756}} {"text": "function [R2_cv,mP,VP,R2] = PRESS_GLM(X,y,verbose)\n% evaluates the PRESS-R2 cross-valuidation metric for a GLM\n% function [R2_cv,mP,VP,R2] = PRESS_GLM(X,y,verbose)\n% This function evaluates a prediction accuracy metric (PRESS-R2), in the\n% context of a leave-one-out cross-validation scheme for a GLM. Note: it is\n% based upon the predicted residual error sum of squares (PRESS) statistic.\n% IN:\n% - X: nxp design matrix (independent variables)\n% - y: nxk dependent variables\n% - verbose: verbose flag\n% OUT:\n% - R2_cv: PRESS-R2, i.e. percentage of predicted variance, where\n% predictions are derived for each fold of the leave-one-out\n% cross-validation scheme.\n% - mP: pxk OLS-estimates of the GLM parameters\n% - VP: pxk varianceso of the parameters estimates\n% - R2: coefficeint of determination\n\n% Get time\net0 = clock;\n\n% 0- check basic data dimension requirements\n[n,p] = size(X);\nif n < 3\n disp('Error: PRESS_GLM: data dimension is lower than 3!!')\n R2_cv = [];\n return\nelse\n if verbose\n fprintf(1,'PRESS_GLM: leave-one-out cross-validation scheme:...')\n fprintf(1,'%6.2f %%',0)\n end\nend\n\n% 1- perform leave-one-out scheme\nEg = NaN(size(y));\nii = 0;\nfor i=1:n\n X0 = X;\n X0(i,:) = [];\n y0 = y;\n y0(i,:) = [];\n b = pinv(X0'*X0)*X0'*y0;\n Eg(i,:) = X(i,:)*b;\n if verbose\n fprintf(1,repmat('\\b',1,8))\n fprintf(1,'%6.2f %%',floor(100*i/n))\n end\nend\nif verbose\n fprintf(1,repmat('\\b',1,8))\n fprintf(1,[' OK (took ',num2str(etime(clock,et0)),' seconds).'])\n fprintf(1,'\\n')\nend\n\n% 2- evaluate PRESS and R2_cv\nfor i=1:size(y,2)\n PRESS = sum((y(:,i)-Eg(:,i)).^2);\n TSS(i) = sum((y(:,i)-mean(y(:,i))).^2);\n R2_cv(i) = 1 - PRESS./TSS(i);\nend\n\n% 3- fit the model conditional on all data and wrap-up\nif verbose\n disp('PRESS_GLM: model fit on full-data...')\nend\niX = pinv(X'*X);\nmP = iX*X'*y;\nfor i=1:size(y,2)\n yhat = X*mP(:,i);\n RSS = sum((yhat-y(:,i)).^2);\n vhat = RSS./(n-p);\n C = vhat*iX;\n VP(:,i) = diag(C);\n R2(i) = 1 - RSS./TSS(i);\nend\nif verbose\n disp('PRESS_GLM: model fit on full-data... OK.')\nend\n", "meta": {"author": "MBB-team", "repo": "VBA-toolbox", "sha": "01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414", "save_path": "github-repos/MATLAB/MBB-team-VBA-toolbox", "path": "github-repos/MATLAB/MBB-team-VBA-toolbox/VBA-toolbox-01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414/modules/GLM/PRESS_GLM.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259923, "lm_q2_score": 0.8688267660487572, "lm_q1q2_score": 0.8166218760953711}} {"text": "function value = rayleigh ( n, a, x )\n\n%*****************************************************************************80\n%\n%% RAYLEIGH returns the Rayleigh quotient of the matrix A and the vector X.\n%\n% Formula:\n%\n% RAYLEIGH = X' * A * X / ( X' * X )\n%\n% Properties:\n%\n% If X is an eigenvector of A, then RAYLEIGH will equal the\n% corresponding eigenvalue.\n%\n% The set of all Rayleigh quotients for a matrix is known\n% as its \"field of values\".\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 20 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Input, real A(N,N), the matrix.\n%\n% Input, real X(N), the vector used in the Rayleigh quotient.\n%\n% Output, real VALUE, the Rayleigh quotient of A and X.\n%\n value = ( x(1:n) * a(1:n,1:n) * x(1:n))') / ( x(1:n) * x(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/test_mat/rayleigh.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768145, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.8165968813732065}} {"text": "function p = sphere_stereograph2_inverse ( q, focus, center )\n\n%*****************************************************************************80\n%\n%% SPHERE_STEREOGRAPH2_INVERSE computes stereographic preimages of points.\n%\n% Discussion:\n%\n% We start with a sphere of center C.\n%\n% F is a point on the sphere which is the focus of the mapping,\n% and the antipodal point 2*C-F is the point of tangency\n% to the sphere of a plane.\n%\n% For any point Q on the plane, the stereographic inverse projection\n% P of the point is defined by drawing the line from F through Q, and\n% computing P as the intersection of this line with the sphere.\n%\n% The spatial dimension M is arbitrary, but should be at least 2.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 November 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% C F Marcus,\n% The stereographic projection in vector notation,\n% Mathematics Magazine,\n% Volume 39, Number 2, March 1966, pages 100-102.\n%\n% Parameters:\n%\n% Input, real Q(M,N), the points, which are presumed to lie\n% on the plane.\n%\n% Input, real FOCUS(M,1), the coordinates of the focus point.\n%\n% Input, real CENTER(M,1), the coordinates of the center of the sphere.\n%\n% Output, real P(M,N), the stereographic inverse projections of the points.\n%\n [ m, n ] = size ( q );\n\n ff = repmat ( focus, 1, n );\n\n s(1,1:n) = 2.0 * ( center - focus )' * ( q - ff ) ./ sum ( ( q - ff ).^2, 1 );\n\n ss = repmat ( s, m, 1 );\n\n p = ss .* q + ( 1.0 - ss ) .* ff;\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_stereograph/sphere_stereograph2_inverse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455085, "lm_q2_score": 0.8856314858927012, "lm_q1q2_score": 0.8164830082793686}} {"text": "function Mutual_Information=MutualInformation(x,y)\n\n% Compute Mutual Information and Joint entropy of two images\n% Takes two images and returns the mutual information and joint \n% entropy. For implementing this function also download function\n% joint_histogram.m in my file exchange.\n% \n% written by Amir Pasha Mahmoudzadeh\n% Wright State University\n% Biomedical Imaging Lab\n\nh=joint_histogram(x,y); % Joint histogram for 2D\n[m,n] = size(h);\nJ= h./(m*n); % normalized joint histogram\ny_summ=sum(J); %sum of the rows of normalized joint histogram\nx_summ=sum(J);%sum of columns of normalized joint histogran\n\nsy=0;\nfor s=1:n; % column \n if( y_summ(s)==0 )\n \n else\n sy = sy + -(y_summ(s)*(log2(y_summ(s)))); %marginal entropy for image 1\n end\n end\n \nsx=0;\nfor s=1:m; %rows\n if( x_summ(s)==0 )\n \n else\n sx = sx + -(x_summ(s)*(log2(x_summ(s)))); %marginal entropy for image 2\n end \n end\njoint_entropy = -sum(sum(J.*(log2(J+(J==0))))) % joint entropy\nMutual_Information = sx + sy - joint_entropy; % Mutual information\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/37841-mutual-information-and-joint-entropy/MutualInformation.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539661002182845, "lm_q2_score": 0.8558511506439707, "lm_q1q2_score": 0.8164529845471602}} {"text": "function vol=elemvolume(node,elem,option)\n%\n% vol=elemvolume(node,elem,option)\n%\n% calculate the volume for a list of simplexes\n%\n% author: Qianqian Fang, \n% date: 2007/11/21\n%\n% input:\n% node: node coordinates\n% elem: element table of a mesh\n% option: if option='signed', the volume is the raw determinant,\n% else, the results will be the absolute values\n%\n% output:\n% vol: volume values for all elements\n%\n% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)\n%\n\nif(size(elem,2)==size(node,2))\n\tenum=size(elem,1);\n\tvol=zeros(enum,1);\n\tacol=ones(3,1);\n\tfor i=1:enum\n\t\te1=det([node(elem(i,:),2),node(elem(i,:),3),acol]);\n\t\te2=det([node(elem(i,:),3),node(elem(i,:),1),acol]);\n\t\te3=det([node(elem(i,:),1),node(elem(i,:),2),acol]);\n\t\tvol(i)=sqrt(e1*e1+e2*e2+e3*e3)/2;\n\tend\n\treturn;\nend\ndim=size(elem,2);\nenum=size(elem,1);\nvol=zeros(enum,1);\nfor i=1:enum\n detmat=[node(elem(i,:),:)';ones(1,dim)];\n vol(i)=det(detmat);\nend\nif(nargin==3 && strcmp(option,'signed'))\n vol=vol/prod(1:size(node,2));\nelse\n vol=abs(vol)/prod(1:size(node,2));\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/iso2mesh/elemvolume.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541643004809, "lm_q2_score": 0.8670357632379241, "lm_q1q2_score": 0.816447837050437}} {"text": "function pdf = beta_binomial_pdf ( x, a, b, c )\n\n%*****************************************************************************80\n%\n%% BETA_BINOMIAL_PDF evaluates the Beta Binomial PDF.\n%\n% Discussion:\n%\n% PDF(X)(A,B,C) = Beta(A+X,B+C-X)\n% / ( (C+1) * Beta(X+1,C-X+1) * Beta(A,B) ) for 0 <= X <= C.\n%\n% This PDF can be reformulated as:\n%\n% The beta binomial probability density function for X successes\n% out of N trials is\n%\n% PDF2(X)( N, MU, THETA ) =\n% C(N,X) * Product ( 0 <= R <= X - 1 ) ( MU + R * THETA )\n% * Product ( 0 <= R <= N - X - 1 ) ( 1 - MU + R * THETA )\n% / Product ( 0 <= R <= N - 1 ) ( 1 + R * THETA )\n%\n% where\n%\n% C(N,X) is the combinatorial coefficient;\n% MU is the expectation of the underlying Beta distribution;\n% THETA is a shape parameter.\n%\n% A THETA value of 0 ( or A+B --> Infinity ) results in the binomial\n% distribution:\n%\n% PDF2(X) ( N, MU, 0 ) = C(N,X) * MU**X * ( 1 - MU )**(N-X)\n%\n% Given A, B, C for PDF, then the equivalent PDF2 has:\n%\n% N = C\n% MU = A / ( A + B )\n% THETA = 1 / ( A + B )\n%\n% Given N, MU, THETA for PDF2, the equivalent PDF has:\n%\n% A = MU / THETA\n% B = ( 1 - MU ) / THETA\n% C = N\n%\n% BETA_BINOMIAL_PDF(X)(1,1,C) = UNIFORM_DISCRETE_PDF(X)(0,C-1)\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 09 October 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer X, the argument of the PDF.\n%\n% Input, real A, B, parameters of the PDF.\n% 0.0D+00 < A,\n% 0.0D+00 < B.\n%\n% Input, integer C, a parameter of the PDF.\n% 0 <= C.\n%\n% Output, real PDF, the value of the PDF.\n%\n if ( x < 0 )\n\n pdf = 0.0;\n\n elseif ( x <= c )\n\n pdf = beta ( a + x, b + c - x ) ...\n / ( ( c + 1 ) * beta ( x + 1, c - x + 1 ) * beta ( a, b ) );\n\n elseif ( c < x )\n\n pdf = 0.0;\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/prob/beta_binomial_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541610257062, "lm_q2_score": 0.8670357649558006, "lm_q1q2_score": 0.8164478358287358}} {"text": "function [ w, x ] = line_rule ( a, b, order )\n\n%*****************************************************************************80\n%\n%% LINE_RULE returns a quadrature rule for a line segment in 1D.\n%\n% Discussion:\n%\n% The integration region is:\n% A <= X <= B\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 September 2014\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% Input, real A, B, the lower and upper limits.\n%\n% Input, integer ORDER, the order of the rule.\n%\n% Output, real W(ORDER), the weights.\n%\n% Output, real X(ORDER), the abscissas.\n%\n if ( order == 1 )\n [ w, x ] = line_unit_o01 ( );\n elseif ( order == 2 )\n [ w, x ] = line_unit_o02 ( );\n elseif ( order == 3 )\n [ w, x ] = line_unit_o03 ( );\n elseif ( order == 4 )\n [ w, x ] = line_unit_o04 ( );\n elseif ( order == 5 )\n [ w, x ] = line_unit_o05 ( );\n else\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LINE_RULE - Fatal error!\\n' );\n fprintf ( 1, ' Illegal value of ORDER.\\n' );\n error ( 'LINE_RULE - Fatal error!' );\n end\n%\n% Transform from [-1,+1] to [A,B]\n%\n for j = 1 : order\n w(j) = w(j) * ( b - a ) / 2.0;\n x(j) = ( ( 1.0 - x(j) ) * a ...\n + ( 1.0 + x(j) ) * b ) ...\n / 2.0;\n end\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/line_felippa_rule/line_rule.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.8947894724152068, "lm_q1q2_score": 0.8164382706457193}} {"text": "% sine wave fitting from noisy sine signal \n% phase fitting has to be considered \n% with a fixed omega! \n% Written by Dr Chen YangQuan \n% Last modified in 05-11-2000\n% DESCRIPTIONS:\n% s0: sampled series. 1xNp (note here) \n% omega: known freq. (2*pi*f) (rad/sec.) \n% Ts: sampling period (in Sec.) \n% t0: initial time (in Sec.) \n% Ahat: estimated amplitude \n% Theta: fitted theta_0 (in rad.) \n% RMS: root mean squares. \n% \n% See also \"jomega\"\nfunction [Ahat,Theta,RMS]=sinefit2(s0,omega,t0,Ts) \nNp=size(s0); \nt=t0+[0:Np(2)-1]*Ts; \nA11= (sin(omega*t)*(sin(omega*t))'); \nA12= (sin(omega*t)*(cos(omega*t))'); \nA22= (cos(omega*t)*(cos(omega*t))'); \nb1=s0*(sin(omega*t))'; \nb2=s0*(cos(omega*t))'; \nA=[A11,A12;A12,A22]; \nAlpha=inv(A)*[b1,b2]'; \n% be careful here... \nAsintheta=Alpha(2);Acostheta=Alpha(1); \nAhat=sqrt(Asintheta*Asintheta+Acostheta*Acostheta); \nTheta=atan2(Asintheta,Acostheta); \nRMS=sqrt((s0-Ahat*sin(omega*t+Theta))*... \n(s0-Ahat*sin(omega*t+Theta))'/(Np(2)-1.)); \nif (0)\nfigure;\nplot(t,s0,'k:',t, Ahat*sin(omega*t+Theta),'-r'); \nlegend(['measured (RMS=',num2str(RMS),', f=',... \nnum2str(omega/2/pi),')'],['fitted: ',... \n' A.hat=',num2str(Ahat),' | theta.hat=',num2str(Theta*180/pi)]) \nend\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/3730-sinefit/sinefit/sinefit2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9697854164256365, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.8163902378018598}} {"text": "function [J, grad] = costFunctionReg(theta, X, y, lambda)\n%COSTFUNCTIONREG Compute cost and gradient for logistic regression with regularization\n% J = COSTFUNCTIONREG(theta, X, y, lambda) computes the cost of using\n% theta as the parameter for regularized logistic regression and the\n% gradient of the cost w.r.t. to the parameters. \n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n\n\nn = length(theta);\n\n% X.shape = [m, n], y.shape = [m, 1], theta.shape = [n, 1]\n% y_pred = sigmoid(X*theta), y_pred.shape = [m, 1]\ny_pred = sigmoid(X*theta);\nJ = -1.0 / m * sum( y.*log(y_pred) + (1-y).*log(1-y_pred) );\nJ = J + lambda / (2.0*m) * sum( theta(2:n, 1).^2 ); % ignore theta(1)\ngrad = 1.0 / m .* (X' * (y_pred - y));\ngrad(2:n, 1) = grad(2:n, 1) + lambda / m * theta(2:n, 1); % ignore theta(1)\n\n\n\n\n% =============================================================\n\nend\n", "meta": {"author": "imLogM", "repo": "Machine_Learning_AndrewNg", "sha": "1d499e8e2738032dc85e869ba55c32eb24da288d", "save_path": "github-repos/MATLAB/imLogM-Machine_Learning_AndrewNg", "path": "github-repos/MATLAB/imLogM-Machine_Learning_AndrewNg/Machine_Learning_AndrewNg-1d499e8e2738032dc85e869ba55c32eb24da288d/machine-learning-ex2/ex2/costFunctionReg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813551535004, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.8163246725266589}} {"text": "function area = sphere01_triangle_vertices_to_area ( v1, v2, v3 )\n\n%*****************************************************************************80\n%\n%% SPHERE01_TRIANGLE_VERTICES_TO_AREA: area of a spherical triangle on unit sphere.\n%\n% Discussion:\n%\n% A unit sphere centered at 0 in 3D satisfies the equation:\n%\n% X * X + Y * Y + Z * Z = 1\n%\n% A spherical triangle is specified by three points on the surface\n% of the sphere.\n%\n% The area formula is known as Girard's formula.\n%\n% The area of a spherical triangle on the unit sphere is:\n%\n% AREA = ( A + B + C - PI )\n%\n% where A, B and C are the (surface) angles of the triangle.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 September 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real V1(3), V2(3), V3(3), the vertices of the triangle.\n%\n% Output, real AREA, the area of the spherical triangle.\n%\n\n%\n% Compute the lengths of the sides of the spherical triangle.\n%\n [ as, bs, cs ] = sphere01_triangle_vertices_to_sides ( v1, v2, v3 );\n%\n% Get the spherical angles.\n%\n [ a, b, c ] = sphere01_triangle_sides_to_angles ( as, bs, cs );\n%\n% Get the area.\n%\n area = sphere01_triangle_angles_to_area ( a, b, c );\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_triangle_quad/sphere01_triangle_vertices_to_area.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813451206063, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.8163246586283456}} {"text": "function det = r8mat_det_4d ( a )\n\n%*****************************************************************************80\n%\n%% R8MAT_DET_4D computes the determinant of a 4 by 4 matrix.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 31 January 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A(4,4), the matrix whose determinant is desired.\n%\n% Output, real DET, the determinant of the matrix.\n%\n det = ...\n a(1,1) * ( ...\n a(2,2) * ( a(3,3) * a(4,4) - a(3,4) * a(4,3) ) ...\n - a(2,3) * ( a(3,2) * a(4,4) - a(3,4) * a(4,2) ) ...\n + a(2,4) * ( a(3,2) * a(4,3) - a(3,3) * a(4,2) ) ) ...\n - a(1,2) * ( ...\n a(2,1) * ( a(3,3) * a(4,4) - a(3,4) * a(4,3) ) ...\n - a(2,3) * ( a(3,1) * a(4,4) - a(3,4) * a(4,1) ) ...\n + a(2,4) * ( a(3,1) * a(4,3) - a(3,3) * a(4,1) ) ) ...\n + a(1,3) * ( ...\n a(2,1) * ( a(3,2) * a(4,4) - a(3,4) * a(4,2) ) ...\n - a(2,2) * ( a(3,1) * a(4,4) - a(3,4) * a(4,1) ) ...\n + a(2,4) * ( a(3,1) * a(4,2) - a(3,2) * a(4,1) ) ) ...\n - a(1,4) * ( ...\n a(2,1) * ( a(3,2) * a(4,3) - a(3,3) * a(4,2) ) ...\n - a(2,2) * ( a(3,1) * a(4,3) - a(3,3) * a(4,1) ) ...\n + a(2,3) * ( a(3,1) * a(4,2) - a(3,2) * a(4,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/tetrahedron_keast_rule/r8mat_det_4d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551525886193, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.8162119175567694}} {"text": "function [K,H,Pmax,Pmin] = surfature(X,Y,Z),\n% SURFATURE - COMPUTE GAUSSIAN AND MEAN CURVATURES OF A SURFACE\n% [K,H] = SURFATURE(X,Y,Z), WHERE X,Y,Z ARE 2D ARRAYS OF POINTS ON THE\n% SURFACE. K AND H ARE THE GAUSSIAN AND MEAN CURVATURES, RESPECTIVELY.\n% SURFATURE RETURNS 2 ADDITIONAL ARGUEMENTS,\n% [K,H,Pmax,Pmin] = SURFATURE(...), WHERE Pmax AND Pmin ARE THE MINIMUM\n% AND MAXIMUM CURVATURES AT EACH POINT, RESPECTIVELY.\n\n\n% First Derivatives\n[Xu,Xv] = gradient(X);\n[Yu,Yv] = gradient(Y);\n[Zu,Zv] = gradient(Z);\n\n% Second Derivatives\n[Xuu,Xuv] = gradient(Xu);\n[Yuu,Yuv] = gradient(Yu);\n[Zuu,Zuv] = gradient(Zu);\n\n[Xuv,Xvv] = gradient(Xv);\n[Yuv,Yvv] = gradient(Yv);\n[Zuv,Zvv] = gradient(Zv);\n\n% Reshape 2D Arrays into Vectors\nXu = Xu(:); Yu = Yu(:); Zu = Zu(:); \nXv = Xv(:); Yv = Yv(:); Zv = Zv(:); \nXuu = Xuu(:); Yuu = Yuu(:); Zuu = Zuu(:); \nXuv = Xuv(:); Yuv = Yuv(:); Zuv = Zuv(:); \nXvv = Xvv(:); Yvv = Yvv(:); Zvv = Zvv(:); \n\nXu = [Xu Yu Zu];\nXv = [Xv Yv Zv];\nXuu = [Xuu Yuu Zuu];\nXuv = [Xuv Yuv Zuv];\nXvv = [Xvv Yvv Zvv];\n\n% First fundamental Coeffecients of the surface (E,F,G)\nE = dot(Xu,Xu,2);\nF = dot(Xu,Xv,2);\nG = dot(Xv,Xv,2);\n\nm = cross(Xu,Xv,2);\np = sqrt(dot(m,m,2));\nn = m./[p p p]; \n\n% Second fundamental Coeffecients of the surface (L,M,N)\nL = dot(Xuu,n,2);\nM = dot(Xuv,n,2);\nN = dot(Xvv,n,2);\n\n[s,t] = size(Z);\n\n% Gaussian Curvature\nK = (L.*N - M.^2)./(E.*G - F.^2);\nK = reshape(K,s,t);\n\n% Mean Curvature\nH = (E.*N + G.*L - 2.*F.*M)./(2*(E.*G - F.^2));\nH = reshape(H,s,t);\n\n% Principal Curvatures\nPmax = H + sqrt(H.^2 - K);\nPmin = H - sqrt(H.^2 - K);\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/11168-surface-curvature/surfature.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551495568569, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.8162119131183471}} {"text": "function [A,z]=jacobiancsd(fun,x)\n% JACOBIANCSD Complex Step Jacobian\n% J = jacobiancsd(f,x) returns the numberical (m x n) Jacobian matrix of a \n% m-vector function, f(x) at the refdrence point, x (n-vector).\n% [J,z] = jacobiancsd(f,x) also returns the function value, z=f(x).\n%\n% Example\n% f=@(x)[x(1)*x(2)^2;x(1)*x(3)^2;x(1)^2];\n% x=1:3;\n% [J,z]=jacobiancsd(f,x)\n% J =\n% 4 4 0\n% 9 0 6\n% 2 0 0\n% z =\n% 4\n% 9\n% 1\n%\n% By Yi Cao at Cranfield University, 02/01/2008\n%\nz=fun(x); % function value\nn=numel(x); % size of independent\nm=numel(z); % size of dependent\nA=zeros(m,n); % allocate memory for the Jacobian matrix\nh=n*eps; % differentiation step size\nfor k=1:n % loop for each independent variable \n x1=x; % reference point\n x1(k)=x1(k)+h*i; % increment in kth independent variable\n A(:,k)=imag(fun(x1))/h; % complex step differentiation \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/18176-complex-step-jacobian/jacobiancsd.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.8791467690927438, "lm_q1q2_score": 0.8162076008884861}} {"text": "function [A,b,x] = phillips(n)\n%PHILLIPS Test problem: Phillips' \"famous\" problem.\n%\n% [A,b,x] = phillips(n)\n%\n% Discretization of the `famous' first-kind Fredholm integral\n% equation deviced by D. L. Phillips. Define the function\n% phi(x) = | 1 + cos(x*pi/3) , |x| < 3 .\n% | 0 , |x| >= 3\n% Then the kernel K, the solution f, and the right-hand side\n% g are given by:\n% K(s,t) = phi(s-t) ,\n% f(t) = phi(t) ,\n% g(s) = (6-|s|)*(1+.5*cos(s*pi/3)) + 9/(2*pi)*sin(|s|*pi/3) .\n% Both integration intervals are [-6,6].\n%\n% The order n must be a multiple of 4.\n\n% Reference: D. L. Phillips, \"A technique for the numerical solution\n% of certain integral equations of the first kind\", J. ACM 9\n% (1962), 84-97.\n\n% Discretized by Galerkin method with orthonormal box functions.\n\n% Per Christian Hansen, IMM, 09/17/92.\n\n% Check input.\nif (rem(n,4)~=0), error('The order n must be a multiple of 4'), end\n\n% Compute the matrix A.\nh = 12/n; n4 = n/4; r1 = zeros(1,n);\nc = cos((-1:n4)*4*pi/n);\nr1(1:n4) = h + 9/(h*pi^2)*(2*c(2:n4+1) - c(1:n4) - c(3:n4+2));\nr1(n4+1) = h/2 + 9/(h*pi^2)*(cos(4*pi/n)-1);\nA = toeplitz(r1);\n\n% Compute the right-hand side b.\nif (nargout>1),\n b = zeros(n,1); c = pi/3;\n for i=n/2+1:n\n t1 = -6 + i*h; t2 = t1 - h;\n b(i) = t1*(6-abs(t1)/2) ...\n + ((3-abs(t1)/2)*sin(c*t1) - 2/c*(cos(c*t1) - 1))/c ...\n - t2*(6-abs(t2)/2) ...\n - ((3-abs(t2)/2)*sin(c*t2) - 2/c*(cos(c*t2) - 1))/c;\n b(n-i+1) = b(i);\n end\n b = b/sqrt(h);\nend\n\n% Compute the solution x.\nif (nargout==3)\n x = zeros(n,1);\n x(2*n4+1:3*n4) = (h + diff(sin((0:h:(3+10*eps))'*c))/c)/sqrt(h);\n x(n4+1:2*n4) = x(3*n4:-1:2*n4+1);\nend", "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/phillips.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392795, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.8159470691504241}} {"text": "function [ x, seed ] = sample_sphere_uniform ( m, n, seed )\n\n%*****************************************************************************80\n%\n%% SAMPLE_SPHERE_UNIFORM samples points inside the unit sphere.\n%\n% Discussion:\n%\n% The sphere has center 0 and radius 1.\n%\n% We first generate a point ON the sphere, and then distribute it\n% IN the sphere.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 31 October 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Russell Cheng,\n% Random Variate Generation,\n% in Handbook of Simulation,\n% edited by Jerry Banks,\n% Wiley, 1998, pages 168.\n%\n% Reuven Rubinstein,\n% Monte Carlo Optimization, Simulation, and Sensitivity\n% of Queueing Networks,\n% Wiley, 1986, page 232.\n%\n% Parameters:\n%\n% Input, integer M, 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(M,N), the points.\n%\n exponent = 1.0 / m;\n\n for j = 1 : n\n%\n% Fill a vector with normally distributed values.\n%\n [ y, seed ] = r8ec_normal_01 ( m, seed );\n%\n% Compute the length of the vector.\n%\n norm = sqrt ( sum ( y(1:m).^2 ) );\n%\n% Normalize the vector.\n%\n y(1:m) = y(1:m) / norm;\n%\n% Now compute a value to map the point ON the sphere INTO the sphere.\n%\n [ r, seed ] = r8_uniform_01 ( seed );\n\n x(1:m,j) = r^exponent * y(1:m)';\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/quality/sample_sphere_uniform.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8740772417253256, "lm_q1q2_score": 0.8158906318834152}} {"text": "function [ c_est, r_est, c_err, r_err ] = ellipsoid_random_centralize ( ...\n m, n, c, r )\n\n%*****************************************************************************80\n%\n%% ELLIPSOID_RANDOM_CENTRALIZE estimates the center and radius of an ellipsoid.\n%\n% Discussion:\n%\n% We generate N points on the M dimensional ellipsoid of center C,\n% and radiuses R. We seek to estimate the values of C and R.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 24 April 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, the spatial dimension.\n%\n% Input, integer N, the number of random points to generate.\n%\n% Input, real C(M,1), the center.\n%\n% Input, real R(M,1), the radiuses.\n%\n% Output, real C_EST(M,1), R_EST, the estimated center and radius.\n%\n% Output, real C_ERR, R_ERR, the errors in the estimates.\n%\n c = c(:);\n r = r(:);\n%\n% Construct a diagonal matrix from R.\n%\n a = diag ( r );\n%\n% Multiply it by a random orthogonal matrix.\n%\n q = r8mat_orth_uniform ( m );\n a = q * a * q';\n%\n% Now generate points on the ellipsoid surface (X-C)' * A * (X-C) = R * R.\n%\n rr = 1.0;\n x = ellipsoid_surface_sample ( m, n, a, c, rr );\n\n c_est = sum ( x, 2 ) / n;\n c_err = norm ( c - c_est );\n\n r_mat = x - repmat ( c_est, 1, n );\n r_mat = r_mat.^2;\n r_mat = sum ( r_mat, 1 );\n r_mat = sqrt ( r_mat );\n r_est = sum ( r_mat ) / n;\n% r_err = abs ( r - r_est );\n r_err = 0.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/centralize/ellipsoid_random_centralize.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.8807970732843033, "lm_q1q2_score": 0.8158856074474613}} {"text": "function angles = polyangles(x, y)\n%POLYANGLES Computes internal polygon angles.\n% ANGLES = POLYANGLES(X, Y) computes the interior angles (in\n% degrees) of an arbitrary polygon whose vertices are given in \n% [X, Y], ordered in a clockwise manner. The program eliminates\n% duplicate adjacent rows in [X Y], except that the first row may\n% equal the last, so that the polygon is closed. \n\n% Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins\n% Digital Image Processing Using MATLAB, Prentice-Hall, 2004\n% $Revision: 1.6 $ $Date: 2003/11/21 14:44:06 $\n\n% Preliminaries.\n[x y] = dupgone(x, y); % Eliminate duplicate vertices.\nxy = [x(:) y(:)];\nif isempty(xy)\n % No vertices!\n angles = zeros(0, 1);\n return;\nend\nif size(xy, 1) == 1 | ~isequal(xy(1, :), xy(end, :))\n % Close the polygon\n xy(end + 1, :) = xy(1, :);\nend\n\n% Precompute some quantities.\nd = diff(xy, 1);\nv1 = -d(1:end, :);\nv2 = [d(2:end, :); d(1, :)];\nv1_dot_v2 = sum(v1 .* v2, 2);\nmag_v1 = sqrt(sum(v1.^2, 2));\nmag_v2 = sqrt(sum(v2.^2, 2));\n\n% Protect against nearly duplicate vertices; output angle will be 90\n% degrees for such cases. The \"real\" further protects against\n% possible small imaginary angle components in those cases.\nmag_v1(~mag_v1) = eps;\nmag_v2(~mag_v2) = eps;\nangles = real(acos(v1_dot_v2 ./ mag_v1 ./ mag_v2) * 180 / pi);\n\n% The first angle computed was for the second vertex, and the\n% last was for the first vertex. Scroll one position down to \n% make the last vertex be the first.\nangles = circshift(angles, [1, 0]);\n\n% Now determine if any vertices are concave and adjust the angles\n% accordingly.\nsgn = convex_angle_test(xy);\n\n% Any element of sgn that's -1 indicates that the angle is\n% concave. The corresponding angles have to be subtracted \n% from 360.\nI = find(sgn == -1);\nangles(I) = 360 - angles(I);\n\n%-------------------------------------------------------------------%\nfunction sgn = convex_angle_test(xy)\n% The rows of array xy are ordered vertices of a polygon. If the\n% kth angle is convex (>0 and <= 180 degress) then sgn(k) =\n% 1. Otherwise sgn(k) = -1. This function assumes that the first\n% vertex in the list is convex, and that no other vertex has a\n% smaller value of x-coordinate. These two conditions are true in\n% the first vertex generated by the MPP algorithm. Also the\n% vertices are assumed to be ordered in a clockwise sequence, and\n% there can be no duplicate vertices. \n%\n% The test is based on the fact that every convex vertex is on the\n% positive side of the line passing through the two vertices\n% immediately following each vertex being considered. If a vertex\n% is concave then it lies on the negative side of the line joining\n% the next two vertices. This property is true also if positive and\n% negative are interchanged in the preceding two sentences.\n\n% It is assumed that the polygon is closed. If not, close it.\nif size(xy, 1) == 1 | ~isequal(xy(1, :), xy(end, :))\n xy(end + 1, :) = xy(1, :);\nend\n\n% Sign convention: sgn = 1 for convex vertices (i.e, interior angle > 0 \n% and <= 180 degrees), sgn = -1 for concave vertices.\n\n% Extreme points to be used in the following loop. A 1 is appended \n% to perform the inner (dot) product with w, which is 1-by-3 (see \n% below).\nL = 10^25;\ntop_left = [-L, -L, 1];\ntop_right = [-L, L, 1];\nbottom_left = [L, -L, 1];\nbottom_right = [L, L, 1];\n\nsgn = 1; % The first vertex is known to be convex.\n\n% Start following the vertices. \nfor k = 2:length(xy) - 1\n pfirst= xy(k - 1, :);\n psecond = xy(k, :); % This is the point tested for convexity.\n pthird = xy(k + 1, :);\n % Get the coefficients of the line (polygon edge) passing \n % through pfirst and psecond. \n w = polyedge(pfirst, psecond);\n\n % Establish the positive side of the line w1x + w2y + w3 = 0.\n % The positive side of the line should be in the right side of the\n % vector (psecond - pfirst). deltax and deltay of this vector\n % give the direction of travel. This establishes which of the\n % extreme points (see above) should be on the + side. If that \n % point is on the negative side of the line, then w is replaced by -w.\n \n deltax = psecond(:, 1) - pfirst(:, 1);\n deltay = psecond(:, 2) - pfirst(:, 2);\n if deltax == 0 & deltay == 0\n error('Data into convexity test is 0 or duplicated.')\n end\n if deltax <= 0 & deltay >= 0 % Bottom_right should be on + side.\n vector_product = dot(w, bottom_right); % Inner product.\n w = sign(vector_product)*w;\n elseif deltax <= 0 & deltay <= 0 % Top_right should be on + side.\n vector_product = dot(w, top_right);\n w = sign(vector_product)*w;\n elseif deltax >= 0 & deltay <= 0 % Top_left should be on + side.\n vector_product = dot(w, top_left);\n w = sign(vector_product)*w;\n else % deltax >= 0 & deltay >= 0, so bottom_left should be on + side.\n vector_product = dot(w, bottom_left);\n w = sign(vector_product)*w;\n end\n % For the vertex at psecond to be convex, pthird has to be on the\n % positive side of the line.\n sgn(k) = 1;\n if (w(1)*pthird(:, 1) + w(2)*pthird(:, 2) + w(3)) < 0\n sgn(k) = -1;\n end\nend\n\n%-------------------------------------------------------------------%\nfunction w = polyedge(p1, p2)\n% Outputs the coefficients of the line passing through p1 and\n% p2. The line is of the form w1x + w2y + w3 = 0. \n\nx1 = p1(:, 1); y1 = p1(:, 2);\nx2 = p2(:, 1); y2 = p2(:, 2);\nif x1==x2\n w2 = 0;\n w1 = -1/x1;\n w3 = 1;\nelseif y1==y2\n w1 = 0;\n w2 = -1/y1;\n w3 = 1;\nelseif x1 == y1 & x2 == y2\n w1 = 1;\n w2 = 1;\n w3 = 0; \nelse\n w1 = (y1 - y2)/(x1*(y2 - y1) - y1*(x2 - x1) + eps);\n w2 = -w1*(x2 - x1)/(y2 - y1);\n w3 = 1;\nend\nw = [w1, w2, w3];\n\n%-------------------------------------------------------------------%\nfunction [xg, yg] = dupgone(x, y)\n% Eliminates duplicate, adjacent rows in [x y], except that the \n% first and last rows can be equal so that the polygon is closed.\n\nxg = x;\nyg = y;\nif size(xg, 1) > 2\n I = find((x(1:end-1, :) == x(2:end, :)) & ...\n (y(1:end-1, :) == y(2:end, :)));\n xg(I) = [];\n yg(I) = [];\nend\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/《MATLAB图像处理》源文件/本书源文件/chap11/polyangles.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266013, "lm_q2_score": 0.9059898279984214, "lm_q1q2_score": 0.8158708332882133}} {"text": "% ============================================================= % \n% Files of the Matlab programs included in the book: %\n% Xin-She Yang, Nature-Inspired Metaheuristic Algorithms, %\n% Second Edition, Luniver Press, (2010). www.luniver.com %\n% ============================================================= % \n% The Accelerated Particle Swarm Optimization: % \n% For detail, section Chapter 5 (section 5.3) in the book by %\n% Xin-She Yang, Nature-Inspired Metaheuristic Algorithms, %\n% First Edition, Luniver Press, (2008). Also in Chapter 8 %\n% (section 8.3, page 65) of the second edition (2010). %\n% ------------------------------------------------------------- %\n\n% =============================================================\n% Usage: apso(number_of_particles,timesteps)\n% eg: best=apso(20,10);\n% where best=[xbest ybest zbest] %a n by 3 matrix\n% ------------------------------------------------------------- \nfunction [best]=apso(n,timesteps)\n% n=number of particles \n% timesteps=total number of time steps\nif nargin<2, timesteps=15; end\nif nargin<1, n=20; end\n% -------------------------------------------------------------\n% Michalewicz Function f*=-1.8013 at [2.20319, 1.57049]\nfunstr='-sin(x)*(sin(x^2/pi))^20-sin(y)*(sin(2*y^2/pi))^20';\nf=inline(vectorize(funstr));\n% Lb=[xmin ymin] and Ub=[xmax ymax];\nLb=[0 0]; Ub=[4 4]; \n% ------------------------------------------------------------- \n% Setting parameters alpha, beta\n% Randomization amplitude of roaming particles alpha=[0,1]\n% alpha=gamma^t=0.7^t;\n% Speed of convergence (0->1)=(slow->fast); % beta=0.5 \nbeta=0.5;\n% -------------------------------------------------------------\n% Grid values for show the topology of the function \n% to be optimized. For display only, not used for optimization.\nNgrid=100; % Ngrid=100;\ndx=(Ub(1)-Lb(1))/Ngrid;\ndy=(Ub(2)-Lb(2))/Ngrid;\n\n[x,y]=meshgrid(Lb(1):dx:Ub(1),Lb(2):dy:Ub(2));\n% get the shape of the function\n% you can define any function to be optimized in 'fun(x,y)'\n% funflag=1 or 2 or 3 choose a function from a list\n\nz=f(x,y);\n\n% Display the shape of the function to be optimized\nfigure(1);\nsurfc(x,y,z); \n% -----------------------------------------------------------\nbest=zeros(timesteps,3); \n\n% ===========================================================\n% ------------- Start Particle Swarm Optimization -----------\n% generating the initial locations of n particles\n[xn,yn]=init_pso(n,Lb,Ub);\n% Display the paths of particles in a figure with \n% contours of the function to be optimized \n figure(2);\n\n% Time-marching or iterations \nfor i=1:timesteps, %%%%% start time-stepping\n % Show the contour of the function \n contour(x,y,z,15); hold on;\n colormap cool;\n\n% Find the current best location (xo,yo)\nzn=f(xn,yn);\nzn_min=min(zn);\nxo=min(xn(zn==zn_min));\nyo=min(yn(zn==zn_min));\nzo=min(zn(zn==zn_min));\n\n% Trace the paths of all roaming particles \n% Display these roaming particles\nplot(xn,yn,'.',xo,yo,'d','markersize',10,'markerfacecolor','g');\n\n% The accelerated PSO alpha=alpha_0* gamma^t with alpha_0=1\n gamma=0.7; alpha=gamma.^i;\n% Move all particle to new locations \n [xn,yn]=pso_moving(xn,yn,xo,yo,alpha,beta,Lb,Ub); \n drawnow;\n \n% If you keep \"hold on\", then the paths of particles are displayed \n\thold off;\n% History\n best(i,1)=xo; best(i,2)=yo; best(i,3)=zo;\n% Output the results (xo,yo) to screen\n str=strcat('Best estimates: =',num2str([xo yo]));\n str=strcat(str,' fmin='); str=strcat(str,num2str(best(i,3)));\n str=strcat(str,' Iteration='); str=strcat(str,num2str(i));\n disp(str);\nend %%%%% end of time-stepping\n\n% Postprocessing & display best\nbestsolution=best(end,1:2)\nfmin=best(end,3)\n% -----------------------------------------------------------------\n% All subfunctions are listed here \n% -----------------------------------------------------------------\n% Intial locations of particles\nfunction [xn,yn]=init_pso(n,Lb,Ub)\nxn=rand(1,n)*(Ub(1)-Lb(1))+Lb(1);\nyn=rand(1,n)*(Ub(2)-Lb(1))+Lb(2);\n\n% Move all the particles toward (xo,yo)\nfunction [xn,yn]=pso_moving(xn,yn,xo,yo,alpha,beta,Lb,Ub)\n% Get the number of particles\nnn=size(yn,2);\nxn=xn.*(1-beta)+xo.*beta+alpha.*randn(1,nn);\nyn=yn.*(1-beta)+yo.*beta+alpha.*randn(1,nn);\n[xn,yn]=findrange(xn,yn,Lb,Ub);\n\n% Make sure the particles are not outside of the range\nfunction [xn,yn]=findrange(xn,yn,Lb,Ub)\nnn=length(yn);\nfor i=1:nn,\n if xn(i)<=Lb(1), xn(i)=Lb(1); end\n if xn(i)>=Ub(1), xn(i)=Ub(1); end\n if yn(i)<=Lb(2), yn(i)=Lb(2); end\n if yn(i)>=Ub(2), yn(i)=Ub(2); end\nend\n% End of the APSO -------------------------------------------------\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/29725-accelerated-particle-swarm-optimization/apso.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750440288019, "lm_q2_score": 0.855851148805615, "lm_q1q2_score": 0.8158615415597733}} {"text": "%% Homework 12 (a)\n% Heat equation with variable coeficients using Point Jacobi Method:\n%\n% $\\frac{\\partial}{\\partial x}\\left (k(x,y)\\frac{\\partial{T}}{\\partial{x}} \\right )+\\frac{\\partial}{\\partial x}\\left (k(x,y)\\frac{\\partial{T}}{\\partial{y}} \\right)=0$\n%\n% where:\n%\n% $k(x,y)=1+exp\\left[-\\left( \\frac{x-0.25-0.5y}{0.25} \\right)^2 \\right]$\n\n%close all\nclear all\n\n%% Grid\nh = 0.02;\nlx = [0,1]; dx = h; x = lx(1):dx:lx(2); n = length(x);\nly = [0,1]; dy = h; y = ly(1):dy:ly(2); m = length(y);\nT = zeros(m,n); T_next = zeros(m,n);\n \n% Computing k(x,y) on the grid\nk = zeros(m,n);\nfor j=1:m\n for i=1:n\n %k(j,i)=1+exp(-((x(i)-0.25-0.5*y(j))/0.25)^2);\n k(j,i)=1;\n end\nend\n\n%% Boundary Conditions\nT(1,:) = 0; % Bottom (last row of the matrix)\nT(m,:) = 1-cos(pi*x); % Top (first row of the matrix)\n% Left and Right BCs will be updated on every iteration \n\n%% Method of Solution\n%\nA = zeros(m,n); B = zeros(m,n); C = zeros(m,n); D = zeros(m,n);\nr = 0.00001;\niter = 0;\nr_iter = 1;\nwhile r_iter >= r\n%for s=1:5000\n for i=2:m-1\n for j=2:n-1\n A(i,j)=k(i,j)+k(i+1,j);\n B(i,j)=k(i,j)+k(i,j+1);\n C(i,j)=k(i,j)+k(i-1,j);\n D(i,j)=k(i,j)+k(i,j-1);\n if j == 2 % Matrix left Column, Neumann BC\n T_next(i,j)=...\n 1/(k(i+1,j)+k(i-1,j)+3*k(i,j)+k(i,j+1))*(...\n A(i,j)*T(i+1,j)+...\n B(i,j)*T(i,j+1)+...\n C(i,j)*T(i-1,j));\n elseif j == n-1 % Matrix right Column, Neumann BC\n T_next(i,j)=...\n 1/(k(i+1,j)+k(i-1,j)+3*k(i,j)+k(i,j-1))*(...\n A(i,j)*T(i+1,j)+...\n C(i,j)*T(i-1,j)+...\n D(i,j)*T(i,j-1));\n else\n T_next(i,j)=...\n 1/(k(i+1,j)+k(i-1,j)+4*k(i,j)+k(i,j+1)+k(i,j-1))*(...\n A(i,j)*T(i+1,j)+...\n B(i,j)*T(i,j+1)+...\n C(i,j)*T(i-1,j)+...\n D(i,j)*T(i,j-1));\n end\n end\n end\n T_next(1,:) = 0; % Matrix bottom row, Direchlet BC\n T_next(m,:) = 1-cos(pi*x); % Matrix top row, Direchlet BC\n T_next(2:m-1,1)= T_next(2:m-1,2); % Matrix Left column, Neumann BC\n T_next(2:m-1,n)= T_next(2:m-1,n-1); % Matrix right column, Neumann BC\n %r_iter = norm(T_next-T,2);\n r_iter = max(max(abs(T_next-T)));\n T = T_next;\n iter=iter+1;\nend\nfprintf('iterations: %4.1f \\n',iter);\n\n%% Plot Figures\nfigure\ncontourf(T)\ntitle(['Point Jacobi Method, h =',num2str(h),', iterations: ',num2str(iter)])\nxlabel('x points')\nylabel('y points')\ncolormap hot\ncolorbar('location','southoutside')", "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/Eliptic/Point_Jacobi.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422199928904, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.815859461348531}} {"text": "function plist = partitions(total_sum,candidate_set,max_count,fixed_count)\n% extracts the list of all partitions of a number as integer sums of a list of candidates\n% usage: plist = partitions(total_sum,candidate_set)\n% usage: plist = partitions(total_sum,candidate_set,max_count,fixed_count)\n%\n% PARTITIONS solves the money changing problem. E.g.,\n% how can you make change for one dollar given coins\n% of a given set of denominations. A good reference on\n% the general problem is found here:\n%\n% http://en.wikipedia.org/wiki/Integer_partition\n%\n% PARTITIONS uses a recursive strategy to enumerate all\n% possible partitions of the total_sum. This may be\n% highly intensive for large sums or large sets of\n% candidates.\n%\n% arguments: (input)\n% total_sum - scalar positive integer (to be partitioned)\n%\n% BEWARE! a large total_sum can easily cause\n% stack problems. For example, the number of\n% partitions of 40 is 37338, a set that took 24\n% seconds to completely enumerate on my cpu.\n%\n% candidate_set - (OPTIONAL) vector of (distinct) candidate\n% positive integers for the partitions.\n%\n% Efficiency considerations force me to require\n% that the candidates be sorted in non-decreasing\n% order. An error is produced otherwise.\n%\n% DEFAULT: candidate_set = 1:total_sum\n%\n% BEWARE! large candidate sets can easily cause\n% stack problems\n%\n% max_count - (OPTIONAL) the maximum quantity of any\n% candidate in the final sum.\n%\n% max_count must be either a vector of the\n% same length as candidate_set, or a scalar\n% that applies to all elements in that set.\n%\n% DEFAULT = floor(total_sum./candidate_set)\n%\n% fixed_count - (OPTIONAL) Allows you to specify a fixed\n% number of terms in the partitioned sum.\n%\n% fixed_count must be a positive integer if\n% supplied.\n%\n% DEFAULT = []\n%\n% arguments: (output)\n% plist - array of partitions of total_sum. This is a list\n% of the quantity of each element such that\n% plist*candidate_set(:) yields total_sum\n%\n%\n% example: Write 9 as an integer combination of the set [1 2 4 7]\n%\n% partitions(9,[1 2 4 7])\n%\n% ans =\n% 9 0 0 0\n% 7 1 0 0\n% 5 2 0 0\n% 3 3 0 0\n% 1 4 0 0\n% 5 0 1 0\n% 3 1 1 0\n% 1 2 1 0\n% 1 0 2 0\n% 2 0 0 1\n% 0 1 0 1\n%\n% Thus, we can write 9 = 9*1\n% or 9 = 1*1 + 4*2\n% or 9 = 1*2 + 1*7\n% or any of 8 distinct other ways.\n%\n% There are 11 such ways to write 9 in terms of these\n% candidates.\n%\n%\n% example: Change a 1 dollar bill (100 cents) as an integer\n% combination of the set [1 5 10 25 50], using no more than\n% 4 of any one coin denomination. Note that no pennies will\n% be allowed by the maximum constraint.\n%\n% partitions(100,[1 5 10 25 50],4)\n%\n% ans =\n% 0 4 3 2 0\n% 0 2 4 2 0\n% 0 3 1 3 0\n% 0 1 2 3 0\n% 0 0 0 4 0\n% 0 4 3 0 1\n% 0 2 4 0 1\n% 0 3 1 1 1\n% 0 1 2 1 1\n% 0 0 0 2 1\n% 0 0 0 0 2\n%\n% example: Write 13 as an integer combination of the set [2 4 6 8 10 12]\n% (Note that no such combination exists.)\n%\n% partitions(13,[2 4 6 8 10 12])\n%\n% ans =\n% Empty matrix: 0-by-6\n%\n%\n% example: find all possible ways to write 100 as a sum of EXACTLY 4\n% squares of the integers 1:9.\n%\n% partitions(100,(1:9).^2,[],4)\n% ans =\n% 0 0 0 0 4 0 0 0 0\n% 1 0 0 0 2 0 1 0 0\n% 2 0 0 0 0 0 2 0 0\n% 0 1 0 2 0 0 0 1 0\n% 1 0 2 0 0 0 0 0 1\n%\n%\n% Author: John D'Errico\n% e-mail: woodchips@rochester.rr.com\n% Release: 2\n% Release date: 7/15/08\n\n% default for candidate_set\nif (nargin<2) || isempty(candidate_set)\n candidate_set = 1:total_sum;\nend\n\n% how many candidates are there\nn = length(candidate_set);\n\n% error checks\nif any(candidate_set<=0)\n error('All members of candidate_set must be > 0')\nend\n% candidates must be sorted in increasng order\nif any(diff(candidate_set)<0)\n error('Efficiency requires that candidate_set be sorted')\nend\n\n% check for a max_count. do we supply a default?\nif (nargin<3) || isempty(max_count)\n % how high do we need look?\n max_count = floor(total_sum./candidate_set);\nelseif length(max_count)==1\n % if a scalar was provided, then turn it into a vector\n max_count = repmat(max_count,1,n);\nend\n\n% check for a fixed_count\nif (nargin<4) || isempty(fixed_count)\n fixed_count = [];\nelseif (fixed_count<0) || (fixed_count~=round(fixed_count))\n error('fixed_count must be a positive integer if supplied')\nend\n\n% check for degenerate cases\nif isempty(fixed_count)\n if total_sum == 0\n plist = zeros(1,n);\n return\n elseif (n == 0)\n plist = [];\n return\n elseif (n == 1)\n % only one element in the set. can we form\n % total_sum from it as an integer multiple?\n p = total_sum/candidate_set;\n if (p==fix(p)) && (p<=max_count)\n plist = p;\n else\n plist = [];\n end\n return\n end\nelse\n % there was a fixed_count supplied\n if (total_sum == 0) && (fixed_count == 0)\n plist = zeros(1,n);\n return\n elseif (n == 0) || (fixed_count <= 0)\n plist = [];\n return\n elseif (n==1)\n % there must be a non-zero fixed_count, since\n % we did not trip the last test. since there\n % is only one candidate in the set, will it work?\n if (fixed_count*candidate_set) == total_sum\n plist = fixed_count;\n else\n plist = [];\n end\n return\n end\nend\n\n% finally, we can do some work. start with the\n% largest element and work backwards\nm = max_count(end);\n% do we need to back off on m?\nc = candidate_set(end);\nm = min([m,floor(total_sum/c),fixed_count]);\n\nplist = zeros(0,n);\nfor i = 0:m\n temp = partitions(total_sum - i*c, ...\n candidate_set(1:(end-1)), ...\n max_count(1:(end-1)),fixed_count-i);\n plist = [plist;[temp,repmat(i,size(temp,1),1)]]; %#ok\nend\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/12009-partitions-of-an-integer/partitions/partitions.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.8991213806488609, "lm_q1q2_score": 0.8157838194027978}} {"text": "function[r]=ellrad(varargin)\n%ELLRAD Average and instantaneous ellipse radius. \n%\n% R=ELLRAD(KAPPA,LAMBDA,PHI,STR) where KAPPA and LAMBDA are the amplitude \n% and linearity of a time-varying ellise, and PHI is its time-varying \n% phase, returns various measures of the ellipse 'radius'.\n% \n% STR determines the radius quantity to be output.\n%\n% STR Symbol Description\n% ----------------------------------------------------------------\n% 'geo' RM Geometric mean radius = SQRT(A*B) \n% 'ave' RBAR Period-averaged distance from the origin \n% 'ins' RI Instantaneous distance from the origin\n% \n% See Lilly and Gascard (2006) for details.\n%\n% If STR is omitted, the geometric mean radius is returned by default.\n%\n% RM=ELLRAD(KAPPA,LAMBDA) with PHI omitted also works for computing RM.\n% ____________________________________________________________________\n% \n% Cell array input/output\n%\n% If ELLRAD is given cell array input, it returns cell array output.\n%\n% Thus KAPPA, LAMBDA, and PHI may each be cell arrays of the same size, \n% where each element in the cell array is a numerical array. \n%\n% The output variables will be also cell arrays of this size.\n% ____________________________________________________________________\n%\n% See also ELLVEL, ELLPARAMS, ELLDIFF.\n%\n% Usage: rm=ellrad(kappa,lambda);\n% rbar=ellrad(kappa,lambda,phi,'average');\n% ri=ellrad(kappa,lambda,phi,'instantaneous');\n% __________________________________________________________________\n% This is part of JLAB --- type 'help jlab' for more information\n% (C) 2005--2014 J.M. Lilly --- type 'help jlab_license' for details \n \n\nif ischar(varargin{end})\n str=varargin{end}(1:3);\n varargin=varargin(1:end-1);\nelse\n str='geo';\nend\n\nkappa=varargin{1};\nlambda=varargin{2};\n\nif length(varargin)==2\n if ~aresame(str,'geo')\n error('Only the geometric mean radius can be computed without PHI input.')\n else\n phi=kappa; %It doesn't matter what we set this to as it will not be used.\n end\nelse\n phi=varargin{3};\nend\n\nif ~isempty(kappa)\n if ~iscell(kappa)\n r=ellrad_one(kappa,lambda,phi,str);\n else\n r=kappa;\n for i=1:length(kappa)\n r{i}=ellrad_one(kappa{i},lambda{i},phi{i},str);\n end\n end\nelse\n r=kappa;\nend\n\nfunction[r]=ellrad_one(kappa,lambda,phi,str)\nif aresame(str,'geo')\n [a,b]=kl2ab(kappa,lambda);\n r=sqrt(a.*abs(b)); %r=kappa^2*sqrt(1-lambda^2);\nelseif aresame(str,'ave')\n ecc=ecconv(lambda,'lin2ecc');\n [K,E]=ellipke(ecc.^2);\n r=frac(2*kappa,pi).*sqrt(1+abs(lambda)).*E;\nelseif aresame(str,'ins')\n r=kappa.*sqrt(1+abs(lambda).*cos(2*phi));\nend\n\n", "meta": {"author": "jonathanlilly", "repo": "jLab", "sha": "9f32f63e647209bc1cb81c8713deb954857f1919", "save_path": "github-repos/MATLAB/jonathanlilly-jLab", "path": "github-repos/MATLAB/jonathanlilly-jLab/jLab-9f32f63e647209bc1cb81c8713deb954857f1919/jEllipse/ellrad.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.8757869965109765, "lm_q1q2_score": 0.81576274967384}} {"text": "function sigma = PropError(f,varlist,vals,errs)\n%SIGMA = PROPERROR(F,VARLIST,VALS,ERRS)\n%\n%Finds the propagated uncertainty in a function f with estimated variables\n%\"vals\" with corresponding uncertainties \"errs\".\n%\n%varlist is a row vector of variable names. Enter in the estimated values\n%in \"vals\" and their associated errors in \"errs\" at positions corresponding \n%to the order you typed in the variables in varlist.\n%\n%Example using period of a simple harmonic pendulum:\n%\n%For this example, lets say the pendulum length is 10m with an uncertainty\n%of 1mm, and no error in g.\n%syms L g\n%T = 2*pi*sqrt(L/g)\n%type the function T = 2*pi*sqrt(L/g)\n%\n%PropError(T,[L g],[10 9.81],[0.001 0])\n%ans =\n%\n% [ 6.3437] '+/-' [3.1719e-004]\n% 'Percent Error' '+/-' [ 0.0050]\n%\n%(c) Brad Ridder 2007. Feel free to use this under the BSD guidelines. If\n%you wish to add to this program, just leave my name and add yours to it.\nn = numel(varlist);\nsig = vpa(ones(1,n));\nfor i = 1:n\n sig(i) = diff(f,varlist(i),1);\nend\nerror1 =sqrt((sum((subs(sig,varlist,vals).^2).*(errs.^2))));\nerror = double(error1);\nsigma = [{subs(f,varlist,vals)} {'+/-'} {error};\n {'Percent Error'} {'+/-'} {abs(100*(error)/subs(f,varlist,vals))}];", "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/17901-propagation-of-uncertainty/PropError.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172659321806, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.8157497706372525}} {"text": "function mean = log_normal_mean ( a, b )\n\n%*****************************************************************************80\n%\n%% LOG_NORMAL_MEAN returns the mean of the Lognormal PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 February 1999\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A, B, the parameters of the PDF.\n% 0.0 < B.\n%\n% Output, real MEAN, the mean of the PDF.\n%\n mean = exp ( a + 0.5 * b * b );\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/log_normal_mean.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897492587141, "lm_q2_score": 0.8670357563664174, "lm_q1q2_score": 0.8156983518303013}} {"text": "function N=nmultichoosek(n,k,type)\n%NMULTICHOOSEK Unordered samples WITH or WITHOUT repetition.\n% NMULTICHOOSEK(N,K) finds the number of multisets of length k on n\n% symbols. NMULTICHOOSEK can take vector or scalar input.\n% \n% NMULTICHOOSEK(N,K,'single') is the same as NCHOOSEK (unordered samples WITHOUT\n% repetition), except that it accepts vector inputs for both n and k.\n% \n% NMULTICHOOSEK(N,K,'multi') is the same as NMULTICHOOSEK(N,K).\n% \n% Examples:\n% N = nmultichoosek(5,1:5)\n% \n% finds the number of multisets of length 1 to 5 from a 5 symbol set\n% \n% N = nmultichoosek(5,1:5,'single')\n% \n% is the same as:\n% \n% for k=1:5\n% N(k) = nchoosek(5,k);\n% end\n%\n% See also nchoosek, perms.\n\n% Author: Peter (PB) Bodin\n% Email: pbodin@kth.se\n% Created: 14-Nov-2005 19:48:49\n\nmsg = nargchk(2,3,nargin);\nerror(msg);\nn = n(:); % Convert N-D arrays to 1-D\nk = k(:); % Convert N-D arrays to 1-D\nif numel(n)>1 & numel(k)>1\n if numel(n)~=numel(k)\n error('vectors must have the same number of elements')\n end\nend\n\nif nargin > 2\n switch type\n case 'single'\n N = round(exp(gammaln(n+1) - gammaln(k+1) - gammaln(n-k+1)));\n return;\n case 'multi'\n otherwise\n error('valid types are ''multi'' and ''single''');\n end\nend\n\nN = round(exp(gammaln(n+k) - gammaln(k+1) - gammaln(n)));\nN(n0)\n theRank=theRank+numMPartitions(sum(thePartition(idx:m)),curParts,true);\n end\n end\n theRank=numberOfPartitions(n)-theRank;\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/rankPartition.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086368, "lm_q2_score": 0.8902942348544447, "lm_q1q2_score": 0.8156071033951489}} {"text": "function value = quat_norm ( q )\n\n%*****************************************************************************80\n%\n%% QUAT_NORM computes the norm of a quaternion.\n%\n% Discussion:\n%\n% A quaternion is a quadruplet (A,B,C,D) of real numbers, which\n% may be written as\n%\n% Q = A + Bi + Cj + Dk.\n%\n% The norm of Q is\n%\n% norm(Q) = sqrt ( A**2 + B**2 + C**2 + D**2 ).\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 Q(4), the quaternion.\n%\n% Output, real VALUE, the norm of the quaternion.\n%\n value = sqrt ( sum ( q(1:4).^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/quat_norm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.8774767762675404, "lm_q1q2_score": 0.815562365840381}} {"text": "function [eu,cEu]=grIsEulerian(E)\n% Function eu=grIsEulerian(E) returns 1 for Eulerian graph, \n% 0.5 for semi-Eulerian and 0 otherwise.\n% Input parameter: \n% E(m,2) - the edges of graph;\n% 1st and 2nd elements of each row is numbers of vertexes;\n% m - number of edges.\n% Output parameter:\n% eu = 1 for Eulerian graph;\n% eu = 0.5 for semi-Eulerian graph;\n% eu = 0 otherwise.\n% The graph is Eulerian, if he is connected and powers of \n% all vertexes is even.\n% The graph is semi-Eulerian, if he is connected and only \n% two vertexes have odd powers, and other powers of vertexes is even.\n% [eu,cEu]=grIsEulerian(E) return also \n% cEu(m,1) - the vector-column with numbers of edges\n% included to Eulerian cycle (if eu=1) or Eulerian way (if eu=0.5)\n% and cEu=[] otherwise. The Fleury algorithm is used.\n% Author: Sergiy Iglin\n% e-mail: siglin@yandex.ru\n% personal page: http://iglin.exponenta.ru\n\nif nargin<1,\n error('There are no input data!')\nend\neu = 0; % the graph is not Eulerian\ncEu=[];\nncV=grComp(E); % the number of components\nif max(ncV)>1, % 2 or more components\n return % the graph is not Eulerian\nend\nn=max(max(E(:,1:2))); % number of vertexes\nE1=find([diff(sort(E(:)));1]);\np=[E1(1);diff(E1)]; % powers of vertexes\nrp=rem(p,2); % remainder after division to 2\nsrp=sum(rp); % summa of remainders\nswitch srp\n case 0, % Eulerian graph\n eu=1;\n case 2, % semi-Eulerian graph\n eu=0.5;\n otherwise, % not Eulerian graph\n return\nend\n%=========== we find the Eulerian cycle or way =============\nif nargout>1,\n if srp==0, % Eulerian graph\n v1=1; % first vertex of Eulerian cycle\n else % semi-Eulerian graph\n v1=find(rp);\n v1=v1(1); % first vertex of Eulerian way\n end\n vc=v1; % the current vertex\n m=size(E,1); % number of edges\n E1=[E(:,1:2), [1:m]']; % all edges with numbers\n while ~isempty(E1), % the Fleury algorithm\n evc=find((E1(:,1)==vc)|(E1(:,2)==vc)); % edges connected with vc\n levc=length(evc); % number of edges connected with vertex vc\n if levc==1, % only one way\n cEu=[cEu;E1(evc,3)]; % we add new edge to Eulerian cycle (way)\n vcold=vc;\n vc=sum(E1(evc,1:2))-vc; % new current vertex\n E1=E1(setdiff([1:size(E1,1)],evc),:); % we delete isolated vertex\n E2=E1(:,1:2);\n E2gv=E2>vcold;\n E2(E2gv)=E2(E2gv)-1;\n E1(:,1:2)=E2;\n if vc>vcold,\n vc=vc-1;\n end\n if v1>vcold,\n v1=v1-1;\n end\n else % several ways from vertex vc\n for k=1:levc,\n E2=E1(setdiff([1:size(E1,1)],evc(k)),:);\n ncv=grComp(E2); % number of components\n nco=max(ncv);\n if (max(ncv)==1), % this edge is not bridge\n cEu=[cEu;E1(evc(k),3)]; % we add new edge to Eulerian cycle (way)\n vc=sum(E1(evc(k),1:2))-vc; % new current vertex\n E1=E2;\n break;\n end\n end\n end\n end\nend\nreturn", "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/GraphTheory(图论)/basic/grIsEulerian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966747198242, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.8155292008262225}} {"text": "function [x, err] = rombergQuadrature(fun,tSpan,tol)\n% [x, err] = rombergQuadrature(fun,tSpan,tol)\n%\n% Compute the integral(fun), over the domain tSpan, to an accuracy of tol,\n% using Romberg quadrature. Fully vectorized.\n%\n% Good for high-accuracy quadrature over smooth vector functions.\n%\n% If necessary, this function will automatically sub-divide the interval to\n% achieve the desired accuracy. This should only occur when fun is stiff or\n% non-smooth.\n%\n% INPUTS:\n% fun = vector function to be integrated\n% dx = fun(t)\n% t = [1, nt] = time vector\n% dx = [nx, nt] = function value at each point in t\n% tSpan = [tLow, tUpp] = time span (domain) for integration\n% tol = [nx,1] = desired error tolerance along each dimension\n%\n% OUTPUT:\n% x = [nx,1] = integral along each dimension\n% err = [nx, 1] = error estimate along each dimension\n%\n% NOTES:\n% algorithm from:\n% http://www.math.usm.edu/lambers/mat460/fall09/lecture29.pdf\n%\n\na = tSpan(1);\nb = tSpan(2);\nh = b-a;\nf0 = fun(tSpan);\nnx = size(f0,1);\n\nif isscalar(tol)\n tol = tol*ones(nx,1);\nend\n\nnMin = 4; % Complete at least this many iterations\nnMax = 12; % Maximum iteration count\nnSubSegment = 4; % Sub-divide segment if max iteration is reached\n\nT = zeros(nMax,nMax,nx); % (iteration, extrapolation, dimension)\nErr = zeros(nMax,nx); %(extrapolation, dimension)\n\nT(1,1,:) = 0.5*h*sum(f0,2);\nh = h/2;\n\nconverged = false;\nfor j=2:nMax\n \n % Trapazoid method\n i = 1:2^(j-2);\n t = a+h*(2*i-1);\n f = fun(t);\n T(j,1,:) = 0.5*T(j-1,1,:) + reshape(h*sum(f,2),1,1,nx);\n \n % Richardson extrapolation\n for k=2:j\n T(j,k,:) = T(j,k-1,:) + ...\n ( 1/(4^(k-1)-1) )*( T(j,k-1,:) - T(j-1,k-1,:) );\n end\n h = h/2;\n \n % Check the error estimate for convergence\n Err(j,:) = T(j,k,:) - T(j-1,k-1,:);\n err = abs(Err(j,:))';\n if all( err < tol ) && j > nMin\n converged = true;\n break;\n end\nend\n\nx = reshape(T(j,j,:),nx,1);\n\nif ~converged %Then non-smooth problem. Recursively sub-divide interval.\n time = linspace(tSpan(1), tSpan(2), nSubSegment+1);\n x = zeros(nx,1);\n err = zeros(nx,1);\n for i=1:nSubSegment\n [xTmp, errTmp] = rombergQuadrature(fun,time([i, i+1]),tol);\n x = x + xTmp;\n err = max(err,errTmp);\n end\nend\n\nend\n", "meta": {"author": "MatthewPeterKelly", "repo": "OptimTraj", "sha": "c97b57fda511dacc6a6187f683428f0f3a1965f2", "save_path": "github-repos/MATLAB/MatthewPeterKelly-OptimTraj", "path": "github-repos/MATLAB/MatthewPeterKelly-OptimTraj/OptimTraj-c97b57fda511dacc6a6187f683428f0f3a1965f2/rombergQuadrature.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418283357703, "lm_q2_score": 0.8824278587245935, "lm_q1q2_score": 0.8154884947361647}} {"text": "%GENTRUNK Generation of Trunk's classification problem of 2 Gaussian classes\n% \n% A = GENTRUNK(N,K)\n% \n% INPUT\n% N Dataset size, or 2-element array of class sizes (default: [50 50]).\n% K Dimensionality of the dataset to be generated (default: 10).\n%\n% OUTPUT\n% A Dataset.\n%\n% DESCRIPTION\n% Generation of a K-dimensional 2-class dataset A of N objects. Both classes \n% are Gaussian distributed with the idenity matrix as covariance matrix.\n% The means of the first class are defined by ua(j) = 1/sqrt(j). The means\n% for the second class are ub = -ua. These means are such that the Nearest\n% Mean Classifier always shows peaking for a finite training set.\n%\n% REFERENCES\n% 1. G.V. Trunk, A Problem of Dimensionality: A Simple Example, IEEE Trans. \n% Pattern Analysis and Machine Intelligence, vol. 1, pp. 306-307, 1979\n% 2. A.K. Jain, R.P.W. Duin, and J. Mao, Statistical Pattern Recognition: \n% A Review, IEEE Transactions on Pattern Analysis and Machine Intelligence, \n% vol. 22, pp. 4-37, 2000.\n%\n% EXAMPLE\n% a = gentrunk([1000 1000],200);\n% e = clevalf(a,nmc,[1:9 10:5:25 50:25:200],[5 5],25);\n% plote(e)\n%\n% SEE ALSO (PRTools Guide)\n% DATASETS, PRDATASETS\n\n% Copyright: R.P.W. Duin, r.p.w.duin@37steps.com\n% Faculty EWI, Delft University of Technology\n% P.O. Box 5031, 2600 GA Delft, The Netherlands\n\n% $Id: gentrunk.m,v 1.2 2009/01/27 13:01:42 duin Exp $\n\nfunction A = gendats (N,k)\n\n\t\tif (nargin < 1), N = [50 50]; end\n\tif (nargin < 2), k = 10;\tend\n\n\t% Set equal priors and generate random class sizes according to these.\n\tp = [0.5 0.5]; N = genclass(N,p);\t\n\n\t% Unit covariance matrices\n\t% GA = eye(k); GB = eye(k);\n % Trunk means\n ma = 1./sqrt(1:k);\n mb = -ma;\n \n A = prdataset([randn(N(1),k) + repmat(ma,N(1),1); randn(N(2),k) + repmat(mb,N(2),1)]);\n A = prdataset(A,genlab(N));\n A = setprior(A,p);\n \n% \tU = prdataset([ma;mb],[1 2]');\n% \tU = setprior(U,p);\n% \n% \t% Create dataset.\n% \tA = gendatgauss(N,U,cat(3,GA,GB));\n\tA = setname(A,'Trunk''s Problem');\n\nreturn\n", "meta": {"author": "marianux", "repo": "ecg-kit", "sha": "c8e3de47c54a9214138143676d2aa546b0540dd2", "save_path": "github-repos/MATLAB/marianux-ecg-kit", "path": "github-repos/MATLAB/marianux-ecg-kit/ecg-kit-c8e3de47c54a9214138143676d2aa546b0540dd2/common/prtools/gentrunk.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418241572635, "lm_q2_score": 0.8824278602705731, "lm_q1q2_score": 0.8154884924776382}} {"text": "function geometry_test178 ( )\n\n%*****************************************************************************80\n%\n%% TEST178 tests ROTATION_MAT2QUAT_3D, ROTATION_QUAT2MAT_3D.\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 dim_num = 3;\n\n a = [ ...\n 0.43301269, -0.5, 0.75; ...\n 0.25, 0.86602539, 0.43301269; ...\n -0.86602539, 0.0, 0.5 ]';\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST178\\n' );\n fprintf ( 1, ' ROTATION_MAT2QUAT_3D computes a rotation\\n' );\n fprintf ( 1, ' quaternion from a rotation matrix.\\n' );\n fprintf ( 1, ' ROTATION_QUAT2MAT_3D computes a rotation matrix\\n' );\n fprintf ( 1, ' from a rotation quaternion.\\n' );\n\n r8mat_print ( dim_num, dim_num, a, ' The rotation matrix:' );\n\n q = rotation_mat2quat_3d ( a );\n\n r8vec_print ( 4, q, ' The rotation quaternion:' );\n\n a = rotation_quat2mat_3d ( q );\n\n r8mat_print ( dim_num, dim_num, a, ' The rotation matrix:' );\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_test178.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249611, "lm_q2_score": 0.8887588038050466, "lm_q1q2_score": 0.815260812451323}} {"text": "function d = mahalanobis(varargin)\n%MAHALANOBIS Computes the Mahalanobis distance.\n% D = MAHALANOBIS(Y, X) computes the Mahalanobis distance between\n% each vector in Y to the mean (centroid) of the vectors in X, and\n% outputs the result in vector D, whose length is size(Y, 1). The\n% vectors in X and Y are assumed to be organized as rows. The\n% input data can be real or complex. The outputs are real\n% quantities.\n%\n% D = MAHALANOBIS(Y, CX, MX) computes the Mahalanobis distance\n% between each vector in Y and the given mean vector, MX. The\n% results are output in vector D, whose length is size(Y, 1). The\n% vectors in Y are assumed to be organized as the rows of this\n% array. The input data can be real or complex. The outputs are\n% real quantities. In addition to the mean vector MX, the\n% covariance matrix CX of a population of vectors X also must be\n% provided. Use function COVMATRIX (Section 11.5) to compute MX and\n% CX.\n\n% Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins\n% Digital Image Processing Using MATLAB, Prentice-Hall, 2004\n% $Revision: 1.6 $ $Date: 2005/01/18 13:44:47 $\n\n% Reference: Acklam, P. J. [2002]. \"MATLAB Array Manipulation Tips\n% and Tricks.\" Available at\n% home.online.no/~pjacklam/matlab/doc/mtt/index.html \n% or at\n% www.prenhall.com/gonzalezwoodseddins\n\nparam = varargin; % Keep in mind that param is a cell array.\nY = param{1};\nny = size(Y, 1); % Number of vectors in Y.\n\nif length(param) == 2\n X = param{2};\n % Compute the mean vector and covariance matrix of the vectors\n % in X.\n [Cx, mx] = covmatrix(X);\nelseif length(param) == 3 % Cov. matrix and mean vector provided.\n Cx = param{2};\n mx = param{3};\nelse \n error('Wrong number of inputs.')\nend\nmx = mx(:)'; % Make sure that mx is a row vector.\n\n% Subtract the mean vector from each vector in Y.\nYc = Y - mx(ones(ny, 1), :);\t\n\n% Compute the Mahalanobis distances.\nd = real(sum(Yc/Cx.*conj(Yc), 2));\n", "meta": {"author": "Ultrasty", "repo": "Digital-Image-Processing", "sha": "dbcad426ff9ae7582d25b6f36de68edbfbd2a3b7", "save_path": "github-repos/MATLAB/Ultrasty-Digital-Image-Processing", "path": "github-repos/MATLAB/Ultrasty-Digital-Image-Processing/Digital-Image-Processing-dbcad426ff9ae7582d25b6f36de68edbfbd2a3b7/冈萨雷斯数字图像处理源代码/mahalanobis.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951570602081, "lm_q2_score": 0.8723473862936943, "lm_q1q2_score": 0.8151171730269586}} {"text": "function [xy,scalFact]=ellips2Mercator(latLon,a,f)\n%%ELLIPS2MERCATOR Convert from ellipsoidal (geodetic) latitude and\n% longitude into Mercator Easting and Northing. The Mercator\n% projection is useful, because lines of constant heading\n% (i.e. degrees East of North) are straight lines on the map\n% and the projection is conformal. However, the poles are\n% placed at +/-Inf. The Mercator projection is a type of\n% cylindrical projection.\n%\n%INPUTS: latLon A 2XN matrix of ellipsoidal [latitude;longitude] points\n% given in radians.\n% a The semi-major axis of the reference ellipsoid. If this\n% argument is omitted, the value in\n% Constants.WGS84SemiMajorAxis is used.\n% f The flattening factor of the reference ellipsoid. If this\n% argument is omitted, the value in Constants.WGS84Flattening\n% is used.\n%\n%OUTPUTS: xy A 2XN matrix of [Easting;Northing] points in the Mercator\n% projection. Easting is related to longitude and Northing is\n% related to latitude. The units are those of the semi-major\n% axis and are typically meters.\n% scalFact The scale factor (both parallel and meridian) at the given\n% points.\n%\n%The Mercator projection is discussed in detail in Chapter 7 of [1].\n%Equations for the conversion along with a commonly used but very\n%inaccurate spherical Mercator conversion (the \"Web\" Mercator map) are\n%given in [2]. The \"web\" Mercator conversion can be obtained by setting\n%f to zero.\n%\n%REFERENCES:\n%[1] J. P. Snyder, \"Map projections- a working manual,\" U.S. Geological\n% Survey, Tech. Rep. 1395, 1987.\n%[2] Office of Geomatics, \"National geospatial-intelligence agency\n% standardization document: Implementation practice: Web mercator map\n% projection,\" National Geospatial-Intelligence Agency, Tech. Rep.\n% NGA.SIG.0011 1.0.0 WEBMERC, 18 Feb. 2014. [Online]. Available:\n% http://earth-info.nga.mil/GandG/wgs84/web_mercator/(U)%20NGA_SIG_0011_1.0.0_WEBMERC.pdf\n%\n%August 2017 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<2||isempty(a))\n a=Constants.WGS84SemiMajorAxis;\nend\n\nif(nargin<3||isempty(f))\n f=Constants.WGS84Flattening;\nend\n\ne2=2*f-f^2;\n%The first numerical eccentricity of the ellipsoid.\ne=sqrt(e2);\n\nsinPhi=sin(latLon(1,:));\ncosPhi=cos(latLon(1,:));\nlambda=latLon(2,:);\n\nx=a*lambda;\ny=a*(atanh(sinPhi)-e*atanh(e*sinPhi));\n\nxy=[x;y];\n\nscalFact=sqrt(1-e2*sinPhi.^2)./cosPhi;\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/ellips2Mercator.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.8723473630627235, "lm_q1q2_score": 0.81511715291375}} {"text": "function S = SeparateScales(X,L)\n% SeparatesScales: Separates an image into an (orthonormal) \n% series of disjoint scales.\n% Usage:\n% S = SeparateScales(X,L);\n% Inputs:\n% X n by n image \n% L scale of the coarsest coefficients\n% Outputs: S data structure which contains the FT of X tapered at\n% dyadic scales.\n%\n% Description\n% For each s = 1, ..., J - L, \n% S{s} is a structure which contains the DFT of X tapered with a \n% Meyer-style window which isolates frequencies near a dyadic \n% frequency subband\n%\n% S{s} m by m matrix with m = 2*2^(j+1)); matrix\n% entries are Fourier coefficients of Img at \n% -2^(j+1) <= k1,k2 < 2^(j+1) after windowing with a \n% bandpass Meyer window which isolates frequencies \n% in the range 2^(j-1) <= |k| <= 2^j. \n% \n% j = L - 2 + s \n% See Also\n% Adj_ Separatescales, Curvelet02Xform\n%\n% By Emmanuel Candes, 2003-2004\n\n n = size(X,1);\n n2 = n/2;\n J = log2(n);\n deg = 3;\n \n scale = (L-1):(J-1);\n nscales = length(scale); \n S = cell(1,nscales); % Create data structure\n \n F = fft2_mid0(X)/sqrt(prod(size(X)));\n \n % Partition at Coarse Level\n [ix,w] = CoarseMeyerWindow(L-1,deg);\n w = [0 reverse(w(2:length(w))) w]; \n \n w2 = w'*w; % Build 2D-window\n \n l = 2^L;\n lx = (n2 - l + 1):(n2 + l); \n S{1} = F(lx,lx).*w2;\n \n % Loop to Get Partition for j = L, ..., J - 1;\n for j = L:(J-1),\n \n l = min(2^(j+1),n2);\n wlo = zeros(1,l); whi = wlo;\n\t \n [ixf, wf] = CoarseMeyerWindow(j-1,deg);\n wlo(ixf+1) = wf;\n wlo = [0 reverse(wlo(2:length(wlo))) wlo]; \n \n if j < J -1, \t \n [ixp, wp] = CoarseMeyerWindow(j,deg); \n whi(ixp+1) = wp; \n whi = [0 reverse(whi(2:length(whi))) whi];\n end\n \n if j == J - 1, \n whi = ones(1,2*l); \n end\n \n w2 = sqrt((whi'*whi).^2 - (wlo'*wlo).^2); % Build 2D-window\n \n lx = (n2 - l + 1):(n2 + l); \n S{j - L + 2} = F(lx,lx).*w2; \t \n end\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/utils/utils_TRAFO/CurveLab-2.1.3/fdct_usfft_matlab/CurveCoeff/SeparateScales.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.948154530420204, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.8150940779794987}} {"text": "function [w,b,Yt] = ridgeregress(X,Y,gam, Xt)\n% Linear ridge regression\n% \n% >> [w, b] = ridgeregress(X, Y, gam)\n% >> [w, b, Yt] = ridgeregress(X, Y, gam, Xt)\n% \n% Ordinary Least squares with a regularization parameter (gam).\n% \n% Full syntax\n% \n% >> [w, b, Yt] = ridgeregress(X, Y, gam, Xt)\n% \n% Outputs \n% w : d x 1 vector with the regression coefficients\n% b : bias term\n% Yt(*) : Nt x 1 vector with predicted outputs of test data\n% Inputs \n% X : N x d matrix with the inputs of the training data\n% Y : N x 1 vector with the outputs of the training data\n% gam : Regularization parameter\n% Xt(*) : Nt x d matrix with the inputs of the test data\n% \n% See also:\n% bay_rr,bay_lssvm\n\n% Copyright (c) 2011, KULeuven-ESAT-SCD, License & help @ http://www.esat.kuleuven.be/sista/lssvmlab\n\n \nif size(X,1)~=size(Y,1),\n error('X and Y need to have the same number of data points');\nend\nif size(Y,2)~=1,\n error('Only handling one-dimensional output');\nend\nif nargin==4 & size(Xt,2)~=size(X,2),\n error('Training input and test inputs need to have the same dimension');\nend\n \n[nD,nx] = size(X);\nif nx>nD, warning('dim datapoints larger than number of datapoints...');end\n\n\nXe = [X ones(nD,1)];\n%H = [ Xe'*Xe + gam^-1*[eye(nx) zeros(nx,1); zeros(1,nx+1)]];\nH = Xe'*Xe + inv(gam).*eye(nx+1);\n\nsol = pinv(H)*Xe'*Y;\nw = sol(1:end-1);\nb = sol(end);\n\n\nif nargin<4, return; end\nYt = Xt*w+b;\n \n \n \n", "meta": {"author": "peterhcharlton", "repo": "RRest", "sha": "f5022e7029c5b6d6b8159b665dccc2c8f267976e", "save_path": "github-repos/MATLAB/peterhcharlton-RRest", "path": "github-repos/MATLAB/peterhcharlton-RRest/RRest-f5022e7029c5b6d6b8159b665dccc2c8f267976e/RRest_v3.0/Algorithms/extract_resp_sig/feat_based_extraction/LSSVMlabv1_8_R2009b_R2011a/ridgeregress.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533163686646, "lm_q2_score": 0.8740772236840656, "lm_q1q2_score": 0.815036205986522}} {"text": "function table = hen_power_product ( p, e )\n\n%*****************************************************************************80\n%\n%% HEN_POWER_PRODUCT: power products, x^e*Hen(i,x)*Hen(j,x).\n%\n% Discussion:\n%\n% Hen(i,x) is the normalized probabilist's Hermite 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 X with every possible pair\n% of basis functions. That is, we'd like to form\n%\n% Tij = Integral ( -oo < X < +oo ) X^E * Hen(I,X) * Hen(J,X) exp(-0.5*X*X) dx\n%\n% We will estimate these integrals using Gauss-Hermite quadrature.\n%\n% When E is 0, the computed table should be the identity matrix.\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% 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. TABLE(I,J)\n% represents the weighted integral of X^E * Hen(I+1,X) * Hen(J+1,X).\n%\n table(1:p+1,1:p+1) = 0.0;\n\n order = p + 1 + floor ( ( e + 1 ) / 2 );\n\n [ x_table, w_table ] = he_quadrature_rule ( order );\n\n for k = 1 : order\n\n x = x_table(k);\n h_table = hen_polynomial_value ( 1, p, x );\n%\n% The following formula is an outer product in H_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) * h_table(1:p+1)' * h_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 * h_table(1:p+1)' * h_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/hermite_polynomial/hen_power_product.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002789, "lm_q2_score": 0.8840392863287585, "lm_q1q2_score": 0.8150151228326246}} {"text": "function [ p, seed ] = cylinder_sample_3d ( p1, p2, r, n, seed )\n\n%*****************************************************************************80\n%\n%% CYLINDER_SAMPLE_3D samples a cylinder in 3D.\n%\n% Discussion:\n%\n% We are sampling the interior of a right finite cylinder in 3D.\n%\n% The interior of a (right) (finite) cylinder in 3D is defined by an axis,\n% which is the line segment from point P1 to P2, and a radius R. The points\n% on or inside the cylinder are:\n% * points whose distance from the line through P1 and P2 is less than\n% or equal to R, and whose nearest point on the line through P1 and P2\n% lies (nonstrictly) between P1 and P2.\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 P1(3,1), P2(3,1), the first and last points\n% on the axis line of the cylinder.\n%\n% Input, real R, the radius of the cylinder.\n%\n% Input, integer N, the number of sample points to compute.\n%\n% Input, integer SEED, the random number seed.\n%\n% Input, real P(3,N), the sample points.\n%\n% Output, integer SEED, the random number seed.\n%\n\n%\n% Compute the axis vector.\n%\n axis(1:3,1) = p2(1:3,1) - p1(1:3,1);\n axis_length = r8vec_norm ( 3, axis );\n axis(1:3,1) = axis(1:3,1) / axis_length;\n%\n% Compute vectors V2 and V3 that form an orthogonal triple with AXIS.\n%\n [ v2, v3 ] = plane_normal_basis_3d ( p1, axis );\n%\n% Assemble the randomized information.\n%\n [ radius(1,1:n), seed ] = r8vec_uniform_01 ( n, seed );\n radius(1,1:n) = r * sqrt ( radius(1,1:n) );\n\n [ theta(1,1:n), seed ] = r8vec_uniform_01 ( n, seed );\n theta(1,1:n) = 2.0 * pi * theta(1,1:n);\n\n [ z(1,1:n), seed ] = r8vec_uniform_01 ( n, seed );\n z(1,1:n) = axis_length * z(1,1:n);\n\n for i = 1 : 3\n\n p(i,1:n) = p1(i,1) ...\n + axis(i,1) * z(1,1:n) ...\n + v2(i,1) * radius(1,1:n) .* cos ( theta(1,1:n) ) ...\n + v3(i,1) * radius(1,1:n) .* sin ( theta(1,1:n) );\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/cylinder_sample_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218412907381, "lm_q2_score": 0.8840392756357327, "lm_q1q2_score": 0.815015116767425}} {"text": "classdef ChiD\n%%CHID Functions to handle the chi distribution. \n%These distributions arise when taking the square root of the sum of the\n%squares of independent normal random variables.\n%Implemented methods are: mean, var, moments, PDF, CDF, (supports\n% noncentral distributions) rand, entropy\n%\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nmethods(Static)\n\nfunction val=mean(nu)\n%%MEAN Obtain the mean of central chi probability distribution.\n%\n%INPUTS: nu The number of degrees of freedom of the central chi\n% distribution. Note that nu>0.\n%\n%OUTPUTS: val The mean of the central chi distribution.\n%\n%The mean of the central chi distribution is given in [1].\n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Chi Distribution.\" From MathWorld--A Wolfram Web\n% Resource. http://mathworld.wolfram.com/ChiDistribution.html\n%\n%May 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n \n val=sqrt(2)*exp(gammaln((nu+1)/2)-gammaln(nu/2));\nend\n\nfunction val=var(nu)\n%%VAR Obtain the variance of the central chi probability distribution.\n%\n%INPUTS: nu The number of degrees of freedom of the chi distribution. Note\n% that nu>0.\n%\n%OUTPUTS: val The variance of the central chi distribution.\n%\n%The variance of the central chi distribution is given in [1]. \n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Chi Distribution.\" From MathWorld--A Wolfram Web\n% Resource. http://mathworld.wolfram.com/ChiDistribution.html\n%\n%May 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n val=2*exp(gammaln(1+nu/2)-gammaln(nu/2))-ChiD.mean(nu)^2;\nend\n\nfunction val=moments(m,nu)\n%%MOMENTS Obtain noncentral moments of the chi distribution.\n%\n%INPUTS: m The order of the moment m>=0. The zeroth order moment is just 1.\n% nu The number of degrees of freedom of the chi distribution. Note\n% that nu>0.\n%\n%OUTPUTS: val The mth-degree noncentral moments of the chi distribution.\n%\n%Moments of the chi distribution are given in [1].\n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Chi Distribution.\" From MathWorld--A Wolfram Web\n% Resource. http://mathworld.wolfram.com/ChiDistribution.html\n%\n%May 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n val=2^(m/2)*exp(gammaln((1/2)*(nu+m))-gammaln(nu/2));\nend\n\nfunction val=PDF(x,nu)\n%%PDF Evaluate the central chi probability distribution function (PDF).\n%\n%INPUTS: x The point(s) at which the central chi PDF is to be evaluated.\n% Note that x>=0 for a nonzero probability.\n% nu The number of degrees of freedom of the chi distribution. Note\n% that nu>0. Numerical precision problems can arise for very large\n% values of nu.\n%\n%OUTPUTS: val The value(s) of the central chi PDF evaluated at x.\n%\n%The PDF is given in [1].\n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Chi Distribution.\" From MathWorld--A Wolfram Web\n% Resource. http://mathworld.wolfram.com/ChiDistribution.html\n%\n%May 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n val=zeros(size(x));\n sel=(x>=0);\n \n y=x(sel);\n val(sel)=2^(1-nu/2)*y.^(nu-1).*exp(-y.^2/2)/gamma(nu/2);\nend\n\nfunction prob=CDF(x,nu)\n%%CDF Evaluate the cumulative distribution function (CDF) of the central\n% chi distribution at desired points.\n%\n%INPUTS: x The point(s) at which the chi CDF is to be evaluated.\n% nu The number of degrees of freedom of the chi-square\n% distribution. Note that nu>0.\n%\n%OUTPUTS: prob The value(s) of the CDF of the chi distribution with nu\n% degrees of freedom evaluated at x.\n%\n%The CDF of the central chi distribution is given in [1]. \n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Chi Distribution.\" From MathWorld--A Wolfram Web\n% Resource. http://mathworld.wolfram.com/ChiDistribution.html\n%\n%May 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n prob=gammainc(x.^2/2,nu/2);\nend\n\nfunction vals=rand(N,nu,lambda)\n%%RAND Generate chi distributed random variables with the given 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% nu The number of degrees of freedom of the chi distribution. Note\n% that nu>0. If lambda is not zero, nu >=1.\n% lambda The non-centrality parameter of the distribution. In the central\n% chi distribution, this is zero. If this parameter is omitted or\n% an empty matrix is passed, then 0 is used.\n%\n%OUTPUTS: vals A matrix whose dimensions are determined by N of the\n% generated chi-squared random variables.\n%\n%A chi distributed random variable is just the square root of a chi-squared\n%random variable. Thus, this function takes the square root of\n%ChiSquareD.rand(N,nu,lambda).\n%\n%EXAMPLE:\n%Here, we demonstrate that a histogram of many random samples will tend to\n%agree with the PDF of the central distribution.\n% nu=4.4;\n% lambda=0;\n% numSamp=[10000,1];\n% samp=ChiD.rand(numSamp,nu);\n% figure(1)\n% clf\n% hold on\n% h=histogram(samp,'Normalization','pdf');\n% %We will plot the PDF.\n% numPoints=100;\n% x=linspace(0,20,numPoints);\n% PDFVals=ChiD.PDF(x,nu);\n% plot(x,PDFVals,'-r','linewidth',2)\n%\n%May 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n if(nargin<3||isempty(lambda))\n lambda=0;\n end\n\n if(isscalar(N))\n dims=[N N];\n else\n dims=N;\n end\n\n vals=sqrt(ChiSquareD.rand(dims,nu,lambda));\nend\n\nfunction entropyVal=entropy(nu)\n%%ENTROPY Obtain the differential entropy of the central chi distribution\n% given in nats. The differential entropy of a continuous\n% distribution is entropy=-int_x p(x)*log(p(x)) dx where the\n% integral is over all values of x. Units of nats mean that the\n% natural logarithm is used in the definition. Unlike the Shannon\n% entropy for discrete variables, the differential entropy of\n% continuous variables can be both positive and negative.\n%\n%INPUTS: nu The number of degrees of freedom of the chi distribution. Note\n% that nu>0. \n%\n%OUTPUTS: entropyVal The value of the differential entropy in nats.\n%\n%Differential entropy is defined in Chapter 8 of [1].\n%\n%REFERENCES:\n%[1] T. M. Cover and J. A. Thomas, Elements of Information Theory, 2nd ed.\n% Hoboken, NJ: Wiley-Interscience, 2006.\n%\n%April 2018 David F. Crouse, Naval Research Laboratory, Washington D.C.\n \n entropyVal=gammaln(nu/2)+(1/2)*(nu-log(2)-(nu-1)*psi(nu/2)); \nend\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/ChiD.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342012360932, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.815007184605872}} {"text": "function [xi,w]=thirdOrderSpherShellCubPoints(numDim,rMin)\n%%THIRDORDERSPHERSHELLCUBPOINTS Obtain third order cubature points and\n% weight for integrating spherical region surrounding the\n% origin from radius rMin to radius 1, where rMin>0.\n%\n%INPUTS: numDim An integer specifying the dimensionality of the points to\n% be generated.\n% rMin The minimum radius of the spherical shell. 01)\n N=size(x,2);\n \n if(N>1)\n error('Derivatives are only available for numPoints=1.')\n end\n \n aJacob=[0 0, 1, 0;\n 0, 0, 0, 1;\n thetaDot^2, 0, 0, 2*r*thetaDot;\n 2*rDot*thetaDot/r^2, 0, -((2*thetaDot)/r), -((2*rDot)/r)];\n\n if(nargout>2)\n aHess=zeros(4,4,4);\n\n aHess(:,:,1)=[zeros(2,4);\n 0, 0, 0, 2*thetaDot;\n -((4*rDot*thetaDot)/r^3), 0, (2*thetaDot)/r^2, (2*rDot)/r^2];\n aHess(:,:,3)=[zeros(3,4);\n 2*thetaDot/r^2,0,0,-(2/r)];\n aHess(:,:,4)=[zeros(2,4);\n 2*thetaDot, 0, 0, 2*r;\n 2*rDot/r^2, 0, -((2)/r), -((2*rDot)/r)];\n\n if(nargout>3)\n papt=zeros(4,1);\n end\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/Dynamic_Models/Continuous_Time/Non-Cartesian_Position/aCVPolar.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922387, "lm_q2_score": 0.8670357649558006, "lm_q1q2_score": 0.8149384931772042}} {"text": "% ............................................................. \n function [shape,naturalDerivatives]=shapeFunctionQ4(xi,eta)\n\n % shape function and derivatives for Q4 elements\n % shape : Shape functions\n % naturalDerivatives: derivatives w.r.t. xi and eta \n % xi, eta: natural coordinates (-1 ... +1)\n \n shape=1/4*[ (1-xi)*(1-eta);\n (1+xi)*(1-eta);\n (1+xi)*(1+eta);\n (1-xi)*(1+eta)];\n naturalDerivatives=...\n 1/4*[-(1-eta), -(1-xi);\n 1-eta, -(1+xi);\n\t\t 1+eta, 1+xi;\n -(1+eta), 1-xi];\n\n end % end function shapeFunctionQ4\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/FEM/Abaqus2Matlab/MATLAB ABAQUS Parser Q4/shapeFunctionQ4.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9458012732322216, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.8148439320556423}} {"text": "function [z, mu, sigma] = VBA_zscore (x, flag, dim, omitnan)\n% // VBA toolbox //////////////////////////////////////////////////////////\n%\n% [z, mu, sigma] = VBA_zscore (x, flag, dim, ignore_nans)\n% standard score, aka z-score\n%\n% Compute the stardardized zscore of x, ie z = (x - mean(x)) / std(x)\n%\n% IN:\n% x: vector or matrix to normalize\n% flag: if true, normalizes x using std(X,1), i.e., by computing the\n% standard deviation(s) using N rather than N-1, where N is the length of\n% the dimension along which VBA_zscore works. VBA_zscore(x,0) is the same as\n% VBA_zscore(x). Default = false;\n% dim: dimension along which the standardization is performed. By\n% default, uses the first non singleton dimension.\n% ignore_nans: if true, use nan-safe normalization (default = false).\n%\n% OUT: z-score of x\n%\n% /////////////////////////////////////////////////////////////////////////\n\nif nargin < 2 || isempty (flag)\n\tflag = 0;\nelse\n flag = +(flag > 0);\nend\n\nif nargin < 3 || isempty (dim)\n\tdim = find (size(x) > 1, 1);\n\tif isempty(dim)\n\t\tdim = 1;\n\tend\nend\n\nif nargin < 4\n omitnan = false;\nend\n\nif omitnan\n mu = VBA_nanmean (x, dim);\n sigma = sqrt(VBA_nanvar (x, dim, flag));\nelse\n mu = mean (x, dim);\n sigma = std (x, flag, dim);\nend\nsigma(sigma == 0) = 1;\n\nz = bsxfun(@minus, x, mu);\nz = bsxfun(@rdivide, z, sigma);\n", "meta": {"author": "MBB-team", "repo": "VBA-toolbox", "sha": "01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414", "save_path": "github-repos/MATLAB/MBB-team-VBA-toolbox", "path": "github-repos/MATLAB/MBB-team-VBA-toolbox/VBA-toolbox-01ff63f43ef7a6473bc5e3f28dd9ffa58fcfb414/utils/VBA_zscore.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8918110346549901, "lm_q1q2_score": 0.8148268014930603}} {"text": "function variance = power_variance ( a, b )\n\n%*****************************************************************************80\n%\n%% POWER_VARIANCE returns the variance of the Power PDF.\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% Parameters:\n%\n% Input, real A, B, the parameters of the PDF.\n% 0.0 < A, 0.0 < B.\n%\n% Output, real VARIANCE, the variance of the PDF.\n%\n variance = b * b * a / ( ( a + 1.0 )^2 * ( a + 2.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/prob/power_variance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541577509316, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.8147418465636056}} {"text": "% PROBABILITY DISTRIBUTION FUNCTIONS (in the dist-folder):\n%\n% Priors \n% PRIOR_FIXED Fix parameter to its current value\n% PRIOR_GAMMA Gamma prior structure \n% PRIOR_GAUSSIAN Gaussian prior structure \n% PRIOR_INVGAMMA Inverse-gamma prior structure \n% PRIOR_INVT Inverse Student-t prior structure\n% PRIOR_INVT Inverse uniform prior structure\n% PRIOR_LAPLACE Laplace (double exponential) prior structure\n% PRIOR_LOGGAUSSIAN Log-Gaussian prior structure \n% PRIOR_LOGLOGUNIF Uniform prior structure for the log(log(parameter))\n% PRIOR_LOGT Student-t prior structure for the logarithm of the parameter\n% PRIOR_LOGUNIF Uniform prior structure for the logarithm of the parameter\n% PRIOR_SINVCHI2 Scaled inverse-chi-square prior structure\n% PRIOR_SQRTT Student-t prior structure for the square root of the\n% parameter\n% PRIOR_SQRTUNIF Uniform prior structure for the square root of the\n% parameter\n% PRIOR_UNIF Uniform prior structure \n% PRIOR_T Student-t prior structure\n% PRIOR_SQRTUNIF Uniform prior structure for the square root of the\n% parameter\n%\n% Probability density functions\n%\n% BETA_LPDF - Beta log-probability density function (lpdf).\n% BETA_PDF - Beta probability density function (pdf).\n% DIR_LPDF - Log probability density function of uniform Dirichlet\n% distribution\n% DIR_PDF - Probability density function of uniform Dirichlet\n% distribution\n% GAM_CDF - Cumulative of Gamma probability density function (cdf).\n% GAM_LPDF - Log of Gamma probability density function (lpdf).\n% GAM_PDF - Gamma probability density function (pdf).\n% GEO_LPDF - Geometric log probability density function (lpdf).\n% INVGAM_LPDF - Inverse-Gamma log probability density function.\n% INVGAM_PDF - Inverse-Gamma probability density function.\n% LAPLACE_LPDF - Laplace log-probability density function (lpdf).\n% LAPLACE_PDF - Laplace probability density function (pdf).\n% LOGN_LPDF - Log normal log-probability density function (lpdf)\n% LOGT_LPDF - Log probability density function (lpdf) for log Student's T\n% MNORM_LPDF - Multivariate-Normal log-probability density function (lpdf).\n% MNORM_PDF - Multivariate-Normal log-probability density function (lpdf).\n% NORM_LPDF - Normal log-probability density function (lpdf).\n% NORM_PDF - Normal probability density function (pdf).\n% POISS_LPDF - Poisson log-probability density function.\n% POISS_PDF - Poisson probability density function.\n% SINVCHI2_LPDF - Scaled inverse-chi log-probability density function.\n% SINVCHI2_PDF - Scaled inverse-chi probability density function.\n% T_LPDF - Student's T log-probability density function (lpdf)\n% T_PDF - Student's T probability density function (pdf)\n%\n% Random number generators\n%\n% CATRAND - Random matrices from categorical distribution.\n% DIRRAND - Uniform dirichlet random vectors\n% EXPRAND - Random matrices from exponential distribution.\n% GAMRAND - Random matrices from gamma distribution.\n% INTRAND - Random matrices from uniform integer distribution.\n% INVGAMRAND - Random matrices from inverse gamma distribution\n% INVGAMRAND1 - Random matrices from inverse gamma distribution\n% INVWISHRND - Random matrices from inverse Wishart distribution.\n% NORMLTRAND - Random draws from a left-truncated normal\n% distribution, with mean = mu, variance = sigma2\n% NORMRTRAND - Random draws from a right-truncated normal\n% distribution, with mean = mu, variance = sigma2\n% NORMTRAND - Random draws from a normal truncated to interval\n% NORMTZRAND - Random draws from a normal distribution truncated by zero\n% SINVCHI2RAND - Random matrices from scaled inverse-chi distribution\n% TRAND - Random numbers from Student's t-distribution\n% UNIFRAND - Generate unifrom random numberm from interval [A,B]\n% WISHRND - Random matrices from Wishart distribution.\n%\n% Others\n% KERNELP - Kernel density estimator for one dimensional distribution.\n% HAMMERSLEY - Hammersley quasi-random sequence\n%\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/dmlt/external/gpstuff/dist/Contents.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660936744719, "lm_q2_score": 0.8539127566694177, "lm_q1q2_score": 0.8146038168187243}} {"text": "function fx = p06_fun ( n, x )\n\n%*****************************************************************************80\n%\n%% P06_FUN evaluates the integrand for problem 6.\n%\n% Interval:\n%\n% -1 <= x <= 1\n%\n% Integrand:\n%\n% sqrt ( abs ( x + 0.5 ) )\n%\n% Exact Integral:\n%\n% ( sqrt ( 2 ) + 3 * sqrt ( 6 ) ) / 6 = 1.460447131787105\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 November 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Charles Clenshaw, Alan Curtis,\n% A Method for Numerical Integration on an Automatic Computer,\n% Numerische Mathematik,\n% Volume 2, Number 1, December 1960, pages 197-205.\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 = sqrt ( abs ( x + 0.5 ) );\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/p06_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723468, "lm_q2_score": 0.8824278757303678, "lm_q1q2_score": 0.814515496445418}} {"text": "function alpha = sphericalAngle(p1, p2, p3)\n%SPHERICALANGLE Compute angle between points on the sphere\n%\n% ALPHA = sphericalAngle(P1, P2, P3)\n% Computes angle (P1, P2, P3), i.e. the angle, measured at point P2,\n% between the direction (P2, P1) and the direction (P2, P3).\n% The result is given in radians, between 0 and 2*PI.\n%\n% Points are given either as [x y z] (there will be normalized to lie on\n% the unit sphere), or as [phi theta], with phi being the longitude in [0\n% 2*PI] and theta being the elevation on horizontal [-pi/2 pi/2].\n%\n%\n% NOTE: \n% this is an 'oriented' version of the angle computation, that is, the\n% result of sphericalAngle(P1, P2, P3) equals\n% 2*pi-sphericalAngle(P3,P2,P1). To have the more classical relation\n% (with results given betwen 0 and PI), it suffices to take the minimum\n% of angle and 2*pi-angle.\n% \n% Examples\n% % Use inputs as cartesian coordinates \n% p1 = [0 1 0];\n% p2 = [1 0 0];\n% p3 = [0 0 1];\n% alpha = sphericalAngle(p1, p2, p3)\n% alpha =\n% 1.5708\n%\n% % Use inputs as spherical coordinates \n% sph1 = [.1 0];\n% sph2 = [0 0];\n% sph3 = [0 .1];\n% alphas = sphericalAngle(sph1, sph2, sph3)\n% alphas =\n% 1.5708\n% \n%\n% See also:\n% geom3d, angles3d, spheres, sph2cart\n\n% ---------\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 21/02/2005.\n%\n\n% HISTORY\n% 23-05-2006 fix bug for points with angle from center > pi/2\n% 05-06-2013 fix bug for points given as spherical coordinates, better\n% support for multiple inputs\n\n% test if points are given as matlab spherical coordinates\nif size(p1, 2) == 2\n [x, y, z] = sph2cart(p1(:,1), p1(:,2), ones(size(p1,1), 1));\n p1 = [x y z];\n [x, y, z] = sph2cart(p2(:,1), p2(:,2), ones(size(p2,1), 1));\n p2 = [x y z];\n [x, y, z] = sph2cart(p3(:,1), p3(:,2), ones(size(p3,1), 1));\n p3 = [x y z];\nend\n\n% normalize points\np1 = normalizeVector3d(p1);\np2 = normalizeVector3d(p2);\np3 = normalizeVector3d(p3);\n\n% create the plane tangent to the unit sphere and containing central point\nplane = createPlane(p2, p2);\n\n% project the two other points on the plane\npp1 = planePosition(projPointOnPlane(p1, plane), plane);\npp3 = planePosition(projPointOnPlane(p3, plane), plane);\n\n% compute angle on the tangent plane\npp2 = zeros(max(size(pp1, 1), size(pp3,1)), 2);\nalpha = angle3Points(pp1, pp2, pp3);\n\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/sphericalAngle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552538, "lm_q2_score": 0.8824278757303677, "lm_q1q2_score": 0.8145154945772359}} {"text": "function x = f2_abscissas ( n )\n\n%*****************************************************************************80\n%\n%% F2_ABSCISSAS computes Fejer Type 2 abscissas.\n%\n% Discussion:\n%\n% The interval is [-1,+1].\n%\n% The abscissas are the cosines of equally spaced angles.\n% The angles are computed as N+2 equally spaced values between 0 and PI,\n% but with the first and last angle omitted.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 July 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Philip Davis, Philip Rabinowitz,\n% Methods of Numerical Integration,\n% Second Edition,\n% Dover, 2007,\n% ISBN: 0486453391,\n% LC: QA299.3.D28.\n%\n% Walter Gautschi,\n% Numerical Quadrature in the Presence of a Singularity,\n% SIAM Journal on Numerical Analysis,\n% Volume 4, Number 3, 1967, pages 357-362.\n%\n% Joerg Waldvogel,\n% Fast Construction of the Fejer and Clenshaw-Curtis Quadrature Rules,\n% BIT Numerical Mathematics,\n% Volume 43, Number 1, 2003, pages 1-18.\n%\n% Parameters:\n%\n% Input, integer N, the order of the rule.\n%\n% Output, real X(N), the abscissas.\n%\n if ( n == 1 )\n x(1) = 0.0;\n return\n elseif ( n == 2 )\n x(1) = -0.5;\n x(2) = 0.5;\n return\n end\n\n for i = 1 : n\n theta(i) = ( n + 1 - i ) * pi ...\n / ( n + 1 );\n end\n\n x(1:n) = cos ( theta(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/interp/f2_abscissas.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552538, "lm_q2_score": 0.8824278649085117, "lm_q1q2_score": 0.8145154845882389}} {"text": "function mat = eulerAnglesToRotation3d(phi, theta, psi, varargin)\n%EULERANGLESTOROTATION3D Convert 3D Euler angles to 3D rotation matrix.\n%\n% MAT = eulerAnglesToRotation3d(PHI, THETA, PSI)\n% Creates a rotation matrix from the 3 euler angles PHI THETA and PSI,\n% given in degrees, using the 'XYZ' convention (local basis), or the\n% 'ZYX' convention (global basis). The result MAT is a 4-by-4 rotation\n% matrix in homogeneous coordinates.\n%\n% PHI: rotation angle around Z-axis, in degrees, corresponding to the\n% 'Yaw'. PHI is between -180 and +180.\n% THETA: rotation angle around Y-axis, in degrees, corresponding to the\n% 'Pitch'. THETA is between -90 and +90.\n% PSI: rotation angle around X-axis, in degrees, corresponding to the\n% 'Roll'. PSI is between -180 and +180.\n% These angles correspond to the \"Yaw-Pitch-Roll\" convention, also known\n% as \"Tait–Bryan angles\".\n%\n% The resulting rotation is equivalent to a rotation around X-axis by an\n% angle PSI, followed by a rotation around the Y-axis by an angle THETA,\n% followed by a rotation around the Z-axis by an angle PHI.\n% That is:\n% ROT = Rz * Ry * Rx;\n%\n% MAT = eulerAnglesToRotation3d(ANGLES)\n% Concatenates all angles in a single 1-by-3 array.\n% \n% ... = eulerAnglesToRotation3d(ANGLES, CONVENTION)\n% CONVENTION specifies the axis rotation sequence. \n% Supported conventions are: 'ZYX', 'ZYZ'. Default is 'ZYX'.\n%\n% Example\n% [n e f] = createCube;\n% phi = 20;\n% theta = 30;\n% psi = 10;\n% rot = eulerAnglesToRotation3d(phi, theta, psi);\n% n2 = transformPoint3d(n, rot);\n% drawPolyhedron(n2, f);\n%\n% See also\n% transforms3d, createRotationOx, createRotationOy, createRotationOz\n% rotation3dAxisAndAngle\n%\n\n% ------\n% Author: David Legland\n% e-mail: david.legland@inra.fr\n% Created: 2010-07-22, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2010 INRA - Cepia Software Platform.\n\n% HISTORY\n% 2011-06-20 rename and use degrees\n\np = inputParser;\nvalidStrings = {'ZYX','ZYZ'};\naddOptional(p,'convention','ZYX',@(x) any(validatestring(x,validStrings)));\nparse(p,varargin{:});\nconvention=p.Results.convention;\n\n% Process input arguments\nif size(phi, 2) == 3\n % manages arguments given as one array\n psi = phi(:, 3);\n theta = phi(:, 2);\n phi = phi(:, 1);\nend\n\n% create individual rotation matrices\nk = pi / 180;\n\nswitch convention\n case 'ZYX'\n rot1 = createRotationOx(psi * k);\n rot2 = createRotationOy(theta * k);\n rot3 = createRotationOz(phi * k);\n case 'ZYZ'\n rot1 = createRotationOz(psi * k);\n rot2 = createRotationOy(theta * k);\n rot3 = createRotationOz(phi * k);\nend\n\n% concatenate matrices\nmat = rot3 * rot2 * rot1;\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/eulerAnglesToRotation3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629193, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.8144783818048709}} {"text": "function varargout = circumCenter(a, b, c)\n%CIRCUMCENTER Circumcenter of three points\n%\n% CC = circumCenter(P1, P2, P3)\n%\n% Example\n% A = [10 10]; B = [30 10]; C = [10 20];\n% circumCenter(A, B, C)\n% ans =\n% 20 15\n%\n% % works also for multiple input points\n% circumCenter([A;A;A], [B;B;B], [C;C;C])\n% ans =\n% 20 15\n% 20 15\n% 20 15\n%\n%\n% See also\n% points2d, circles2d, circumCircle, centroid\n%\n\n% ------\n% Author: David Legland\n% e-mail: david.legland@inra.fr\n% Created: 2011-12-09, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2011 INRA - Cepia Software Platform.\n\n% pre-compute some terms\nah = sum(a .^ 2, 2);\nbh = sum(b .^ 2, 2);\nch = sum(c .^ 2, 2);\n\ndab = a - b;\ndbc = b - c;\ndca = c - a;\n\n% common denominator\nD = .5 ./ (a(:,1) .* dbc(:,2) + b(:,1) .* dca(:,2) + c(:,1) .* dab(:,2));\n\n% center coordinates\nxc = (ah .* dbc(:,2) + bh .* dca(:,2) + ch .* dab(:,2) ) .* D;\nyc = -(ah .* dbc(:,1) + bh .* dca(:,1) + ch .* dab(:,1) ) .* D;\n\nif nargout <= 1\n varargout = {[xc yc]};\nelse\n varargout = {xc, yc};\nend\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/geom2d/circumCenter.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086179018818864, "lm_q2_score": 0.8962513772903669, "lm_q1q2_score": 0.8143500459923241}} {"text": "function [xi,w]=fourthOrderPyramidCubPoints()\n%%FOURTHORDERPYRAMIDCUBPOINTS Generate fourth-order cubature points for\n% integration over a 3-dimensional pyramid with a square base with the\n% peak vertex at (0,0,1) and the base vertices at (1,-1,-1), (-1,-1,-1),\n% (-1,1,-1), and (1,1,-1).\n% \n%INPUTS: None\n%\n%OUTPUTS: xi This is a 3XnumCubPoints set of points for the standard\n% square pyramid.\n% w A 1XnumCubPoints set of cubature weights. This sums to the\n% volume of the standard square pyramid (8/3).\n%\n%This function implements the points given in [1] (10 points).\n%\n%EXAMPLE:\n%We compare a 4th-order moment computed using these cubature points\n%to one computed using monomialIntPyramid. The results are the same within\n%typical finite precision limits.\n% [xi,w]=fourthOrderPyramidCubPoints();\n% alpha=[2;0;2];\n% theMoment=findMomentFromSamp(alpha,xi,w);\n% intVal=monomialIntPyramid(alpha);\n% RelErr=(theMoment-intVal)/intVal\n%\n%REFERENCES:\n%[1] F. D. Witherden and P. E. Vincent, \"On the identification of symmetric\n% quadrature rules for finite element methods,\" Computer and Mathematics\n% with Applications, vol. 69, no. 10, pp. 1232-1241, May 2015.\n%\n%October 2022 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nM=[ 0, 0, 0.35446557777227471722730849524904581806, 0.30331168845504517111391728481208001144;\n 0, 0, -0.74972609378250711033655604388057044149, 0.55168907357213937275730716433358729608;\n 0.6505815563982325146829577797417295398, 0, -0.35523170084357268589593075201816127231, 0.28353223437153468006819777082540613962;\n 0, 0.6505815563982325146829577797417295398, -0.35523170084357268589593075201816127231, 0.28353223437153468006819777082540613962;\n -0.6505815563982325146829577797417295398, 0, -0.35523170084357268589593075201816127231, 0.28353223437153468006819777082540613962;\n 0, -0.6505815563982325146829577797417295398, -0.35523170084357268589593075201816127231, 0.28353223437153468006819777082540613962;\n 0.65796699712169008954533549931479427127, 0.65796699712169008954533549931479427127, -0.92150343220236930457646242598412224897, 0.16938424178833585063066278355484370017;\n 0.65796699712169008954533549931479427127, -0.65796699712169008954533549931479427127, -0.92150343220236930457646242598412224897, 0.16938424178833585063066278355484370017;\n-0.65796699712169008954533549931479427127, 0.65796699712169008954533549931479427127, -0.92150343220236930457646242598412224897, 0.16938424178833585063066278355484370017;\n-0.65796699712169008954533549931479427127, -0.65796699712169008954533549931479427127, -0.92150343220236930457646242598412224897, 0.16938424178833585063066278355484370017];\n\nw=M(:,4);\nxi=M(:,1:3)';\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/Numerical_Integration/Cubature_Points/Pyramid/fourthOrderPyramidCubPoints.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346504434783, "lm_q2_score": 0.8705972784807406, "lm_q1q2_score": 0.8143101211973961}} {"text": "function [Fn,Ln] = fibonacci(n,modulus)\n% fibonacci: vpi tool to efficiently compute the n'th Fibonacci number and the n'th Lucas number\n% usage: [Fn,Ln] = fibonacci(n)\n% usage: [Fn,Ln] = fibonacci(n,modulus)\n%\n% Compute the nth Fibonacci number as well as the nth Lucas\n% Lucas number. In the event that all members of these\n% sequences from 1 to n are desired, then a simple,\n% direct loop would be more efficient, and more direct.\n%\n% Both the Fibonacci numbers and the Lucas numbers\n% are defined by the same basic recursion:\n%\n% F(n) = F(n-1) + F(n-2)\n% L(n) = L(n-1) + L(n-2)\n%\n% The difference is the starting point. The Fibonacci\n% numbers start with F(1) = F(2) = 1, whereas the Lucas\n% sequence starts with L(1) = 1, and L(2) = 3. The first\n% few members of these sequences are:\n%\n% Fibonacci: [1 1 2 3 5 8 13 21 ... ]\n% Lucas: [1 3 4 7 11 18 29 ... ]\n%\n% These sequences are also defined for n = 0 and for\n% negative values of n.\n%\n% For efficiency, fibonacci uses a variety of tricks to\n% maximize speed. While computation of fibonacci numbers\n% is commonly done recursively, fibonacci does so using a\n% direct iterative scheme given the binary representation\n% of n. In addition, several Fibonacci and Lucas number\n% identities are employed to maximize throughput.\n%\n% The methods employed by fibonacci will be O(log2(n)) in time.\n%\n%\n% Arguments: (input)\n% n - any non-negative integer, vpi or numeric.\n% n must be less than 2^53 (in theory. Even that\n% number would be impossibly huge to compute.\n% Don't bother to try it.) In practice, recognize\n% that F(1e6) is a number with 208995 digits.\n%\n% When n is a vector or array, fibonacci will\n% generate each of the indicated Fibonacci and\n% Lucas numbers.\n%\n% modulus - (OPTIONAL) - allows the computation of the\n% indicated Fibonacci/Lucas numbers modulo a given\n% modulus. This enables the computation of such\n% numbers for truly immense index.\n%\n% Arguments: (output)\n% Fn, Ln - scalar vpi number, containing the nth\n% Fibonacci number and nth Lucas numbers in\n% their respective sequences.\n%\n% Example:\n% [Fn,Ln] = fibonacci(150)\n%\n% Fn =\n% 9969216677189303386214405760200\n% Ln =\n% 22291846172619859445381409012498\n%\n% See also: \n%\n% Author: John D'Errico\n% e-mail: woodchips@rochester.rr.com\n% Release: 1.0\n% Release date: 4/30/09\n\nif (nargin < 1) || (nargin > 2)\n error('fibonacci accepts only 1 or 2 arguments')\nelseif any(n(:)~=round(n(:))) || any(abs(n) > 2^53)\n error('n must be an integer, <= 2^53 in absolute value')\nend\n\n% was a modulus provided?\nif (nargin < 2)\n modulus = [];\nend\n\n% The first 15 Fibonacci and Lucas numbers to\n% start things off efficiently.\nFseq = [0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610];\nLseq = [2 1 3 4 7 11 18 29 47 76 123 199 322 521 843 1364];\n\nif ~isempty(modulus)\n Fseq = mod(Fseq,modulus);\n Lseq = mod(Lseq,modulus);\nend\n\n% intialize Fn and Ln to the proper size,\n% in case n is a vector or array\nFn = repmat(vpi(0),size(n));\nLn = Fn;\n\n% much faster if n is not a vpi but a double.\n% also, we don't need to worry about n being\n% larger than 2^53, as this would have a vast\n% number of digits.\nn = double(n(:));\n\n% catch any zeros in n first.\nk = (n(:) == 0);\n% Fn(k) is already zero\nif any(k)\n Ln(k) = vpi(2);\nend\n\n% Negative values for n will be inconvenient\n% in a loop, so make them all positive. deal\n% with any signs later.\nnsign = 2*(n>=0) - 1;\nif any(n<0)\n neven = iseven(n);\n n = abs(n);\nend\n\nif numel(n) > 1\n % sort them and work upwards\n [n,ntags] = sort(n);\n \n flag = false;\n for i = 1:numel(n)\n if n(i) <= 15\n % small values of n are pre-computed\n Fn(i) = Fseq(n(i) + 1);\n Ln(i) = Lseq(n(i) + 1);\n elseif (i == 1) || ((n(i) - n(i-1)) > 15)\n % the smallest value of n is > 15,\n % or the difference from the last value\n % computed was too large\n [Fn(i),Ln(i)] = fibonacci(n(i),modulus);\n \n flag = false;\n elseif n(i) == n(i-1)\n % will happen if there were positive and\n % negative values in the list\n Fn(i) = Fn(i-1);\n Ln(i) = Ln(i-1);\n \n flag = false;\n elseif (n(i) == (n(i-1)+1))\n % we can use an addition formula to\n % get Fn & Ln. Which one?\n if flag\n % the last two values of n were\n % separated by 1, so just use the\n % two term recurrence\n Fn(i) = (Fn(i-1) + Fn(i-2));\n Ln(i) = (Ln(i-1) + Ln(i-2));\n if ~isempty(modulus)\n Fn(i) = mod(Fn(i),modulus);\n Ln(i) = mod(Ln(i),modulus);\n end\n else\n % we must use the addition formula\n Fn(i) = (Fn(i-1) + Ln(i-1))./2;\n Ln(i) = (5 .*Fn(i-1) + Ln(i-1))./2;\n if ~isempty(modulus)\n Fn(i) = mod(Fn(i),modulus);\n Ln(i) = mod(Ln(i),modulus);\n end\n \n % flag indicates whether the last two\n % numbers were consecutive\n flag = true;\n end\n \n else\n % 1 < n(i) - n(i-1) <= 15\n m = n(i) - n(i-1);\n Fm = Fseq(m+1);\n Lm = Lseq(m+1);\n \n % use an addition formula\n Fn(i) = (Fm.*Ln(i-1) + Lm.*Fn(i-1))./2;\n Ln(i) = (5 .*Fm.*Fn(i-1) + Lm.*Ln(i-1))./2;\n if ~isempty(modulus)\n Fn(i) = mod(Fn(i),modulus);\n Ln(i) = mod(Ln(i),modulus);\n end\n\n flag = false;\n end\n \n end % for i = 1:numel(n)\n \n % shuffle Fn and Ln to reflect the sort\n Fn(ntags) = Fn;\n Ln(ntags) = Ln;\n \nelse\n % For only one value of n, compute it individually.\n % Uses an efficient iterative (recursive, but not\n % really so) scheme.\n \n % get the binary representation of n. Thus\n % nbin is a character vector, of length\n % ceil(log2(n)).\n nbin = dec2bin(n);\n \n % get the 4 highest order bits from nbin\n k = min(numel(nbin),4);\n \n % start the sequence from the top\n % few bits of n.\n nhigh = bin2dec(nbin(1:k));\n \n Fn = vpi(Fseq(nhigh+1));\n Ln = vpi(Lseq(nhigh+1));\n \n % We need to loop forwards. Essentially, we started\n % with the highest order bit(s) of the binary representation\n % for n. Look at each successively lower order bit.\n % If the next bit is 0, then we are essentially doubling\n % the index at this step. If the next bit is odd, then\n % we are moving to 2*n+1.\n for k = 5:numel(nbin)\n bit = (nbin(k) == '1');\n if bit\n % the next bit was odd. Use\n % a 2*n+1 rule to step up.\n F2n = Fn.*Ln;\n % we want to do this...\n % L2n = (5 .*Fn.*Fn + Ln.*Ln)./2;\n % Instead use the identity that\n % 5F(n)^2 + L(n)^2 = 2*L(n)^2 + 4*(-1)^(n+1)\n % to make that expression more efficiently\n % computed. See that the form used below\n % has only a single multiplication between a\n % pair of large integers, whereas the prior\n % form for L2n would have had several multiples\n % as well as a divide.\n L2n = Ln.*Ln + 2*(-1)^(nhigh+1);\n \n Fn = (L2n + F2n)./2;\n Ln = (5 .*F2n + L2n)./2;\n if ~isempty(modulus)\n Fn = mod(Fn,modulus);\n Ln = mod(Ln,modulus);\n end\n else\n % the next bit was even. Use the 2*n\n % rule to step up.\n F2n = Fn.*Ln;\n Ln = Ln.*Ln + 2*(-1)^(nhigh+1);\n Fn = F2n;\n if ~isempty(modulus)\n Fn = mod(Fn,modulus);\n Ln = mod(Ln,modulus);\n end\n end\n \n % update the top bits of n\n nhigh = 2*nhigh + bit;\n end % for k = 5:numel(nbin)\n \nend % if numel(n) > 1\n\n% if n was negative, then we may need to apply a\n% sign change to Fn and Ln.\nif any(nsign < 0)\n k = neven & (nsign < 0);\n Fn(k) = -Fn(k);\n\n k = (~neven) & (nsign < 0);\n Ln(k) = -Ln(k);\n \n if ~isempty(modulus)\n Fn(k) = mod(Fn(k),modulus);\n Ln(k) = mod(Ln(k),modulus);\n end\nend\n\n% ==================================\n% End mainline, begin subfunctions.\n% ==================================\n\nfunction result = iseven(n)\n% tests if a scalar value is an even integer, works\n% for either numeric or vpi inputs\nif isnumeric(n)\n result = (mod(n,2) == 0);\nelseif isa(n,'vpi')\n % must have been a vpi\n result = (mod(trailingdigit(n,1),2) == 0);\nelse\n error('n must be either numeric or vpi')\nend\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/34766-the-fibonacci-sequence/FibonacciSequence/fibonacci.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370312, "lm_q2_score": 0.8705972633721708, "lm_q1q2_score": 0.8143101086346805}} {"text": "function [midpoint,minDist,t]=closestPointBetween2Lines(a1,b1,a2,b2)\n%%CLOSESTPOINTBETWEEN2LINES Given two non-parallel lines in numDim\n% dimensions that do not necessarily intersect, find the point\n% closest to both lines. This is done by finding the point on\n% each line that is closest to the other line, and then\n% averaging the points (get the point halfway between the\n% lines).\n%\n%INPUTS: a1,b1 numDimXN matrix of parameters for the first line in N pairs\n% of lines, the closes point between each being desired. The\n% ith line is represented in parametic form as\n% r=a1(:,i)*t+b1(:,i), where t is a scalar parameter and p is\n% a point on the line.\n% a2,b2 The numDimXN set of parameters for the second lines.\n% \n%OUTPUTS: midpoint The numDimXN set of closest points between each of the N\n% pairs of lines.\n% minDist The NX1 set of minimum distances between the pairs of\n% lines.\n% t The 2XN set of values of t used in the linear equations\n% to get the minimum points. These values can be positive\n% or negative.\n%\n%Line 1 is r1=a1*t1+b1 and line 2 is r2=a2*t2+b2. We want to find the\n%values of t1 and t2 such that norm(r1-r2)^2 is minimized.\n%norm(r1-r2)^2=norm(a1*t1+b1-a2*t2-b2)^2\n% =norm(A*T+c)^2 where A=[a1,-a2] and c=b1-b2 and T=[t1;t2]\n% =T'*A'*A*T+2*c'*A*T+c'*c\n%Setting the derivative with respect to the vector T equal to zero, we get\n% 2*A'*A*T+2*A'*c=0\n%The solution is T=-inv(A'*A)*A'*c, which (being the zero deivative point)\n%is an extrema and being the only extrema (unless the lines are parallel)\n%is the closest point between the lines. The pinv function is used to\n%evaluate (A'*A)\\A' as it is more stable.\n%\n%EXAMPLE 1:\n%This is a simple 2D case, so the lines intersect. The starting points are\n%drawn in blue and lines with positive t are drawn in blue. The\n%intersection point is marked in red.\n% x1=[4;3];\n% u1=[3;2];\n% u1=u1/norm(u1);\n% x2=[6;7];\n% u2=[6;-1];\n% u2=u2/norm(u2);\n% r=10;\n% p1=[x1,x1+r*u1];\n% p2=[x2,x2+r*u2];\n% figure(1)\n% clf\n% hold on\n% scatter(x1(1),x1(2),400,'.b')\n% scatter(x2(1),x2(2),400,'.b')\n% plot(p1(1,:),p1(2,:),'-b')\n% plot(p2(1,:),p2(2,:),'-b')\n% pt=closestPointBetween2Lines(u1,x1,u2,x2);\n% scatter(pt(1),pt(2),300,'.r')\n%\n%EXAMPLE 2:\n%This is the same as example 1, but is in 3D. This time, the lines do not\n%intersect in 3D, so we use t to compute the two nearest points on either\n%line and we draw a red line between them.\n% x1=[4;3;8];\n% u1=[3;2;0];\n% u1=u1/norm(u1);\n% x2=[6;7;-2];\n% u2=[6;-1;4];\n% u2=u2/norm(u2);\n% \n% r=20;\n% p1=[x1,x1+r*u1];\n% p2=[x2,x2+r*u2];\n% figure(1)\n% clf\n% hold on\n% scatter3(x1(1),x1(2),x1(3),400,'.b')\n% scatter3(x2(1),x2(2),x2(3),400,'.b')\n% plot3(p1(1,:),p1(2,:),p1(3,:),'-b')\n% plot3(p2(1,:),p2(2,:),p2(3,:),'-b')\n% [p,~,t]=closestPointBetween2Lines(u1,x1,u2,x2);\n% scatter3(p(1),p(2),p(3),200,'.r')\n% pt1=x1+t(1)*u1;\n% pt2=x2+t(2)*u2;\n% plot3([pt1(1);pt2(1)],[pt1(2);pt2(2)],[pt1(3);pt2(3)],'-r')\n% view(8,90)\n%\n%March 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nN=size(a1,2);\nnumDim=size(a1,1);\n\nminDist=zeros(N,1);\nmidpoint=zeros(numDim,N);\nt=zeros(2,N);\nfor i=1:N\n A=[a1(:,i),-a2(:,i)];\n c=b1(:,i)-b2(:,i);\n\n %pinv(A)=(A'*A)\\A', we are doing pinv(A)*c using lsqminnorm.\n TMin=-lsqminnorm(A,c);\n\n t(:,i)=TMin;\n \n r1Min=a1*TMin(1)+b1;\n r2Min=a2*TMin(2)+b2;\n \n minDist(i)=norm(r1Min-r2Min);\n midpoint(:,i)=(r1Min+r2Min)/2;\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/closestPointBetween2Lines.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465098415279, "lm_q2_score": 0.8705972566572503, "lm_q1q2_score": 0.8143101054919679}} {"text": "function p = predict(Theta1, Theta2, X)\n%PREDICT Predict the label of an input given a trained neural network\n% p = PREDICT(Theta1, Theta2, X) outputs the predicted label of X given the\n% trained weights of a neural network (Theta1, Theta2)\n\n% Useful values\nm = size(X, 1);\nnum_labels = size(Theta2, 1);\n\n% You need to return the following variables correctly \np = zeros(size(X, 1), 1);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Complete the following code to make predictions using\n% your learned neural network. You should set p to a \n% vector containing labels between 1 to num_labels.\n%\n% Hint: The max function might come in useful. In particular, the max\n% function can also return the index of the max element, for more\n% information see 'help max'. If your examples are in rows, then, you\n% can use max(A, [], 2) to obtain the max for each row.\n%\n\na1 = [ones(m, 1) X]; % add 1\n\nz2 = a1 * Theta1';\n\na2 = [ones(size(sigmoid(z2), 1), 1) sigmoid(z2)]; % add 1\n\nz3 = a2 * Theta2';\na3 = sigmoid(z3); % H_theta(x)\n\n[x, ix] = max(a3, [], 2);\n\np = ix;\n\n% =========================================================================\n\n\nend\n", "meta": {"author": "1094401996", "repo": "machine-learning-coursera", "sha": "e53d1021a08b0f2ab7e0840d9807ab14e24ea9bb", "save_path": "github-repos/MATLAB/1094401996-machine-learning-coursera", "path": "github-repos/MATLAB/1094401996-machine-learning-coursera/machine-learning-coursera-e53d1021a08b0f2ab7e0840d9807ab14e24ea9bb/problem_sets/ex3_solution/predict.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954106, "lm_q2_score": 0.8688267847293731, "lm_q1q2_score": 0.8142738354608521}} {"text": "function [ n_data, n, c ] = omega_values ( n_data )\n\n%*****************************************************************************80\n%\n%% OMEGA_VALUES returns some values of the OMEGA function.\n%\n% Discussion:\n%\n% In Mathematica, the function can be evaluated by\n%\n% Length [ FactorInteger [ n ] ]\n%\n% First values:\n%\n% N OMEGA(N)\n%\n% 1 0\n% 2 1\n% 3 1\n% 4 1\n% 5 1\n% 6 2\n% 7 1\n% 8 1\n% 9 1\n% 10 2\n% 11 1\n% 12 2\n% 13 1\n% 14 2\n% 15 2\n% 16 1\n% 17 1\n% 18 2\n% 19 1\n% 20 2\n%\n% Formula:\n%\n% If N = 1, then\n%\n% OMEGA(N) = 0\n%\n% else if the prime factorization of N is\n%\n% N = P1^E1 * P2^E2 * ... * PM^EM,\n%\n% then\n%\n% OMEGA(N) = M\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 17 April 2013\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 OMEGA function.\n%\n% Output, integer C, the value of the OMEGA function.\n%\n n_max = 23;\n\n c_vec = [ ...\n 0, 1, 1, 1, 1, ...\n 2, 1, 1, 1, 2, ...\n 3, 1, 4, 4, 3, ...\n 1, 5, 2, 2, 1, ...\n 6, 7, 8 ];\n\n n_vec = [ ...\n 1, ...\n 2, ...\n 3, ...\n 4, ...\n 5, ...\n 6, ...\n 7, ...\n 8, ...\n 9, ...\n 10, ...\n 30, ...\n 101, ...\n 210, ...\n 1320, ...\n 1764, ...\n 2003, ...\n 2310, ...\n 2827, ...\n 8717, ...\n 12553, ...\n 30030, ...\n 510510, ...\n 9699690 ];\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/omega_values.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.8887587831798665, "lm_q1q2_score": 0.8142004654331105}} {"text": "function [R,t,PfromTransformed]=rigidTransformation(Pfrom,Pto,varargin)\n%% Find the optimal rigid body transformation between two point clouds %%%%%%%%%\n% The optimal solution is the least square minimization solution between\n% the two point clouds. See (Rubin & Solav 2016)\n% The two point clouds must be corresponded (indeces refer to the same point)\n\n%% INPUT:\n% Pfrom= point cloud (to be transformed into TruP)\n% Pto= true 3D point cloud\n% * optional input: \n% estimation method: 'rigid' (default) or 'affine'\n\n%% OUTPUT:\n% R = estimated rotation matrix from Pfrom to Pto (3-by-3)\n% t = estimated translation vector (3-by-1)\n% PfromTransformed = Pfrom transformed using R and t\n\n%%\nnArg=numel(varargin);\n\nswitch nArg\n case 0\n estimationMethod='rigid';\n case 1\n estimationMethod=varargin{1};\nend\n\n\n\n%%\na=Pfrom;\nb=Pto; \n\n% find NaNs\naNanInd=find(isnan(a(:,1)));\nbNanInd=find(isnan(b(:,1)));\nabNanInd=[aNanInd; bNanInd];\n% delete Nans\naNoNan=a;\naNoNan(abNanInd,:)=[];\nbNoNan=b;\nbNoNan(abNanInd,:)=[];\n\nac=(1/length(aNoNan))*sum(aNoNan); % centroid of RecP.\nbc=(1/length(bNoNan))*sum(bNoNan); % centroid of TruP.\n\nda=aNoNan-ac;\ndb=bNoNan-bc;\n\nswitch estimationMethod\n \n case 'rigid'\n M=db'*da;\n [U,~,V] = svd(M);\n S=[1 0 0; 0 1 0; 0 0 det(U*V')];\n R=U*S*V'; %rotation matrix from reconstructed coordinates to true\n t=bc'-R*ac'; %translation vector from centroid of reconstructed coordinates to true- this is the translation of the origin of the coordinate system!\n \n case 'affine'\n M=db'*da;\n A=da'*da;\n F=M/A;\n% R=F*(F'*F)^-.5; % this gives the same solution as the svd\n [U,~,V] = svd(F);\n S=[1 0 0; 0 1 0; 0 0 det(U*V')];\n R=U*S*V'; %rotation matrix from reconstructed coordinates to true\n t=bc'-R*ac'; %translation vector from centroid of reconstructed coordinates to true- this is the translation of the origin of the coordinate system!\n \nend\n\nPfromTransformed=(R*a'+t)'; %transformed constructed coordinates\n\n\n% residuals=PfromTransformed-Pto;\n% residualsMgn=sqrt(sum(residuals.^2,2));\n% residulasMgnRMS=sqrt(nansum(residualsMgn.^2)/sum(~isnan(residualsMgn)));\n\n\nend\n \n%% \n% MultiDIC: a MATLAB Toolbox for Multi-View 3D Digital Image Correlation\n% \n% License: \n% \n% Copyright (C) 2018 Dana Solav\n% \n% If you use the toolbox/function for your research, please cite our paper:\n% ", "meta": {"author": "MultiDIC", "repo": "MultiDIC", "sha": "d363c3ea74673e58df275d4a4c8e528ef5472acb", "save_path": "github-repos/MATLAB/MultiDIC-MultiDIC", "path": "github-repos/MATLAB/MultiDIC-MultiDIC/MultiDIC-d363c3ea74673e58df275d4a4c8e528ef5472acb/lib_MultiDIC/rigidTransformation.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.8670357546485407, "lm_q1q2_score": 0.8141680926924547}} {"text": "function ta = acf(y,p)\n% ACF - Compute Autocorrelations Through p Lags\n% >> myacf = acf(y,p) \n%\n% Inputs:\n% y - series to compute acf for, nx1 column vector\n% p - total number of lags, 1x1 integer\n%\n% Output:\n% myacf - px1 vector containing autocorrelations\n% (First lag computed is lag 1. Lag 0 not computed)\n%\n%\n% A bar graph of the autocorrelations is also produced, with\n% rejection region bands for testing individual autocorrelations = 0.\n%\n% Note that lag 0 autocorelation is not computed, \n% and is not shown on this graph.\n%\n% Example:\n% >> acf(randn(100,1), 10)\n%\n\n\n% --------------------------\n% USER INPUT CHECKS\n% --------------------------\n\n[n1, n2] = size(y) ;\nif n2 ~=1\n error('Input series y must be an nx1 column vector')\nend\n\n[a1, a2] = size(p) ;\nif ~((a1==1 & a2==1) & (p abs(bar_hi)) % if rejection lines might not appear on graph\n axis([0 p+.60 line_lo line_hi])\nelse\n axis([0 p+.60 bar_lo bar_hi])\nend\ntitle({' ','Sample Autocorrelations',' '})\nxlabel('Lag Length')\nset(gca,'YTick',[-1:.20:1])\n% set number of lag labels shown\nif (p<28 & p>4)\n set(gca,'XTick',floor(linspace(1,p,4)))\nelseif (p>=28)\n set(gca,'XTick',floor(linspace(1,p,8)))\nend\nset(gca,'TickLength',[0 0])\n\n\n\n\n% ---------------\n% SUB FUNCTION\n% ---------------\nfunction ta2 = acf_k(y,k)\n% ACF_K - Autocorrelation at Lag k\n% acf(y,k)\n%\n% Inputs:\n% y - series to compute acf for\n% k - which lag to compute acf\n% \nglobal ybar\nglobal N\ncross_sum = zeros(N-k,1) ;\n\n% Numerator, unscaled covariance\nfor i = (k+1):N\n cross_sum(i) = (y(i)-ybar)*(y(i-k)-ybar) ;\nend\n\n% Denominator, unscaled variance\nyvar = (y-ybar)'*(y-ybar) ;\n\nta2 = sum(cross_sum) / yvar ;\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/30540-autocorrelation-function-acf/acf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.8840392848011834, "lm_q1q2_score": 0.8140142503701796}} {"text": "function an=random_unit_vector(varargin)\n% random_unit_vector\n% random_unit_vector(n)\n% random_unit_vector(m,n)\n% random_unit_vector([m n])\n% random_unit_vector('double')\n% random_unit_vector(n,'double')\n% random_unit_vector(m,n,'double')\n% random_unit_vector([m n],'double')\n% random_unit_vector('single')\n% random_unit_vector(n,'single')\n% random_unit_vector(m,n,'single')\n% random_unit_vector([m n],'single')\n\n% m - dimentionarity \n% n - number of unit vectors\n\nmd=3; % default m\n\nisg=false; % if single\nswitch nargin\n case 0\n % if no inputs\n n=1;\n m=md;\n case 1\n %\n i1=varargin{1};\n if ischar(i1)\n if strcmpi(i1,'single')\n isg=true;\n end\n else\n if length(i1)==1\n m=md;\n n=i1;\n else\n m=i1(1);\n n=i1(2);\n end\n end\n case 2\n i1=varargin{1};\n i2=varargin{2};\n if ischar(i2)\n if length(i1)==1\n m=md;\n n=i1;\n else\n m=i1(1);\n n=i1(2);\n end\n if strcmpi(i2,'single')\n isg=true;\n end\n else\n m=i1;\n n=i2;\n end\n case 3\n m=varargin{1};\n n=varargin{2};\n if strcmpi(varargin{3},'single')\n isg=true;\n end\n \n \nend\n\n% simple case of 1d\nif m==1\n if isg\n an=single(2*(randn(1,n)>0)-1);\n else\n an=2*(randn(1,n)>0)-1;\n end\n return;\nend\n\nif isg\n v=randn(m,n,'single');\nelse\n v=randn(m,n);\nend\n\n% normalize:\nif isg\n an=zeros(m,n,'single');\nelse\n an=zeros(m,n);\nend\nfor nc=1:n\n while 1\n v2=v(:,nc)'*v(:,nc);\n if v2>1e-10 % too small values must be excluded \n % because it will have discretization errors\n an(:,nc)=v(:,nc)/sqrt(v2);\n break;\n else\n % otherwise repeat random generation\n if isg\n v(:,nc)=randn(m,1,'single');\n else\n v(:,nc)=randn(m,1);\n end\n end\n end\nend\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/25363-random-unit-vector-generator/random_unit_vector.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897426182321, "lm_q2_score": 0.8652240738888188, "lm_q1q2_score": 0.8139939337809601}} {"text": "%KDGAUSS Derivative of Gaussian kernel\n%\n% K = KDGAUSS(SIGMA) is a 2-dimensional derivative of Gaussian kernel (WxW)\n% of width (standard deviation) SIGMA and centred within the matrix K whose \n% half-width H = 3xSIGMA and W=2xH+1.\n%\n% K = KDGAUSS(SIGMA, H) as above but the half-width is explictly specified.\n%\n% Notes::\n% - This kernel is the horizontal derivative of the Gaussian, dG/dx.\n% - The vertical derivative, dG/dy, is K'.\n% - This kernel is an effective edge detector.\n%\n% See also KGAUSS, KDOG, KLOG, ISOBEL, ICONV.\n\n% Copyright (C) 1993-2011, by Peter I. Corke\n%\n% This file is part of The Machine Vision Toolbox for Matlab (MVTB).\n% \n% MVTB 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% MVTB 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 MVTB. If not, see .\n\nfunction m = kdgauss(sigma, w)\n\n\n if nargin == 1,\n w = ceil(3*sigma);\n end\n ww = 2*w + 1;\n\n [x,y] = meshgrid(-w:w, -w:w);\n\n % This should properly be\n % m = -x/sigma^4 /(2*pi) .* exp( -(x.^2 + y.^2)/2/sigma^2);\n % but the effect of the error is simply to scale the result by sigma^2.\n %\n % Too many results in the book depend on this...\n \n m = -x/sigma^2 /(2*pi) .* exp( -(x.^2 + y.^2)/2/sigma^2);\n\n\n", "meta": {"author": "petercorke", "repo": "machinevision-toolbox-matlab", "sha": "2d791168c19c5e56acef74d22eafd227b4b58e42", "save_path": "github-repos/MATLAB/petercorke-machinevision-toolbox-matlab", "path": "github-repos/MATLAB/petercorke-machinevision-toolbox-matlab/machinevision-toolbox-matlab-2d791168c19c5e56acef74d22eafd227b4b58e42/kdgauss.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9489172601537141, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.8139509600344527}} {"text": "% MAIN.m -- Robot Arm Trajectory\n%\n% Given an initial and final state, as well as joint angle and rate\n% constraints, find the minimum-jerk trajectory that solves the boundary\n% value problem.\n%\n%\n\nn = 15; %Order of interpolating polynomial;\n\n% Problem specifications:\ntStart = 0; \ntFinal = 1;\nqLow = -pi;\nqUpp = pi;\ndqMax = 1.5; %Joint speed limit\n\n% Boundary values\nqStart = 0;\nqFinal = 1;\ndqStart = 0;\ndqFinal = -1.5;\n\n% Derivatives\nD = chebyshevDifferentiationMatrix(n,[tStart,tFinal]); %Rates\nDD = D*D; %Accelerations\nDDD = DD*D; %Jerk\n\n% Chebyshev grid and quadrature weights:\n[t,w] = chebyshevPoints(n,[tStart,tFinal]);\n\n%%%% Quadratic Program:\n% min 0.5*x'*H*x + f'*x subject to: A*x <= b\n% x Aeq*x == beq\n% LB <= x <=UB\n\n%%%% Boundary Values:\nAeq = zeros(4,n); beq = zeros(4,1);\nAeq(1,1) = 1; beq(1) = qStart;\nAeq(2,end) = 1; beq(2) = qFinal;\nAeq(3:4,:) = D([1,end],:); beq(3:4) = [dqStart; dqFinal];\n\n%%%% Dynamics:\n% u == DDD*x; %Equality Constraint - expressed directly in cost function\n\n%%%% Joint Rate Limits:\n% -dqMax <= D*x <= dqMax\nA = [D;-D];\nb = [dqMax*ones(n,1); dqMax*ones(n,1)];\n\n%%%% Joint Angle Limits:\n% qLow <= x <= qUpp\nLB = qLow*ones(n,1);\nUB = qUpp*ones(n,1);\n\n%%%% Objective Function:\n% min w*(u^2) = x'*(DDD'*W*DDD); W = diag(w);\nW = diag(w);\nH = 0.5*(DDD'*W*DDD);\n\n%%%% Initialize: (Linear trajectory)\nxGuess = interp1([tStart;tFinal],[qStart;qFinal],t');\n\n%%%% Options:\noptions = optimset(...\n 'Display','iter',... % {'iter','final'}\n 'Algorithm','interior-point-convex');\n\n%%%% Build Problem:\nproblem.H = H;\nproblem.f = zeros(n,1);\nproblem.Aineq = A;\nproblem.bineq = b;\nproblem.Aeq = Aeq;\nproblem.beq = beq;\nproblem.lb = LB;\nproblem.ub = UB;\nproblem.x0 = xGuess;\nproblem.options = options;\nproblem.solver = 'quadprog';\n\n%%%% Solve!\n[x, fVal, exitFlag, output] = quadprog(problem);\n\n% Plot the solution:\ntt = linspace(t(1),t(end),100);\n[xx, dxx] = chebyshevInterpolate(x',tt,[t(1),t(end)]);\nfigure(2); clf; \nsubplot(2,1,1); hold on;\nplot(tt,xx);\nplot(t,x,'ko');\nsubplot(2,1,2); hold on;\nplot(tt,dxx);\nplot(t,D*x,'ko');\n\n\n\n\n", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/RobotArmTrajctory/MAIN.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620619801095, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.8138472805858813}} {"text": "function sphere = createSphere(varargin)\n%CREATESPHERE Create a sphere containing 4 points.\n%\n% s = createSphere(p1, p2, p3, p4);\n% return in s the sphere common to the 4 pointsp1, p2, p3 and p4.\n%\n% Ref: P. Bourke\n% http://astronomy.swin.edu.au/~pbourke/geometry/spherefrom4/\n%\n% See also \n% spheres, circles3d\n\n% ------\n% Author: David Legland \n% E-mail: david.legland@inrae.fr\n% Created: 2005-03-22\n% Copyright 2005-2022 INRA - TPV URPOI - BIA IMASTE\n\nif length(varargin)==4\n pts = [varargin{1};varargin{2};varargin{3};varargin{4}];\nelseif length(varargin)==1\n pts = varargin{1};\nelse\n error('wrong number of arguments in createSphere');\nend\n\n\nm1 = det([pts ones(4,1)]);\ns2 = sum(pts.*pts, 2);\nm2 = det([s2 pts(:,2) pts(:,3) ones(4,1)]);\nm3 = det([pts(:,1) s2 pts(:,3) ones(4,1)]);\nm4 = det([pts(:,1) pts(:,2) s2 ones(4,1)]);\n\nm5 = det([s2 pts]);\n\nx0 = m2*.5/m1;\ny0 = m3*.5/m1;\nz0 = m4*.5/m1;\nr = sqrt(x0*x0 + y0*y0 + z0*z0 - m5/m1);\n\nsphere = [x0 y0 z0 r];\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/createSphere.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067179697694, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.8137523926390232}} {"text": "function c=dctiii(f,L,dim)\n%DCTIII Discrete Consine Transform type III\n% Usage: c=dctiii(f);\n% c=dctiii(f,L);\n% c=dctiii(f,[],dim);\n% c=dctiii(f,L,dim);\n%\n% `dctiii(f)` computes the discrete cosine transform of type III of the\n% input signal *f*. If *f* is multi-dimensional, the transformation is\n% applied along the first non-singleton dimension.\n%\n% `dctiii(f,L)` zero-pads or truncates *f* to length *L* before doing the\n% transformation.\n%\n% `dctiii(f,[],dim)` or `dctiii(f,L,dim)` applies the transformation along\n% dimension *dim*.\n%\n% The transform is real (output is real if input is real) and orthonormal.\n%\n% This is the inverse of |dctii|.\n%\n% Let f be a signal of length *L*, let `c=dctiii(f)` and define the vector\n% *w* of length *L* by \n%\n% .. w = [1/sqrt(2) 1 1 1 1 ...]\n%\n% .. math:: w\\left(n\\right)=\\begin{cases}\\frac{1}{\\sqrt{2}} & \\text{if }n=0\\\\1 & \\text{otherwise}\\end{cases}\n%\n% Then \n%\n% .. L-1\n% c(n+1) = sqrt(2/L) * sum w(m+1)*f(m+1)*cos(pi*(n+.5)*m/L) \n% m=0 \n%\n% .. math:: c\\left(n+1\\right)=\\sqrt{\\frac{2}{L}}\\sum_{m=0}^{L-1}w\\left(m\\right)f\\left(m+1\\right)\\cos\\left(\\frac{\\pi}{L}\\left(n+\\frac{1}{2}\\right)m\\right)\n%\n% Examples:\n% ---------\n%\n% The following figures show the first 4 basis functions of the DCTIII of\n% length 20:::\n%\n% % The dctii is the adjoint of dctiii.\n% F=dctii(eye(20));\n%\n% for ii=1:4\n% subplot(4,1,ii);\n% stem(F(:,ii));\n% end;\n%\n% See also: dctii, dctiv, dstii\n%\n% References: rayi90 wi94\n\n% AUTHOR: Peter L. Søndergaard\n% TESTING: TEST_PUREFREQ\n% REFERENCE: REF_DCTIII\n\ncomplainif_argnonotinrange(nargin,1,3,mfilename);\n\nif nargin<3\n dim=[];\nend;\n\nif nargin<2\n L=[];\nend;\n\n[f,L,Ls,W,dim,permutedsize,order]=assert_sigreshape_pre(f,L,dim,'DCTIII');\n\nif ~isempty(L)\n f=postpad(f,L);\nend;\nc=comp_dct(f,3);\n% c=zeros(2*L,W,assert_classname(f));\n% \n% m1=1/sqrt(2)*exp(-(0:L-1)*pi*i/(2*L)).';\n% m1(1)=1;\n% \n% m2=1/sqrt(2)*exp((L-1:-1:1)*pi*i/(2*L)).';\n% \n% for w=1:W\n% c(:,w)=[m1.*f(:,w);0;m2.*f(L:-1:2,w)];\n% end;\n% \n% c=fft(c)/sqrt(L);\n% \n% c=c(1:L,:);\n% \n% if isreal(f)\n% c=real(c);\n% end;\n\nc=assert_sigreshape_post(c,dim,permutedsize,order);\n\n% This is a slow, but convenient way of expressing the above algorithm.\n%R=1/sqrt(2)*[diag(exp(-(0:L-1)*pi*i/(2*L)));...\n%\t zeros(1,L); ...\n%\t [zeros(L-1,1),flipud(diag(exp((1:L-1)*pi*i/(2*L))))]];\n\n%R(1,1)=1;\n\n%c=fft(R*f)/sqrt(L);\n\n%c=c(1:L,:);\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/fourier/dctiii.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632856092014, "lm_q2_score": 0.8774767890838836, "lm_q1q2_score": 0.8137397581706426}} {"text": "% Linear Diophantine Equation\n%Given three integers a, b, c representing a linear equation of the form : ax + by = c. \n%To find if the equation has a solution such that x and y are both integral values.\n%Used in programming to find the exact solution exists or not.\n\nfunction retval = linear_diophantine_eqn (a,b,c)\n if mod(c,gcd(a,b))==0\n retval=true; % 1 represent yes it exist\n else\n retval= false; % 0 represent no it doesn't exist\n\nend\n", "meta": {"author": "TheAlgorithms", "repo": "MATLAB-Octave", "sha": "e150b77ad256de46c1ce3815c3d7945ac4fc28dc", "save_path": "github-repos/MATLAB/TheAlgorithms-MATLAB-Octave", "path": "github-repos/MATLAB/TheAlgorithms-MATLAB-Octave/MATLAB-Octave-e150b77ad256de46c1ce3815c3d7945ac4fc28dc/algorithms/maths/linear_diophantine_eqn.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9664104962847373, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.8135491453806489}} {"text": "clear all, close all, clc\n\nxlim([-2 2])\nylim([-2 2])\nzlim([-2 2])\n% view([-72 18])\nview([45 26]) \n% axis off\n\nset(gca,'FontSize',13);\nset(gcf,'Position',[100 100 300 300])\nset(gcf,'PaperPositionMode','auto')\nprint('-depsc2', '-loose', 'CH01_EX09_1_axis.eps')\n\n%% Define rotation matrix\nt1 = pi/15;\nt2 = -pi/9;\nt3 = -pi/20;\n\nRx = [1 0 0;\n 0 cos(t1) -sin(t1);\n 0 sin(t1) cos(t1)];\n\nRy = [cos(t2) 0 sin(t2);\n 0 1 0;\n -sin(t2) 0 cos(t2)];\n\nRz = [cos(t3) -sin(t3) 0;\n sin(t3) cos(t3) 0;\n 0 0 1];\n\nSigma = diag([3; 1; 0.5]);\n\nR = Rz*Ry*Rx*Sigma;\n\n%% Plot sphere and great circles\n[x,y,z] = sphere(250);\n% subplot(1,2,1)\nplot3([-2 2],[0 0],[0 0],'k','LineWidth',6);\nhold on\nplot3([0 0],[-2 2],[0 0],'k','LineWidth',6);\nplot3([0 0],[0 0],[-2 2],'k','LineWidth',6);\n\nh1=surf(x,y,z);\nhold on\nset(h1,'EdgeColor','none','FaceColor',[.5 .5 .5],'FaceAlpha',.75)\n% set(h1,'FaceColor','none')\nlighting phong\nshading interp\naxis equal\n\ntheta = (0:.001:1)*2*pi;\nx1 = cos(theta);\ny1 = sin(theta);\nz1 = 0*theta;\nx2 = 0*theta;\ny2 = cos(theta);\nz2 = sin(theta);\nx3 = cos(theta);\ny3 = 0*theta;\nz3 = sin(theta);\n\nplot3(x1,y1,z1,'k','LineWidth',6);\nplot3(x2,y2,z2,'k','LineWidth',6);\nplot3(x3,y3,z3,'k','LineWidth',6);\n\nxlim([-2 2])\nylim([-2 2])\nzlim([-2 2])\n% view([-72 18])\nview([45 26]) \n% axis off\n\nset(gca,'FontSize',13);\nset(gcf,'Position',[100 100 100 100])\nset(gcf,'PaperPositionMode','auto')\nset(gcf,'renderer','opengl')\n\naxis off\n% save2pdf('CH01_EX09_1b.pdf',gcf,600)\n% print('-depsc2', '-loose', 'CH01_EX09_1b.eps')\nprint('-dpng','-r1800' ,'-loose', 'CH01_EX09_1a.png')\n\n%%\nxR = 0*x;\nyR = 0*y;\nzR = 0*z;\n\nfor i=1:size(x,1)\n for j=1:size(x,2)\n vec = [x(i,j); y(i,j); z(i,j)];\n vecR = R*vec;\n xR(i,j) = vecR(1);\n yR(i,j) = vecR(2);\n zR(i,j) = vecR(3); \n end\nend\n\nvec1 = [x1; y1; z1];\nvec2 = [x2; y2; z2];\nvec3 = [x3; y3; z3];\n\nvec1R = R*vec1;\nvec2R = R*vec2;\nvec3R = R*vec3;\n\neX = [2; 0; 0];\neY = [0; 2; 0];\neZ = [0; 0; 2];\neXR = R*eX;\neYR = R*eY;\neZR = R*eZ;\n\nx1R = vec1R(1,:);\ny1R = vec1R(2,:);\nz1R = vec1R(3,:);\nx2R = vec2R(1,:);\ny2R = vec2R(2,:);\nz2R = vec2R(3,:);\nx3R = vec3R(1,:);\ny3R = vec3R(2,:);\nz3R = vec3R(3,:);\n\nfigure\n% plot3([0 -2],[0 0],[0 0],'Color',[.3 .3 .3],'LineWidth',6);\n% hold on\n% plot3([0 0],[0 -2],[0 0],'Color',[.3 .3 .3],'LineWidth',6);\n% plot3([0 0],[0 0],[0 2],'Color',[.3 .3 .3],'LineWidth',6);\nh1=surf(xR,yR,zR,z);\nhold on\nset(h1,'EdgeColor','none','FaceColor',[.5 .5 .5],'FaceAlpha',.75)\n% set(h1,'FaceColor','none')\naxis equal\nshading interp\nlighting phong\n\nplot3(x1R,y1R,z1R,'k','LineWidth',6);\nplot3(x2R,y2R,z2R,'k','LineWidth',6);\nplot3(x3R,y3R,z3R,'k','LineWidth',6);\n\nplot3([-eXR(1) eXR(1)],[-eXR(2) eXR(2)],[-eXR(3) eXR(3)],'k','LineWidth',6);\nplot3([-eYR(1) eYR(1)],[-eYR(2) eYR(2)],[-eYR(3) eYR(3)],'k','LineWidth',6);\nplot3([-eZR(1) eZR(1)],[-eZR(2) eZR(2)],[-eZR(3) eZR(3)],'k','LineWidth',6);\n\nxlim([-2 2])\nylim([-2 2])\nzlim([-2 2])\ngrid off\n\n% view([-72 18])\nview([45 26]) \n% axis off\n\nset(gca,'FontSize',13);\nset(gcf,'Position',[100 100 100 100])\nset(gcf,'PaperPositionMode','auto')\nset(gcf,'renderer','opengl')\n\naxis off\n% save2pdf('CH01_EX09_1b.pdf',gcf,600)\n% print('-depsc2', '-loose', 'CH01_EX09_1b.eps')\nprint('-dpng','-r1800' ,'-loose', 'CH01_EX09_1b.png')", "meta": {"author": "dynamicslab", "repo": "databook_matlab", "sha": "d390d39d18489a4804ee87a143ae8db8a1f3010b", "save_path": "github-repos/MATLAB/dynamicslab-databook_matlab", "path": "github-repos/MATLAB/dynamicslab-databook_matlab/databook_matlab-d390d39d18489a4804ee87a143ae8db8a1f3010b/CH01/CH01_SEC03_Rotation_production.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.8824278788223265, "lm_q1q2_score": 0.8135295272781177}} {"text": "function [ x, w ] = moment_method ( n, moment )\n\n%*****************************************************************************80\n%\n%% MOMENT_METHOD computes a quadrature rule by the method of moments.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 October 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Gene Golub, John Welsch,\n% Calculation of Gaussian Quadrature Rules,\n% Mathematics of Computation,\n% Volume 23, Number 106, April 1969, pages 221-230.\n%\n% Parameters:\n%\n% Input, integer N, the order of the quadrature rule.\n%\n% Input, real MOMENT(2*N+1), moments 0 through 2*N.\n%\n% Output, real X(N,1), W(N,1), the points and weights of the quadrature rule.\n%\n debug = 0;\n\n if ( debug )\n r8vec_print ( 2 * n + 1, moment, ' Moments:' );\n end\n%\n% Define the N+1 by N+1 Hankel matrix H(I,J) = moment(I+J).\n%\n h = zeros ( n + 1, n + 1 );\n for i = 1 : n + 1\n for j = 1 : n + 1\n h(i,j) = moment(i+j-1);\n end\n end\n\n if ( debug )\n r8mat_print ( n + 1, n + 1, h, ' Hankel matrix:' )\n end\n%\n% Compute R, the upper triangular Cholesky factor of H.\n%\n r = chol ( h );\n\n if ( debug )\n r8mat_print ( n + 1, n + 1, r, ' Cholesky factor:' )\n end\n%\n% Compute ALPHA and BETA from R, using Golub and Welsch's formula.\n%\n alpha = zeros ( n, 1 );\n alpha(1) = r(1,2) / r(1,1);\n for i = 2 : n\n alpha(i) = r(i,i+1) / r(i,i) - r(i-1,i) / r(i-1,i-1);\n end\n\n beta = zeros ( n - 1, 1 );\n for i = 1 : n - 1\n beta(i) = r(i+1,i+1) / r(i,i);\n end\n%\n% Compute the points and weights from the moments.\n%\n jacobi = diag ( alpha, 0 ) + diag ( beta, -1 ) + diag ( beta, +1 );\n\n if ( debug )\n r8mat_print ( n, n, jacobi, ' Jacobi matrix: ' );\n end\n%\n% Get the eigendecomposition of the Jacobi matrix.\n%\n [ evec, eval ] = eig ( jacobi );\n\n x = diag ( eval );\n w = moment(1) * evec(1,:).^2;\n%\n% Destroy all row vectors.\n%\n x = x(:);\n w = w(:);\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/quadmom/moment_method.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.8824278741843884, "lm_q1q2_score": 0.8135295248953117}} {"text": "function M=Euler1Ang2RotMat(theta,series,handed)\n%%EULER1ANG2ROTMAT Obtain the Euler-angle rotation matrix for a rotation\n% of angle theta about single axis (x, y, or z). The rotation is\n% either right-handed (counterclockwise, the default) or\n% left-handed depending on handed. The components of vectors to\n% be rotated are assumed ordered [x;y;z].\n%\n%INPUTS: theta The angle in radians about which the rotation matrix should\n% rotate a vector around the axis given by series. The\n% handedness of the angle is given by handed.\n% series A text string specifying the angle about which the rotation\n% is performed. This can be 'x', 'y', or 'z'.\n% handed The handedness of the rotation angle. If omitted, it is\n% assumed that the rotation is right-handed (the standard).\n% Possible values are:\n% 'right' The default if omitted. The rotation is right-\n% handed.\n% 'left' The rotation is left-handed. The rotation angle is\n% clockwise when one is looking into the rotation\n% axis.\n%\n%OUTPUTS: M The rotation matrix such that M*v rotates a vector v by theta\n% about the specified axis.\n%\n%Euler angles are discussed in [1].\n%\n%REFERENCES:\n%[1] M. D. Shuster, \"A survey of attitude representations,\" The Journal of\n% Astronautical Sciences, vol. 41, no. 4, pp. 439-517, Oct. - Dec. 1993.\n%\n%September 2014 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\nswitch(handed)\n case 'right'\n case 'left'\n theta=-theta;\n otherwise\n error('Invalid handedness provided.')\nend\n\ncosT=cos(theta);\nsinT=sin(theta);\n\nswitch(series)\n case 'x'\n M=[1, 0, 0;\n 0, cosT, -sinT;\n 0, sinT, cosT];\n case 'y'\n M=[cosT, 0, sinT;\n 0, 1, 0;\n -sinT, 0, cosT];\n case 'z'\n M=[cosT, -sinT, 0;\n sinT, cosT, 0;\n 0, 0, 1];\n otherwise\n error('Invalid rotation axis specified')\nend\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/Euler1Ang2RotMat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.8824278726384089, "lm_q1q2_score": 0.8135295234700395}} {"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 y_pred = X * theta; % X.shape=(m,3) theta.shape=(3,1)\n theta = theta - alpha * 1/m * (X'*(y_pred-y)); % y.shape=(m,1);\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": "imLogM", "repo": "Machine_Learning_AndrewNg", "sha": "1d499e8e2738032dc85e869ba55c32eb24da288d", "save_path": "github-repos/MATLAB/imLogM-Machine_Learning_AndrewNg", "path": "github-repos/MATLAB/imLogM-Machine_Learning_AndrewNg/Machine_Learning_AndrewNg-1d499e8e2738032dc85e869ba55c32eb24da288d/machine-learning-ex1/ex1/gradientDescentMulti.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850057480346, "lm_q2_score": 0.8688267779364222, "lm_q1q2_score": 0.8134694847742494}} {"text": "function nksub = ksubset_enum ( k, n )\n\n%*****************************************************************************80\n%\n%% KSUBSET_ENUM enumerates the K element subsets of an N set.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 24 January 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer K, the number of elements each K subset must\n% have. 0 <= K <= N.\n%\n% Input, integer N, the number of elements in the master set.\n% 0 <= N.\n%\n% Output, integer NKSUB, the number of distinct elements.\n%\n nksub = i4_choose ( n, k );\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/combo/ksubset_enum.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9019206870747657, "lm_q2_score": 0.9019206758704633, "lm_q1q2_score": 0.8134609156680254}} {"text": "%ROT2 SO(2) Rotation matrix\n%\n% R = ROT2(THETA) is an SO(2) rotation matrix (2x2) representing a rotation of THETA \n% radians.\n%\n% R = ROT2(THETA, 'deg') as above but THETA is in degrees.\n%\n% See also SE2, TROT2, ISROT2, TRPLOT2, ROTX, ROTY, ROTZ, SO2.\n\n\n% Copyright (C) 1993-2017, 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\nfunction R = rot2(t, deg)\n\n if nargin > 1 && strcmp(deg, 'deg')\n t = t *pi/180;\n end\n \n ct = cos(t);\n st = sin(t);\n R = [\n ct -st\n st ct\n ];\n", "meta": {"author": "star2dust", "repo": "paper-simulation", "sha": "2d35e3beeccd2ce41f60c59e347b090f25960706", "save_path": "github-repos/MATLAB/star2dust-paper-simulation", "path": "github-repos/MATLAB/star2dust-paper-simulation/paper-simulation-2d35e3beeccd2ce41f60c59e347b090f25960706/Ibuki2020Optimization/rot2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.8723473862936943, "lm_q1q2_score": 0.8134232117376318}} {"text": "% Calculate the number of independent cycles (use L = m-n+c)\n% where L = num cycles, m - num edges, n - num nodes, \n% c - number of connected components\n% This is also known as the \"cyclomatic number\": the number of edges\n% that needs to be removed so that the graph doesn't have cycles.\n%\n% INPUTS: adjacency matrix, nxn\n% OUTPUTs: number of independent cycles (or cyclomatic number)\n%\n% Other routines used: numNodes.m, numEdges.m, findConnComp.m\n% GB: last updated, Oct 5 2012\n\nfunction L = numCycles(adj)\n\nn=numNodes(adj);\nm=numEdges(adj);\ncomp_mat = findConnComp(adj);\n\nL=m-n+length(comp_mat);", "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/numCycles.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338101862455, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.813402258678047}} {"text": "function f = flops_lu(n)\n% FLOPS_LU Flops for LU decomposition.\n% FLOPS_LU(n) returns the number of flops to compute lu(rand(n,n)).\n% The matrix is assumed to be symmetric positive definite, so that no pivoting is required.\n\n% Number of flops for the algorithm in Cormen et al:\n% Number of multiplies+adds is:\n% sum(k=1:n) sum(i=k+1:n) sum(j=k+1:n) 3\n% = sum(k=1:n) 3(n-k)^2\n% = sum(k=0:(n-1)) 3 k^2 \n% = n(n-0.5)(n-1)\n% Number of divides is: n-1\nf = n*(n-0.5)*(n-1) + (n-1)*flops_div;\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/flops_lu.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9615338090839606, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.8134022502764736}} {"text": "% Copyright 2009 - 2010 The MathWorks, Inc.\n% Loading the test data\n% Note that we are tracking an object whose positions are recorded \n% as x and y coordinates in a Cartesian space\nload position.mat\nhold; grid;\nfor idx = 1: numPts\nz = position(:,idx);\nplot(z(1), z(2), 'bx');\naxis([-1 1 -1 1]);\nend\nhold;\n%% This algorithm predicts the position of a moving object based on \n% its past values. It uses a Kalman filter estimator. \n% Kalman filter is a recursive adaptive filter that estimates \n% the state of a dynamic system from a series of \n% noisy measurements. It has a broad range of application in \n% signal and imge processing, control design, \n% and computational finance\n% Let's run the script ObjTrack.m to see how Kalman filter \n% gradually estimates and tracks a moving object. \nObjTrack01(position)\n%% In this example, by assuming a zero initial condition \n% ( no knowledge of the position of the object in the past) \n% Kalman filter iteratively and adaptively estimates and tracks \n% the object. This is depicted by the green circular traces \n% as outputs of the Kalman estimator superimposed \n% on the input positions vectors depicted by blue x traces.\n% Note that there are 3 sudden shifts in position and every time\n% Kalman filter re-adjusts and tracks the object after few iterations\nedit ObjTrack01\n%% Let's look at the Kalman filter function\n% Note that the Kalman estimator computes the position vector \n% by computing and updating the Kalman state vector. \n% We define the state vector as a 6-by-1 column vector \n% that includes position (x and y) velocity (Vx Vy) and \n% acceleration (Ax and Ay) measurements in a 2-dimensional \n% Cartesian space. Based on the classical laws of motion:\n% X = X0 + Vx*t \n% Y = Y0 + Vy*t \n% Vx = Vx0 + Ax*t\n% Vy = Yy0 + Ay*t \n% Note how these laws of motion are reflected in the Kalman \n% state transion matrix A:\n% x=[X Y Vx Vy Ax Ay]' %% state vector\n% x=A*x; %% recursive estimation\n% dt=1;\n% A=[ 1 0 dt 0 0 0;... %% state transion matrix\n% 0 1 0 dt 0 0;...\n% 0 0 1 0 dt 0;...\n% 0 0 0 1 0 dt;...\n% 0 0 0 0 1 0 ;...\n% 0 0 0 0 0 1 ];\n% Note how by writing only 10 lines of MATLAB code, \n% we implement the Kalman estimator as if you are writing\n% the mathematical formula. This is power of MATLAB!\n%% Version 1 Scalar Kalman filter \n% input: one sample \n% output: one sample\nedit kalman01.m\n%% Let us now genearte C code for the kalman filter\n% First we run the emlmex command to see weather there is any \n% function or operator in this function that is not compliant with the \n% Embedded MATLAB subset\nz = position(:,1);\nemlmex -eg {z} kalman01.m\n%% Now that the kalman filter is compliant, Is the \n% calling function (ObjTrack01) compliant with Embedded MATLAB subset?\nemlmex -eg {position} ObjTrack01.m\n%% No,it contains unsupported visualization function\n% How do we make it complaint with the embedded MATLAB subset?\n% Notice eror messages when complaining due to the use of plotting\n% functions. We now showcase use of eml.extrinsic that declare\n% visualization functions to be extrinsic and instruct Embedded MATLAB \n% not to compile them.\nedit ObjTrack02.m\n%% Notice how the non-supported plotting functions now \n% do not take part in compilation and thus no more eror messages\nemlmex -eg {position} ObjTrack02.m\n%% Since this function kalman.m is consistent with \n% Embedded MATLAB subset, let us now use the emlc command to\n% automatically genearte C source code for this functioon\nemlc -eg {z} kalman01.m -c -T RTW -report\n%% Here we note and explain the following features:\n% 1. MATLAB is an untyped language, C is strictly typed. \n% So we use -eg option to set the (data type, size and complexity) of the\n% input variable to the function based on an example variable \n% availbale in MATLAB workspace (in this case varaiable name is z). \n% Based on the properties of this variable, \n% Embeded MATLAB sets and infers the data type, size and complexity of \n% all internal variables to the function, declares them and generate C code.\n% 2. -c option indicates we just want to see the C source code\n% 3. -T RTW option says generate embeddable C-code and \n% 4. -report option says generate a compilation report.\n% Now browse and explain the organization of Compilation report\n%% Now we want to showcase how in many cases we can \n% accelerate the execution speed of a function running a large data set\n% by using emlmex command that compiled the function into a MEX function. \n% Use of emlmex not only verifies the compliance with the Embedded MATLAB\n% subset but it may potentialy accelrate the execution speed of some algorithms\n% specially if the algorithm is fixed-point\n%% First run the kalman algorithm with 100,000 samples without \n% using emlmex to compile it to a mex function\ndelete *.mexw32\nwhich kalman01\n%% Use tic; toc; to record how much time it takes for processing \n% 100K samples of data in this case \nSIZE=100000;\nZ=rand(2,SIZE);\ntic;\nfor i=1:SIZE\n z=Z(:,i);\n y=kalman01(z);\nend;\ntoc;\n%% Second run the kalman algorithm with 100,000 samples WITH \n% using emlmex to compile it to a mex function\nemlmex -eg {z} kalman01.m\nwhich kalman01\n%% Use tic; toc; to record how much time it takes for processing 100K\n% samples\nSIZE=100000;\nZ=rand(2,SIZE);\ntic;\nfor i=1:SIZE\n z=Z(:,i);\n y=kalman01(z);\nend;\ntoc;\n%% Notice a 3 times acceleration of the speed of the execution of this\n% function just by using the emlmex function \n%% Version 3 Variable size Vector (Packet based)\n% Kalman filter \n% input: a variable-sized vector \n% output: sanme size as inoput\nedit ObjTrack03.m\n%% Variable-size data\n% Let us now genearte C code for the packet-based \n% kalman filter. First we run the emlmex command to see weather there is any \n% function or operator in this function that is not compliant with the\n% Embedded MATLAB subset\nN=100;\nz = position(1:2,1:N);\neg_z=emlcoder.egs(z,[2 N]);\nemlmex -eg {eg_z} kalman03.m\n%% Let us run the compiled version to make sure\n% the generated C code can properly handle packets of diferent sizes.\n% By examining ObjTrack03.m we see that we are calling kalman03.m with\n% 7 different (x-y) pairs of varying sizes ranging from 2x10 to 2x100 \nwhich kalman03\nObjTrack03\n%% Since this function kalman.m is consistent with \n% Embedded MATLAB subset, let us now use the emlc command to\n% automatically genearte C source code for this function\n% We use the maximum size of 2x100 as the upper bound for compilation to C\n% and use the emlcoder.egs to indicate the maximum size of the input\n% variable z.\nN=100;\nz = position(1:2,1:N);\neg_z=emlcoder.egs(z,[2 N]);\nemlc -eg {eg_z} kalman03.m -c -T RTW -report\n%% Here we note and explain the following features:\n% 1. The genearted C code has just enough extra code to make it flexible\n% for any size input from 2x1 to 2x100.\n% 2. We showcase emlcoder.egs and explain how it works\n% 3. We explain how easy it is to make an algorithm be flexible relative to\n% input size:\n% We show that in the function at line 36, we had o explicitly index \n% the input variable z (instead of z(:,i) -> z(1:2,i) to make explicit\n% which portion of variable size input us being processed at that line\n%% Fixed-point data: Look at the fixed-point Kalman estimator function\n% It differs from the floating-point algorithm kalman.m \n% by declaring the internal variables as fixed-point \n% using the fi constructor. The variable declaration (where most changes are) are separated \n% from the algorithm part, which remains mostly the same relative to the\n% floating point algorithm.\nedit kalman04.m\n%% To convert algorithm to fixed-point, you need to set numeric type\n% of the fixed-point input data and specify a set of global fimath\n% properties. \n% As of R2009b, you can specify accumulator ad product data types\n% of all intermediate variables globally, which makes the task \n% of fixed-point programming easier.\n%% Look at the syntax of setting the global fimath properties\n% Before setting the global fimath we have the default values \nresetglobalfimath\nfimath\n%% Now note that I am using a helper functin myglobalfimath.m \n% to globaly set the fixed-point math properties of all variables in MATLAB workspace.\nedit myglobalfimath.m\n%% \n% I want to set a global fimath properties such that SpecifyPrecision Mode is used \n% for setting the Sum and Product properties, accumulators and products \n% internal variables have a wordlength of 32 bits, with 20 bits for their fractional part,\n% 11 bits integer part and 1 bit for sign\nmyglobalfimath(20);\nfimath\n%% Notice how it can take a long time to run fixed-point function \n% without using emlmex to accelerate execution speed\n% In my machine about 7 seconds for 1000 samples\ndelete *.mexw32\nwhich kalman04\nSIZE=1000;\nZ=fi(rand(2,SIZE));\ntic;\nfor i=1:SIZE\n z=Z(:,i);\n y=kalman04(z);\nend;\ntoc;\n%% Now you can accelerate the execution speed of fixed-point \n% and in most cases even floating-point functionsby using the\n% emlmex function of Fixed-Point Toolbox. It generates C code automatically\n% from the MATLAB function and compiles it into MEX code. \n% It will run faster. Only catch is that the kalman_fixpt.m \n% must use the subset of MATLAB language allowing automatic \n% MATLAB to C translation. The Embedded MATLAB subset \nz = Z(:,1);\nemlmex -eg {z} kalman04.m\n%% Run the same function and notice the acceleration\n% In my machine it run around 0.3 seconds a 20x acceleration\nmyglobalfimath(20);\nwhich kalman04\nSIZE=1000;\nZ=fi(rand(2,SIZE));\ntic;\nfor i=1:SIZE\n z=Z(:,i);\n y=kalman04(z);\nend;\ntoc;\n%% Now generate C source code from your fixed-point Kalman filter \n% by uising the emlc command of the Real Time Workshop\n% When you use the -report option it creates a link to an HTML report\n% showing the automatically generated C code as kalman_fixpt.c\n% Note that all variables are statically defined as native integers and \n% all scaling functions are defined before the main C function \nemlc -eg {z} kalman04.m -c -T RTW -report\n%% Clean up\ndelete *.mexw32\nclear mex\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/26862-kalman-filtering-demo-in-matlab-with-automatic-matlab-to-c-code-generation/EML_Masterclass.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240125464114, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.8133870756763267}} {"text": "function [b b0] = circ_skewness(alpha, w, dim)\n\n% [b b0] = circ_skewness(alpha,w,dim)\n% Calculates a measure of angular skewness.\n%\n% Input:\n% alpha sample of angles\n% [w weightings in case of binned angle data]\n% [dim statistic computed along this dimension, 1]\n%\n% If dim argument is specified, all other optional arguments can be\n% left empty: circ_skewness(alpha, [], dim)\n%\n% Output:\n% b skewness (from Pewsey)\n% b0 alternative skewness measure (from Fisher)\n%\n% References:\n% Pewsey, Metrika, 2004\n% Statistical analysis of circular data, Fisher, p. 34\n%\n% Circular Statistics Toolbox for Matlab\n\n% By Philipp Berens, 2009\n% berens@tuebingen.mpg.de\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\n% compute neccessary values\nR = circ_r(alpha,w,[],dim);\ntheta = circ_mean(alpha,w,dim);\n[~, rho2 mu2] = circ_moment(alpha,w,2,true,dim);\n\n% compute skewness \ntheta2 = repmat(theta, size(alpha)./size(theta));\nb = sum(w.*(sin(2*(circ_dist(alpha,theta2)))),dim)./sum(w,dim);\nb0 = rho2.*sin(circ_dist(mu2,2*theta))./(1-R).^(3/2); % (formula 2.29)\n\n\n", "meta": {"author": "buzsakilab", "repo": "buzcode", "sha": "2d700a38b3c2a860ad1333be90f14d7a37a72815", "save_path": "github-repos/MATLAB/buzsakilab-buzcode", "path": "github-repos/MATLAB/buzsakilab-buzcode/buzcode-2d700a38b3c2a860ad1333be90f14d7a37a72815/externalPackages/CircularStats/circ_skewness.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240073565738, "lm_q2_score": 0.8670357666736772, "lm_q1q2_score": 0.8133870679533893}} {"text": "function q=axisAng2Quat(u,theta)\n%%AXISANG2QUAT Get a unit quaternion representative of a rotation of a 3D\n% vector an angle of theta counterlockwise (right-handed) or\n% clockwise (left-handed) about an axis given by u. The\n% handedness of theta matches the handedness of the\n% quaternion produced.\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 about\n% the axis u when multiplied by the rotation matrix. The\n% handedness of the rotation angle matches the handedness of the\n% quaternion produced.\n%\n%OUTPUTS: q A 4X1 unit quaternion corresponding to the supplied axis and\n% angle. The handedness of the quaternion (which is important to\n% know when using the quaternion with other functions, such as\n% quatMult) is the same as that of the angle. The quaternion is\n% ordered in terms of hypercomplex numbers as\n% q(1)+i*q(2)+j*q(3)+k*q(4).\n%\n%Quaternions and rotations are discussed in [1].\n%\n%REFERENCES:\n%[1] M. D. Shuster, \"A survey of attitude representations,\" The Journal of\n% Astronautical Sciences, vol. 41, no. 4, pp. 439-517, Oct. -Dec. 1993.\n% wherein the convention for the quaternions is left-handed.\n%\n%August 2014 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nq=[cos(theta/2);sin(theta/2)*u];\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/axisAng2Quat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9381240160063031, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.8133870625603633}} {"text": "function dX = dynamics(X,P)\n% dX = dynamics(X,P)\n%\n% This function computes the first-order dynamics for the classical\n% \"three-body\" problem in newtonian mechanics: three point masses with\n% inverse-square gravity.\n%\n% The input state contains only information about the first two particles.\n% The state of the third particle is computed from the assumption (without\n% loss of generality) that the center of mass of the system is at the\n% origin and not moving.\n%\n% INPUTS:\n% X = [12, N] = first order state vector\n% X(1:3,:) = X1 = [x1;y1;z1]\n% X(4:6,:) = X2 = [x2;y2;z2]\n% X(7:9,:) = V1 = [dx1;dy1;dz1]\n% X(10:12,:) = V2 = [dx2;dy2;dz2]\n% P = parameter struct:\n% .G = gravity constant\n% .m1 = mass one\n% .m2 = mass two\n% .m3 = mass three\n%\n% OUTPUTS:\n% dX = [V1;V2; dV1; dV2];\n%\n%\n\n% Positions\nX1 = X(1:3,:);\nX2 = X(4:6,:);\n\n% Velocity\nV1 = X(7:9,:);\nV2 = X(10:12,:);\n\n% Compute X3 from definition that CoM is at the origin\n% x = (x1*m1 + x2*m2 + x3*m3)/(m1 + m2 + m3);\nX3 = -(X1*P.m1 + X2*P.m2)/P.m3;\n% V3 = -(V1*P.m1 + V2*P.m2)/P.m3; %Unused, but good to know\n\n% Force Vectors\nF12 = getForce(X1, X2, P.m1, P.m2, P.G); % Acting on 1 from 2\nF23 = getForce(X2, X3, P.m2, P.m3, P.G); % Acting on 2 from 3\nF13 = getForce(X1, X3, P.m1, P.m3, P.G); % Acting on 1 from 3\n \n% Acceleration Vectors\nA1 = (F12 + F13)/P.m1;\nA2 = (-F12 + F23)/P.m2;\n% A3 = (-F23 - F13)/P.m3; %Unused, but good to know\n\n% Pack up solution:\ndX = [V1; V2; A1; A2];\n\nend\n\n\nfunction F = getForce(Xa, Xb, ma, mb, G)\n%\n% Computes the force acting on particle a due to particle b, given\n% parameters in the struct P\n%\n\nr = Xa - Xb; %Vector from b to a\nr2 = ones(3,1)*sum(r.^2,1); % Length squared\n\nlFl = G*ma*mb./r2; %Force magnitude\n\nF = -lFl .* (r./sqrt(r2)); %Force vector\n\nend\n\n", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/ThreeMassPeriodicOrbits/bvp4c/dynamics.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9637799441350253, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.8133291766877595}} {"text": "% Minimize thermal noise power of an array with arbitrary 2-D geometry\n% \"Convex optimization examples\" lecture notes (EE364) by S. Boyd\n% \"Antenna array pattern synthesis via convex optimization\"\n% by H. Lebret and S. Boyd\n% (figures are generated)\n%\n% Designs an antenna array such that:\n% - it has unit a sensitivity at some target direction\n% - obeys constraint for minimum sidelobe level outside the beamwidth\n% - minimizes thermal noise power in y (sigma*||w||_2^2)\n%\n% This is a convex problem described as:\n%\n% minimize norm(w)\n% s.t. y(theta_tar) = 1\n% |y(theta)| <= min_sidelobe for theta outside the beam\n%\n% where y is the antenna array gain pattern (complex function) and\n% variables are w (antenna array weights or shading coefficients).\n% Gain pattern is a linear function of w: y(theta) = w'*a(theta)\n% for some a(theta) describing antenna array configuration and specs.\n%\n% Written for CVX by Almir Mutapcic 02/02/06\n\n% select array geometry\nARRAY_GEOMETRY = '2D_RANDOM';\n% ARRAY_GEOMETRY = '1D_UNIFORM_LINE';\n% ARRAY_GEOMETRY = '2D_UNIFORM_LATTICE';\n\n%********************************************************************\n% problem specs\n%********************************************************************\nlambda = 1; % wavelength\ntheta_tar = 60; % target direction\nhalf_beamwidth = 10; % half beamwidth around the target direction\nmin_sidelobe = -20; % maximum sidelobe level in dB\n\n%********************************************************************\n% random array of n antenna elements\n%********************************************************************\nif strcmp( ARRAY_GEOMETRY, '2D_RANDOM' )\n % set random seed to repeat experiments\n rand('state',0);\n\n % (uniformly distributed on [0,L]-by-[0,L] square)\n n = 36;\n L = 5;\n loc = L*rand(n,2);\n\n%********************************************************************\n% uniform 1D array with n elements with inter-element spacing d\n%********************************************************************\nelseif strcmp( ARRAY_GEOMETRY, '1D_UNIFORM_LINE' )\n % (unifrom array on a line)\n n = 30;\n d = 0.45*lambda;\n loc = [d*[0:n-1]' zeros(n,1)];\n\n%********************************************************************\n% uniform 2D array with m-by-m element with d spacing\n%********************************************************************\nelseif strcmp( ARRAY_GEOMETRY, '2D_UNIFORM_LATTICE' )\n m = 6; n = m^2;\n d = 0.45*lambda;\n\n loc = zeros(n,2);\n for x = 0:m-1\n for y = 0:m-1\n loc(m*y+x+1,:) = [x y];\n end\n end\n loc = loc*d;\n\nelse\n error('Undefined array geometry')\nend\n\n%********************************************************************\n% construct optimization data\n%********************************************************************\n% build matrix A that relates w and y(theta), ie, y = A*w\ntheta = [1:360]';\nA = kron(cos(pi*theta/180), loc(:,1)') + kron(sin(pi*theta/180), loc(:,2)');\nA = exp(2*pi*i/lambda*A);\n\n% target constraint matrix\n[diff_closest, ind_closest] = min( abs(theta - theta_tar) );\nAtar = A(ind_closest,:);\n\n% stopband constraint matrix\nind = find(theta <= (theta_tar-half_beamwidth) | ...\n theta >= (theta_tar+half_beamwidth) );\nAs = A(ind,:);\n\n%********************************************************************\n% optimization problem\n%********************************************************************\ncvx_begin\n variable w(n) complex\n minimize( norm( w ) )\n subject to\n Atar*w == 1;\n abs(As*w) <= 10^(min_sidelobe/20);\ncvx_end\n\n% check if problem was successfully solved\ndisp(['Problem is ' cvx_status])\nif ~strfind(cvx_status,'Solved')\n return\nend\n\nfprintf(1,'The minimum norm of w is %3.2f.\\n\\n',norm(w));\n\n%********************************************************************\n% plots\n%********************************************************************\nfigure(1), clf\nplot(loc(:,1),loc(:,2),'o')\ntitle('Antenna locations')\n\n% plot array pattern\ny = A*w;\n\nfigure(2), clf\nymin = -30; ymax = 0;\nplot([1:360], 20*log10(abs(y)), ...\n [theta_tar theta_tar],[ymin ymax],'r--',...\n [theta_tar+half_beamwidth theta_tar+half_beamwidth],[ymin ymax],'g--',...\n [theta_tar-half_beamwidth theta_tar-half_beamwidth],[ymin ymax],'g--',...\n [0 theta_tar-half_beamwidth],[min_sidelobe min_sidelobe],'r--',...\n [theta_tar+half_beamwidth 360],[min_sidelobe min_sidelobe],'r--');\nxlabel('look angle'), ylabel('mag y(theta) in dB');\naxis([0 360 ymin ymax]);\n\n% polar plot\nfigure(3), clf\nzerodB = 50;\ndBY = 20*log10(abs(y)) + zerodB;\nplot(dBY.*cos(pi*theta/180), dBY.*sin(pi*theta/180), '-');\naxis([-zerodB zerodB -zerodB zerodB]), axis('off'), axis('square')\nhold on\nplot(zerodB*cos(pi*theta/180),zerodB*sin(pi*theta/180),'k:') % 0 dB\nplot( (min_sidelobe + zerodB)*cos(pi*theta/180), ...\n (min_sidelobe + zerodB)*sin(pi*theta/180),'k:') % min level\ntext(-zerodB,0,'0 dB')\ntext(-(min_sidelobe + zerodB),0,sprintf('%0.1f dB',min_sidelobe));\ntheta_1 = theta_tar+half_beamwidth;\ntheta_2 = theta_tar-half_beamwidth;\nplot([0 55*cos(theta_tar*pi/180)], [0 55*sin(theta_tar*pi/180)], 'k:')\nplot([0 55*cos(theta_1*pi/180)], [0 55*sin(theta_1*pi/180)], 'k:')\nplot([0 55*cos(theta_2*pi/180)], [0 55*sin(theta_2*pi/180)], 'k:')\nhold off\n", "meta": {"author": "cvxr", "repo": "CVX", "sha": "a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd", "save_path": "github-repos/MATLAB/cvxr-CVX", "path": "github-repos/MATLAB/cvxr-CVX/CVX-a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd/examples/antenna_array_design/ant_array_min_therm_noise.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474181553805, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.8133145445835228}} {"text": "function [ cur_group ] = kmeans_diy( input_data, k )\nn = size(input_data, 1);\nd = size(input_data, 2);\n% initialise means from random samples\nmeans = input_data(randsample(n, k), :);\n% main loop\nnewmeans = zeros(k,d);\nscores = zeros(n, k);\nchange = Inf;\nwhile change > eps\n % assign labels to data points according to distances to the means\n for j = 1:k\n diff = bsxfun(@minus, input_data, means(j,:));\n scores(:,j) = sqrt(sum(diff.^2,2));\n end\n [~,cur_group] = min(scores, [], 2);\n % recompute means based on obtained labelings\n for j = 1:k\n newmeans(j,:) = mean(input_data(cur_group == j,:));\n end\n % stopping criteria\n change = sqrt(sum(sum((newmeans-means).^2, 1), 2))/k;\n means = newmeans;\nend\nend", "meta": {"author": "eldar", "repo": "deepcut", "sha": "096e2d174ddf2fbdc61458d9e7e6c6e897eac16c", "save_path": "github-repos/MATLAB/eldar-deepcut", "path": "github-repos/MATLAB/eldar-deepcut/deepcut-096e2d174ddf2fbdc61458d9e7e6c6e897eac16c/lib/utils/kmeans_diy.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474194456936, "lm_q2_score": 0.8519527963298946, "lm_q1q2_score": 0.8133145385058765}} {"text": "function [vals,coeffs]=asinDerivVal(z,n,coeffs)\n%%ASINDERIVVAL Return the value of the nth derivative of asin(x) with\n% respect to x evaluated at x=z for real or imaginary z.\n%\n%INPUTS: z A matrix of real or complex values at which the nth derivative\n% of the arcsine function is desired. If an empty matrix is\n% passed, then just coeffs will be returned.\n% n The number of derivatives to take. n>=0.\n% coeffs The computation of the derivatives involves determining the\n% structure of a polynomial. If this function has been run before\n% for a given n value, then the polynomial can be passed back and\n% is not determined again. Otherwise, this can be omitted or an\n% empty matrix can be passed. This only makes a difference for\n% n>=12.\n%\n%OUTPUTS: vals The value of the nth derivative of the arcsine function\n% taken at all of the points in z. vals has the same\n% dimensions as z.\n% coeffs A vector of polynomial coefficients that can be passed back\n% to this function when evaluating with the same n to speed it\n% up. \n%\n%For n=0, vals=asin(z). Subsequent derivatives are computed essentially\n%using the chain rule and combining terms to get the appropriate\n%polynomial. All derivatives are of the form\n%polynomial*sqrt(1-z(:).^2).^(-k). For n<12, the coefficients are tabulated\n%to make the function faster.\n%\n%May 2018 David F.Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(n==0)\n vals=asin(z);\n coeffs=[];\n return;\nend\n\nif(nargin<3||isempty(coeffs))\n if(n<12)\n switch(n)\n case 1\n coeffs=1;\n case 2\n coeffs=[1;0];\n case 3\n coeffs=[2;0;1];\n case 4\n coeffs=[6;0;9;0];\n case 5\n coeffs=[24;0;72;0;9];\n case 6\n coeffs=[120;0;600;0;225;0];\n case 7\n coeffs=[720;0;5400;0;4050;0;225];\n case 8\n coeffs=[5040;0;52920;0;66150;0;11025;0];\n case 9\n coeffs=[40320;0;564480;0;1058400;0;352800;0;11025];\n case 10\n coeffs=[362880;0;6531840;0;17146080;0;9525600;0;893025;0];\n case 11\n coeffs=[3628800;0;81648000;0;285768000;0;238140000;0;44651250;0;893025];\n otherwise\n error('Invalid n')\n end\n k=1+2*(n-1);\n else \n %The derivative of (1-x^2)^(-(k/2)) is\n %kx(1-x^2)^(-1-k/2)\n %That is k*x*(1-x^2)^(-(k1/2)) where k1=k+2.\n xVal=[1,0];\n\n %This polynomial is 1-x^2.\n polyX=[-1,0,1];\n\n %The first derivative \n n=n-1;\n coeffs=1;\n k=1;\n while(n>0)\n %Take the derivative of the denominator.\n coeffsNum=conv(k*xVal,coeffs);\n k=k+2;\n\n %Now, differentiate the numerator and multiply to get a\n %common denominator.\n coeffs=polyder(coeffs);\n coeffs=conv(coeffs,polyX);\n coeffs=polySum(coeffs,coeffsNum);\n n=n-1;\n end\n end\nelse\n k=1+2*(n-1);\nend\n \nif(~isempty(z))\n vals=zeros(size(z));\n %Evaluate the result.\n vals(:)=polyval(coeffs,z(:)).*sqrt(1-z(:).^2).^(-k);\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/Specific_Derivatives/asinDerivVal.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.8976952845805989, "lm_q1q2_score": 0.8133027850789306}} {"text": "function value = i4_choose ( n, k )\n\n%*****************************************************************************80\n%\n%% I4_CHOOSE computes the binomial coefficient C(N,K).\n%\n% Discussion:\n%\n% The value is calculated in such a way as to avoid overflow and\n% roundoff. The calculation is done in integer arithmetic.\n%\n% The formula used is:\n%\n% C(N,K) = N! / ( K! * (N-K)! )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 June 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% ML Wolfson, HV Wright,\n% Algorithm 160:\n% Combinatorial of M Things Taken N at a Time,\n% Communications of the ACM,\n% Volume 6, Number 4, April 1963, page 161.\n%\n% Parameters:\n%\n% Input, integer N, K, are the values of N and K.\n%\n% Output, integer VALUE, the number of combinations of N\n% things taken K at a time.\n%\n mn = min ( k, n - k );\n\n if ( mn < 0 )\n\n value = 0;\n\n elseif ( mn == 0 )\n\n value = 1;\n\n else\n\n mx = max ( k, n - k );\n value = mx + 1;\n\n for i = 2 : mn\n value = ( value * ( mx + i ) ) / i;\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/polpak/i4_choose.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582612793112, "lm_q2_score": 0.8740772368049822, "lm_q1q2_score": 0.8132923859813884}} {"text": "function cdf = genlogistic_cdf ( x, a, b, c )\n\n%*****************************************************************************80\n%\n%% GENLOGISTIC_CDF evaluates the Generalized Logistic CDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 11 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the CDF.\n%\n% Input, real A, B, C, the parameters of the PDF.\n% 0.0 < B,\n% 0.0 < C.\n%\n% Output, real CDF, the value of the CDF.\n%\n y = ( x - a ) / b;\n\n cdf = 1.0 / ( 1.0 + exp ( - y ) )^c;\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/genlogistic_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.8652240895276223, "lm_q1q2_score": 0.8132356694254942}} {"text": "%%***********************************************************************\n%% gencorrmat2: generate correlation matrix\n%% \n%% B = gencorrmat(n,options);\n%% \n%% options = 'Randcorr'\n%% = 'Randcorr2'\n%% = 'Diag'\n%% = 'AR1'\n%% = 'CompSym'\n%% = 'Rand'\n%%***********************************************************************\n%% SDPNAL+ \n%% Copyright (c) 2014 by\n%% Liuqin Yang, Defeng Sun, and Kim-Chuan Toh\n%%***********************************************************************\n\n function B = gencorrmat(n,options,alpha)\n\n rng('default')\n if nargin == 2; alpha = 0; end\n \n if strcmp(options,'Randcorr') || (options == 1)\n beta = 10^(-4/(n-1));\n xx = beta.^[0:n-1]; \n xx = n*xx/sum(xx); \n B = gallery('randcorr',xx);\n elseif strcmp(options,'Randcorr2') || (options == 2)\n n2 = n/2; \n beta = 10^(-4/(n-1));\n xx = [beta.^[0:n2-1], zeros(1,n2)]; \n xx = n*xx/sum(xx); \n B = gallery('randcorr',xx);\n elseif strcmp(options,'Diag') || (options == 3)\n n2 = n/2; \n tmp = [ones(n2), zeros(n2); zeros(n2), eye(n2)]; \n B = diag(1e4*(2*rand(n,1)-1));\n elseif strcmp(options,'AR1') || (options == 4)\n tmp = -diag(ones(n,1)) - 0.8*diag(ones(n-1,1),-1); \n Dinv = (1/0.01)*speye(n,n); \n Binv = tmp'*Dinv*tmp; \n B = inv(Binv); B = 0.5*(B+B'); \n diagB = diag(B);\n B = diag(1./sqrt(diagB))*B*diag(1./sqrt(diagB)); \n elseif strcmp(options,'CompSym') || (options == 5)\n sigma = 1; rho = 0.5; \n dd = sigma^2*(1-[0:n-1]*(rho^2)./(1+[0:n-1]*rho)); \n tmp = zeros(n,n); \n for j=2:n\n tmp(1:j-1,j) = rho./(1+[1:j-1]'*rho);\n end\n tmp = -eye(n) -tmp; \n Dinv = diag(1./dd); \n Binv = tmp'*Dinv*tmp;\n B = inv(Binv); B = 0.5*(B+B'); \n diagB = diag(B);\n B = diag(1./sqrt(diagB))*B*diag(1./sqrt(diagB)); \n elseif strcmp(options,'Rand') || (options == 6)\n B = 2*rand(n)-1; \n B = 0.5*(B+B');\n end\n%% \n%% add noise\n%%\n E = 2*(rand(n)-0.5); E = triu(E,1)+ triu(E,1)'; \n B = (1-alpha)*B + alpha*E;\n B = min(B,1);\n B = max(-1,B);\n for i=1:n; B(i,i) = 1; end\n%%****************************************************\n", "meta": {"author": "intellhave", "repo": "SDRSAC", "sha": "b081721e9dfd7843d75aa12f30025b2bd7c8f024", "save_path": "github-repos/MATLAB/intellhave-SDRSAC", "path": "github-repos/MATLAB/intellhave-SDRSAC/SDRSAC-b081721e9dfd7843d75aa12f30025b2bd7c8f024/solvers/SDPNAL+v1.0/util/gencorrmat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428691, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.8132356627155953}} {"text": "function c = correlation_pentaspherical ( n, rho, rho0 )\n\n%*****************************************************************************80\n%\n%% CORRELATION_PENTASPHERICAL evaluates the pentaspherical correlation function.\n%\n% Discussion:\n%\n% This correlation is based on the volume of overlap of two spheres\n% of radius RHO0 and separation RHO.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 March 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Petter Abrahamsen,\n% A Review of Gaussian Random Fields and Correlation Functions,\n% Norwegian Computing Center, 1997.\n%\n% Parameters:\n%\n% Input, integer N, the number of arguments.\n%\n% Input, real RHO(N,1), the arguments.\n%\n% Input, real RHO0, the correlation length.\n%\n% Output, real C(N,1), the correlations.\n%\n rho = rho ( : );\n\n rhohat = min ( abs ( rho ) / rho0, 1.0 );\n\n c = 1.0 - 1.875 * rhohat + 1.25 * rhohat.^3 - 0.375 * rhohat.^5;\n\n return\nend\n\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/correlation/correlation_pentaspherical.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.8130883444380941}} {"text": "function [ux,uy,uz]=LK3D( image1, image2, r )\n%This function estimates deformations between two subsequent 3-D images\n%using Lucas-Kanade optical flow equation. \n%\n% Description : \n%\n% -image1, image2 : two subsequent images or frames\n% -r : radius of the neighbourhood, default value is 2. \n%\n% Reference :\n% Lucas, B. D., Kanade, T., 1981. An iterative image registration \n% technique with an application to stereo vision. In: Proceedings of the \n% 7th international joint conference on Artificial intelligence - Volume 2.\n% Morgan Kaufmann Publishers Inc., San Francisco, CA, USA, pp. 674-679.\n%\n% Author : Mohammad Mustafa\n% By courtesy of The University of Nottingham and Mirada Medical Limited,\n% Oxford, UK\n%\n% Published under a Creative Commons Attribution-Non-Commercial-Share Alike\n% 3.0 Unported Licence http://creativecommons.org/licenses/by-nc-sa/3.0/\n% \n% June 2012\n\n% Default parameter\nif nargin==2\n r=2;\nend\n\n[height,width,depth]=size(image1); \nimage1=im2double(image1);\nimage2=im2double(image2);\n\n% Initializing flow vectors\nux=zeros(size(image1)); uy=ux; uz=ux;\n\n% Computing image derivatives\n[Ix,Iy,Iz,It]=imageDerivatives3D(image1,image2);\n\nfor i=(r+1):(height-r)\n for j=(r+1):(width-r)\n for k=(r+1):(depth-r)\n \n blockofIx=Ix(i-r:i+r,j-r:j+r,k-r:k+r);\n blockofIy=Iy(i-r:i+r,j-r:j+r,k-r:k+r);\n blockofIz=Iz(i-r:i+r,j-r:j+r,k-r:k+r);\n blockofIt=It(i-r:i+r,j-r:j+r,k-r:k+r);\n\n \n A=zeros(3,3);\n B=zeros(3,1);\n \n A(1,1)=sum(sum(sum(blockofIx.^2)));\n A(1,2)=sum(sum(sum(blockofIx.*blockofIy)));\n A(1,3)=sum(sum(sum(blockofIx.*blockofIz)));\n \n A(2,1)=sum(sum(sum(blockofIy.*blockofIx)));\n A(2,2)=sum(sum(sum(blockofIy.^2)));\n A(2,3)=sum(sum(sum(blockofIy.*blockofIz)));\n\n A(3,1)=sum(sum(sum(blockofIz.*blockofIx)));\n A(3,2)=sum(sum(sum(blockofIz.*blockofIy)));\n A(3,3)=sum(sum(sum(blockofIz.^2)));\n \n B(1,1)=sum(sum(sum(blockofIx.*blockofIt)));\n B(2,1)=sum(sum(sum(blockofIy.*blockofIt)));\n B(3,1)=sum(sum(sum(blockofIz.*blockofIt)));\n \n invofA=pinv(A);\n \n V=invofA*(-B);\n ux(i,j,k)=V(1,1);\n uy(i,j,k)=V(2,1);\n uz(i,j,k)=V(3,1);\n end\n end\nend\n\nend\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/37170-lucas-kanade-optical-flow-method-for-3-d-images/LK3D/LK3D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012732322216, "lm_q2_score": 0.8596637577007393, "lm_q1q2_score": 0.8130710765849554}} {"text": "function dist_signed = line_exp_point_dist_signed_2d ( p1, p2, p )\n\n%*****************************************************************************80\n%\n%% LINE_EXP_POINT_DIST_SIGNED_2D: signed distance ( explicit line, point ) in 2D.\n%\n% Discussion:\n%\n% The explicit form of a line in 2D is:\n%\n% ( P1, P2 ) = ( (X1,Y1), (X2,Y2) ).\n%\n% The signed distance has two interesting properties:\n%\n% * The absolute value of the signed distance is the\n% usual (Euclidean) distance.\n%\n% * Points with signed distance 0 lie on the line,\n% points with a negative signed distance lie on one side\n% of the line,\n% points with a positive signed distance lie on the\n% other side of the line.\n%\n% Assuming that C is nonnegative, then if a point is a positive\n% distance away from the line, it is on the same side of the\n% line as the point (0,0), and if it is a negative distance\n% from the line, it is on the opposite side from (0,0).\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 P1(2,1), P2(2,1), two points on the line.\n%\n% Input, real P(2,1), the point whose signed distance is desired.\n%\n% Output, real DIST_SIGNED, the signed distance from the\n% point to the line.\n%\n\n%\n% If the explicit line degenerates to a point, the computation is easy.\n%\n if ( p1(1:2,1) == p2(1:2,1) )\n\n dist_signed = sqrt ( sum ( ( p1(1:2,1) - p(1:2,1) ).^2 ) );\n%\n% Convert the explicit line to the implicit form A * X + B * Y + C = 0.\n% This makes the computation of the signed distance to (X,Y) easy.\n%\n else\n\n a = p2(2,1) - p1(2,1);\n b = p1(1,1) - p2(1,1);\n c = p2(1,1) * p1(2,1) - p1(1,1) * p2(2,1);\n\n dist_signed = ( a * p(1,1) + b * p(2,1) + c ) / sqrt ( a * a + b * b );\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/line_exp_point_dist_signed_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012686491107, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.8130710692444766}} {"text": "clear all, close all, clc\nA = imread('../../CH01_SVD/DATA/dog.jpg');\nB = rgb2gray(A);\n\nfor j=1:size(B,1);\n Cshift(j,:) = fftshift(fft(B(j,:)));\n C(j,:) = (fft(B(j,:)));\nend\n\nfor j=1:size(C,2);\n D(:,j) = fft(C(:,j));\nend\n\nsubplot(1,3,1)\nimagesc(B);\nsubplot(1,3,2)\nimagesc(log(abs(Cshift)))\nsubplot(1,3,3)\nimagesc(fftshift(log(abs(D))))\ncolormap gray\n%%\nfigure\nimagesc(B)\ncolormap gray\naxis off\naxis tight\nset(gcf,'Position',[100 100 600 800])\nset(gcf,'PaperPositionMode','auto')\nprint('-depsc2', '-loose', '../figures/2DFFTa');\n\nfigure\nimagesc(log(abs(Cshift)))\ncolormap gray\n\naxis off\naxis tight\nset(gcf,'Position',[100 100 600 800])\nset(gcf,'PaperPositionMode','auto')\nprint('-depsc2', '-loose', '../figures/2DFFTb');\nfigure\nimagesc(fftshift(log(abs(D))))\ncolormap gray\naxis off\naxis tight\nset(gcf,'Position',[100 100 600 800])\nset(gcf,'PaperPositionMode','auto')\nprint('-depsc2', '-loose', '../figures/2DFFTc');\n\n%% FFT Compression\nfigure\nBt=fft2(B);\nF = log(abs(fftshift(Bt))+1); % put FFT on log-scale\n\n% Zero out all small coefficients and inverse transform\nBtsort = sort(abs(Bt(:)));\nkeepvec = [.1 .05 .01 .005 .002 .001];\nfor k=4:6\n keep = keepvec(k);\n % keep = 0.05;\n thresh = Btsort(floor((1-keep)*length(Btsort)));\n ind = abs(Bt)>thresh;\n Atlow = Bt.*ind;\n Flow = log(abs(fftshift(Atlow))+1); % put FFT on log-scale\n imshow(mat2gray(Flow),[]);\n \n % Plot Reconstruction\n Alow=uint8(ifft2(Atlow));\n imshow(Alow)\n \n axis off\n set(gcf,'PaperPositionMode','auto')\n % print('-depsc2', '-loose', ['../figures/2DFFT_Compress',num2str(k)]);\n print('-dpng', '-loose', ['../figures/2DFFT_Compress',num2str(k)]);\n \nend\n\n%% Denoise\nB = Bold(2:2:end,2:2:end);\nind = rand(size(B));\nBnoise = B + uint8(200*randn(size(B)));\n% Bnoise = B + uint8(200*rand(size(B)));\n% Bnoise = B.*uint8(ind<.2);\nimagesc(Bnoise)\ncolormap gray\naxis off\naxis tight\nset(gcf,'Position',[100 100 600 800])\nset(gcf,'PaperPositionMode','auto')\n% print('-dpng', '-loose', '../figures/2DFFT_Noise1');\n\nBt=fft2(Bnoise);\nBtshift = fftshift(Bt);\n[nx,ny] = size(B);\n\nfigure\nF = log(abs(Btshift)+1); % put FFT on log-scale\nimagesc(F)\ncolormap gray\naxis off\naxis tight\nset(gcf,'Position',[100 100 600 800])\nset(gcf,'PaperPositionMode','auto')\n% print('-dpng', '-loose', '../figures/2DFFT_Noise2');\n\n[X,Y] = meshgrid(-ny/2+1:ny/2,-nx/2+1:nx/2);\nR2 = X.^2+Y.^2;\nind = R2<150^2;\nBtshiftfilt = Btshift.*ind;\n\nfigure\nFfilt = log(abs(Btshiftfilt)+1); % put FFT on log-scale\nimagesc(Ffilt)\ncolormap gray\naxis off\naxis tight\nset(gcf,'Position',[100 100 600 800])\nset(gcf,'PaperPositionMode','auto')\n% print('-dpng', '-loose', '../figures/2DFFT_Noise3');\n\nfigure\nBtfilt = ifftshift(Btshiftfilt);\nBfilt = ifft2(Btfilt);\nimagesc(uint8(Bfilt))\ncolormap gray\naxis off\naxis tight\nset(gcf,'Position',[100 100 600 800])\nset(gcf,'PaperPositionMode','auto')\n% print('-dpng', '-loose', '../figures/2DFFT_Noise4');\n\n%% Wavelet Compression\nfigure\n[C,S] = wavedec2(B,4,'db1');\n\n% Zero out all small coefficients and inverse transform\nCsort = sort(abs(C(:)));\nkeepvec = [.1 .05 .01 .005 .002 .001];\nfor k=1:6\n figure\n keep = keepvec(k);\n % keep = 0.05;\n thresh = Csort(floor((1-keep)*length(Csort)));\n ind = abs(C)>thresh;\n Cfilt = C.*ind;\n \n % Plot Reconstruction\n Alow=uint8(waverec2(Cfilt,S,'db1'));\n imagesc(uint8(Alow))\n colormap gray\n \n colormap gray\n axis off\n axis tight\n set(gcf,'Position',[100 100 600 800])\n set(gcf,'PaperPositionMode','auto')\n % print('-depsc2', '-loose', ['../figures/2DFFT_Compress',num2str(k)]);\n print('-dpng', '-loose', ['../figures/2DWavelet_Compress',num2str(k)]);\n \nend\n\n", "meta": {"author": "dynamicslab", "repo": "databook_matlab", "sha": "d390d39d18489a4804ee87a143ae8db8a1f3010b", "save_path": "github-repos/MATLAB/dynamicslab-databook_matlab", "path": "github-repos/MATLAB/dynamicslab-databook_matlab/databook_matlab-d390d39d18489a4804ee87a143ae8db8a1f3010b/CH02/CH02_SEC06_1_2DFFT_production.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509315, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.813016297644086}} {"text": "function a = circulant ( m, n, x )\n\n%*****************************************************************************80\n%\n%% CIRCULANT returns the CIRCULANT matrix.\n%\n% Formula:\n%\n% K = 1 + mod ( J-I, N )\n% A(I,J) = X(K)\n%\n% Example:\n%\n% M = 4, N = 4, X = ( 1, 2, 3, 4 )\n%\n% 1 2 3 4\n% 4 1 2 3\n% 3 4 1 2\n% 2 3 4 1\n%\n% M = 4, N = 5, X = ( 1, 2, 3, 4, 5 )\n%\n% 1 2 3 4 5\n% 5 1 2 3 4\n% 4 5 1 2 3\n% 3 4 5 1 2\n%\n% M = 5, N = 4, X = ( 1, 2, 3, 4 )\n%\n% 1 2 3 4\n% 5 1 2 3\n% 4 5 1 2\n% 3 4 5 1\n% 1 2 3 4\n%\n% Discussion:\n%\n% Westlake lists the following \"special\" circulants:\n%\n% B2, X = ( T^2, 1, 2, ..., T, T+1, T, T-1, ..., 1 ),\n% with T = ( N - 2 ) / 2;\n%\n% B3, X = ( N+1, 1, 1, ..., 1 );\n%\n% B5, X = ( 1, 2, 3, ..., N ).\n%\n% Rectangular Properties:\n%\n% The product of two circulant matrices is a circulant matrix.\n%\n% The transpose of a circulant matrix is a circulant matrix.\n%\n% A circulant matrix C, whose first row is (c1, c2, ..., cn), can be\n% written as a polynomial in the upshift matrix U:\n%\n% C = c1 * I + c2 * U + c3 * U**2 + ... + cn * U**n-1.\n%\n% A is a circulant: each row is shifted once to get the next row.\n%\n% Square Properties:\n%\n% A is generally not symmetric: A' /= A.\n%\n% A is Toeplitz: constant along diagonals.\n%\n% A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\n%\n% A commutes with any other circulant matrix.\n%\n% A is normal.\n%\n% The transpose of A is also a circulant matrix.\n%\n% The inverse of A is also a circulant matrix.\n%\n% The Fourier matrix is the eigenvector matrix for every circulant matrix.\n%\n% Because the Fourier matrix F diagonalizes A, the inverse (or\n% pseudoinverse, if any LAMBDA is zero) can be written\n%\n% inverse ( A ) = (F*) * 1/LAMBDA * F\n%\n% A is symmetric if, for all I, X(I+1) = X(N-I+1).\n%\n% If R is an N-th root of unity, that is, R is a complex number such\n% that R**N = 1, then\n%\n% Y = X(1) + X(2)*R + X(3)*R**2 + ... + X(N)*R**(N-1)\n%\n% is an eigenvalue of A, with eigenvector\n%\n% ( 1, R, R**2, ..., R**(N-1) )\n%\n% and left eigenvector\n%\n% ( R**(N-1), R**(N-2), ..., R**2, R, 1 ).\n%\n% Although there are exactly N distinct roots of unity, the circulant\n% may have repeated eigenvalues, because of the behavior of the polynomial.\n% However, the matrix is guaranteed to have N linearly independent\n% eigenvectors.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Philip Davis,\n% Circulant Matrices,\n% John Wiley, 1979, QA188.D37.\n%\n% Robert Gregory, David Karney,\n% A Collection of Matrices for Testing Computational Algorithms,\n% Wiley, New York, 1969, page 22, \n% LC: QA263.G68.\n%\n% Joan Westlake,\n% Test Matrix A24,\n% A Handbook of Numerical Matrix Inversion and Solution of Linear Equations,\n% John Wiley, 1968.\n%\n% Parameters:\n%\n% Input, integer M, N, the number of rows and columns of A.\n%\n% Input, real X(N), the values in the first row of A.\n%\n% Output, real A(M,N), the matrix.\n%\n for i = 1 : m\n for j = 1 : n\n\n k = 1 + i4_modp ( j-i, n );\n a(i,j) = x(k);\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/circulant.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8807970826714614, "lm_q1q2_score": 0.8130102031104438}} {"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 delta = (1 / m * (X * theta - y)' * X)';\n\n theta = theta - alpha * delta;\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": "benoitvallon", "repo": "coursera-machine-learning", "sha": "74ec09a5072eb5f3fec942fee45076e4f05b35af", "save_path": "github-repos/MATLAB/benoitvallon-coursera-machine-learning", "path": "github-repos/MATLAB/benoitvallon-coursera-machine-learning/coursera-machine-learning-74ec09a5072eb5f3fec942fee45076e4f05b35af/machine-learning-ex1/ex1/gradientDescentMulti.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.880797068590724, "lm_q1q2_score": 0.8130101901133718}} {"text": "function [ res, jac ] = opt01_rj ( x, flag )\n\n%*****************************************************************************80\n%\n%% OPT01_RJ evaluates RES and JAC for test case #1.\n%\n% Discussion:\n%\n% This example is discussed in Dennis and Schnabel, pages 100, 104 and 202.\n%\n% Suggested starting value for X is ( 1, 1 ).\n%\n% The optimizing value is\n%\n% X* = ( 2, -1 ), \n%\n% for which \n%\n% RES(X*) = (0,0,0).\n%\n% Modified:\n%\n% 05 January 2008\n%\n% Author:\n%\n% Jeff Borggaard,\n% Gene Cliff,\n% Virginia Tech.\n%\n% Reference:\n%\n% John Dennis, Robert Schnabel,\n% Numerical Methods for Unconstrained Optimization \n% and Nonlinear Equations,\n% SIAM, 1996,\n% ISBN13: 978-0-898713-64-0,\n% LC: QA402.5.D44.\n%\n% Parameters:\n%\n% Input, real X(2), the evaluation point.\n%\n% Input, string FLAG, indicates what must be computed.\n% 'f' means only the value of RES is needed,\n% 'g' means only the value of JAC is needed,\n% 'all' means RES and JAC are needed.\n% It is acceptable to behave as though FLAG was 'all'\n% on every call.\n%\n% Output, real RES(3), the residual column vector.\n%\n% Output, real JAC(3,2), the Jacobian matrix.\n%\n n = length ( x );\n\n if ( n ~= 2 )\n fprintf ( '\\n' );\n fprintf ( 'OPT01_RJ - Fatal error!\\n' );\n fprintf ( ' The input vector X should have length 2.\\n'), \n fprintf ( ' Instead, it has length = %d.\\n', n );\n keyboard\n end\n%\n% Formulated as a nonlinear system:\n%\n res(1,1) = ( x(1) - 2 )^2;\n res(2,1) = ( x(1) - 2 ) * x(2);\n res(3,1) = ( x(2) + 1);\n\n jac(1,1) = 2 * ( x(1) - 2 );\n jac(1,2) = 0;\n\n jac(2,1) = x(2);\n jac(2,2) = x(1) - 2;\n\n jac(3,1) = 0;\n jac(3,2) = 1;\n\nreturn\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/entrust/opt01_rj.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.9099070011518829, "lm_q1q2_score": 0.8128284931016488}} {"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\nh=theta'*X'; \n\ndelta=1/m*(X'*X*theta-X'*y);\n\ntheta=theta-alpha.*delta;\n\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": "yhyap", "repo": "machine-learning-coursera", "sha": "fb33f0ad54ff2104660c86b0d26456b15029a798", "save_path": "github-repos/MATLAB/yhyap-machine-learning-coursera", "path": "github-repos/MATLAB/yhyap-machine-learning-coursera/machine-learning-coursera-fb33f0ad54ff2104660c86b0d26456b15029a798/mlclass-ex1/gradientDescentMulti.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.8774767858797979, "lm_q1q2_score": 0.8128100200068038}} {"text": "function [ytrend,ycycle]=one_sided_hpfilter_serial(y,lambda,discard)\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% I am grateful to Martin Kliem for pointing out this alternative to the\n% Kalman variant to me and for sharing his code with me.\n%\n% Copyright: Alexander Meyer-Gohde\n%\n% You are free to use/modify/redistribute this program so long as original\n% authorship credit is given and you in no way impinge on its free\n% distribution\n%\n%\n% This program executes a one-sided HP filter by running the\n% standard two-sided HP filter successively with each new observation\n%\n% Input: y - a Txn data matrix, where T is the number of observations\n% on n variables (i.e.,data is assumed to be in column format). \n% lambda - a smoothing scalar. If not entered, default is 1600.\n% discard - a scalar. The first discard periods will be\n% discarded resulting in output matrices of size\n% (T-discard)xn. Optional: if not entered, default value is 0.\n%\n% Output: ytrend - a (T-discard)xn matrix of extracted trends for\n% each of the n variables.\n% ycycle a (T-discard)xn matrix of deviations from the trends \n% for each of the n variables. Optional.\n%\n% Usage example:\n% [ytrend]=one_sided_hp_filter_kalman(y)\n% will yield the Txn matrix of trends using the data in\n% y with lambda set to 1600\n%\n%\n% This one-side HP filter finds a series {ytrend_t}_{t=1}^T for\n% each n by calculating for each t the standard HP filtered trend using\n% all data upto that t and setting ytrend_t equal to the resulting trend \n% value for period t.\n%\n% See: Mehra, Y.P. (2004). \"The Output Gap, Expected Future Inflation and \n% Inflation Dynamics: Another Look,\" \n% The B.E. Journal of Macroeconomics, Berkeley Electronic Press.\n%\n% The standard HP filter finds a series {ytrend_t}_{t=1}^T that solves\n% the following minimization probelm\n% \n% min sum_{t=1}^T(y_t-ytrend_t)\n% +lambda*sum_{t=2}^{T-1}[(ytrend_{t+1}-ytrend_{t})-(ytrend_{t}-ytrend_{t-1})]\n%\n% Rearanging the first order conditions yields: A*ytrend=y where\n% A=[ 1+lambda -2*lambda lambda 0 0 0 ...\n% [ -2*lambda 1+5*lambda -4*lambda lambda 0 0 ...\n% [ lambda -4*lambda 1+6*lambda -4*lambda lambda 0 ...\n% [ ...\n% [ 0 ... 0 lambda -4*lambda 1+6*lambda -4*lambda lambda 0 ... 0]\n% [ ... ]\n% [ 0 ... lambda -4*lambda 1+6*lambda -4*lambda lambda]\n% [ 0 ... 0 lambda -4*lambda 1+5*lambda -2*lambda ]\n% [ 0 ... 0 0 lambda -2*lambda 1+lambda]\n%\n%\n% Hodrick, R.J. and E.C.Prescott (1997), \"Postwar U.S. Business Cycles:\n% An Empirical Investigation.\" Jounal of Money, Credit and Banking.\n% 29(1), Feb. pp. 1--16.\n%\n% Note that filter will be calculated over and over again with an\n% expanding matrix A. This program uses sparse matrices and exploits the\n% patter in A as t progresses.\n%\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nif nargin < 2, lambda = 1600; end%If the user does not provide lambda, set it to 1600\n[T,n] = size (y); % Calculate the number of periods and the number of variables in the series\n\n%%Preliminary calculations\nx1=[1+lambda, -2*lambda, lambda]; %The non-zero elements of the first row of A\nx2=[ -2*lambda, 1+5*lambda, -4*lambda, lambda];%The non-zero elements of the second row of A\nx3=[lambda, -4*lambda, 1+6*lambda, -4*lambda, lambda];%The non-zero elements of thej'th row of A, 2 maxSamples)\n % Truncate data for sample mean calculations\n Zcwt = Zcw(:,randperm(n,maxSamples));\nelse\n % Full data\n Zcwt = Zcw;\nend\n\n% Random initial weights\nnormRows = @(X) bsxfun(@times,X,1 ./ sqrt(sum(X.^2,2)));\nW = normRows(rand(r,d));\n\n% FastICA w/ Gaussian negentropy\nk = 0;\nerr = inf;\nwhile (err > eps) && (k < maxIters)\n % Increment counter\n k = k + 1;\n \n % Update weights\n Wlast = W; % Save last weights\n Sk = permute(Wlast * Zcwt,[1 3 2]);\n G = Sk .* exp(-0.5 * Sk.^2);\n Gp = Sk .* G;\n W = mean(bsxfun(@times,G,permute(Zcwt,[3 1 2])),3) + bsxfun(@times,mean(Gp,3),Wlast);\n W = normRows(W);\n \n % Decorrelate weights\n [U,S,~] = svd(W,'econ');\n W = U * diag(1 ./ diag(S)) * U' * W;\n \n % Update error\n err = max(1 - dot(W,Wlast,2));\n \n % Display progress\n if dispFlag == true\n sprintf('Iteration %i: max(1 - ) = %.4g\\n',k,k,k - 1,err);\n end\nend\n\n% Transformation matrix\nA = W;\n\n% Independent components\nZica = A * Zcw;\n", "meta": {"author": "zhangqianqianQQ", "repo": "MachineVisionAlgorithm", "sha": "683338f6c3b1aab9fa2b80026915fe936aebf0ee", "save_path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm", "path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm/MachineVisionAlgorithm-683338f6c3b1aab9fa2b80026915fe936aebf0ee/分类算法/deephypercnn-master/Matlab-Sat-Data/pca_ica/myICA.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294984, "lm_q2_score": 0.8705972650509008, "lm_q1q2_score": 0.8126423111965256}} {"text": "function f = f12_f0 ( n, x, y )\n\n%*****************************************************************************80\n%\n%% F12_F0 returns the value of function 12.\n%\n% Discussion:\n%\n% This is an example from Vicente Romero.\n%\n% R = sqrt ( X^2 + Y^2 )\n% T = atan ( Y / X )\n% F(X,Y) = ( 0.8 * R + 0.35 * sin ( 2.4 * pi * R / sqrt ( 2 ) ) )\n% * 1.5 * sin ( 1.3 * T )\n%\n% The mean and standard deviation of the function over the interval\n% are approximately:\n%\n% mu = 0.581608\n% sigma = 0.343208\n%\n% Since the interpolation interval is the unit square, this means the\n% integral of the function over the interval can also be estimated as\n%\n% I = 0.581608\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 August 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Vicente Romero, John Burkardt, Max Gunzburger, Janet Peterson,\n% Initial Evaluation of Centroidal Voronoi Tessellation for\n% Statistical Sampling and Function Integration,\n% Fourth International Symposium on Uncertainty Modeling and Analysis,\n% (ISUMA) 2003.\n%\n% Parameters:\n%\n% Input, integer N, the number of evaluation points.\n%\n% Input, real X(N,1), Y(N,1), the evalution points.\n%\n% Output, real F(N,1), the function values.\n%\n r(1:n,1) = sqrt ( x(1:n,1).^2 + y(1:n,1).^2 );\n t(1:n,1) = atan2 ( y(1:n,1), x(1:n,1) );\n\n f(1:n,1) = 1.5 * ( 0.8 * r(1:n,1) ...\n + 0.35 * sin ( 2.4 * pi * r(1:n,1) / sqrt ( 2.0 ) ) ) ...\n .* sin ( 1.3 * t(1: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/test_interp_2d/f12_f0.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107966642556, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.8125952848406656}} {"text": "function w = moments_normal_01 ( m )\n\n%*****************************************************************************80\n%\n%% MOMENTS_NORMAL_01 returns moments of the standard Normal distribution.\n%\n% Discussion:\n%\n% pdf(x) = exp ( -x^2/2 ) / sqrt ( pi * 2 )\n% mu(k) = integral ( -oo < x < +oo ) x^k pdf(x) dx\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 September 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer M, the number of moments desired.\n%\n% Output, real W(M), the weighted integrals of X^0 through X^(M-1).\n%\n w = zeros ( m, 1 );\n\n w(1) = 1.0;\n\n for k = 3 : 2: m\n w(k) = r8_factorial2 ( k - 2 );\n end\n\n for k = 2 : 2 : m\n w(k) = 0.0;\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/quadmom/moments_normal_01.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104868, "lm_q2_score": 0.8670357598021707, "lm_q1q2_score": 0.8125952736600103}} {"text": "function pdf = dirichlet_pdf ( x, n, a )\n\n%*****************************************************************************80\n%\n%% DIRICHLET_PDF evaluates the Dirichlet PDF.\n%\n% Discussion:\n%\n% PDF(X)(N,A) = Product ( 1 <= I <= N ) X(I)**( A(I) - 1 )\n% * Gamma ( A_SUM ) / A_PROD\n%\n% where\n%\n% 0 < A(I) for all I;\n% 0 <= X(I) for all I;\n% Sum ( 1 <= I <= N ) X(I) = 1;\n% A_SUM = Sum ( 1 <= I <= N ) A(I).\n% A_PROD = Product ( 1 <= I <= N ) Gamma ( A(I) )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 30 October 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X(N), the argument of the PDF. Each X(I) should\n% be greater than 0.0, and the X(I)'s must add up to 1.0.\n%\n% Input, integer N, the number of components.\n%\n% Input, real A(N), the probabilities for each component.\n% Each A(I) should be positive.\n%\n% Output, real PDF, the value of the PDF.\n%\n tol = 0.0001;\n\n for i = 1 : n\n if ( x(i) <= 0.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'DIRICHLET_PDF - Fatal error!\\n' );\n fprintf ( 1, ' X(I) <= 0.\\n' );\n end\n end\n\n x_sum = sum ( x(1:n) );\n\n if ( tol < abs ( x_sum - 1.0 ) )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'DIRICHLET_PDF - Fatal error!\\n' );\n fprintf ( 1, ' SUM X(I) =/= 1.\\n' );\n end\n\n a_sum = sum ( a(1:n) );\n\n a_prod = 1.0;\n for i = 1 : n\n a_prod = a_prod * gamma ( a(i) );\n end\n\n pdf = gamma ( a_sum ) / a_prod;\n for i = 1 : n\n pdf = pdf * x(i)^( a(i) - 1.0 );\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/prob/dirichlet_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248174286374, "lm_q2_score": 0.8652240877899775, "lm_q1q2_score": 0.812466891071843}} {"text": "function dist = circle_imp_point_dist_2d ( r, center, p )\n\n%*****************************************************************************80\n%\n%% CIRCLE_IMP_POINT_DIST_2D: distance ( implicit circle, point ) in 2D.\n%\n% Discussion:\n%\n% The distance is zero if the point is on the circle.\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% 31 January 2005\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,1), the center of the circle.\n%\n% Input, real P(2,1), the point to be checked.\n%\n% Output, real DIST, the distance of the point to the circle.\n%\n dim_num = 2;\n\n r2 = sqrt ( sum ( ( p(1:2,1) - center(1:2,1) ).^2 ) );\n\n dist = abs ( r2 - r );\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/circle_imp_point_dist_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.8791467722591728, "lm_q1q2_score": 0.8124562963072808}} {"text": "% Calculate the number of star motifs of given (subgraph) size.\n% Note 1: Easily extendible to return the actual stars as k-tuples of nodes.\n% Note 2: Star of size 1 is the trivial case of a single node.\n%\n% INPUTs: adjacency list {} (1xn), k - star motif size\n% OUTPUTs: number of stars with k nodes (k-1 spokes)\n%\n% GB: last updated, Oct 5, 2012\n\nfunction num = numStarMotifs(adjL,k)\n\nnum = 0;\n\nfor i=1:length(adjL)\n if length(adjL{i})>=(k-1); num = num + nchoosek(length(adjL{i}),k-1); end\nend\n\n\n\n% ALTERNATIVE\n% function num = numStarMotifs(adj,k)\n% \n% % INPUTs: adjacency matrix, k - star motif size\n% % OUTPUTs: number of stars with k nodes (k-1 spokes)\n%\n% [deg,~,~]=degrees(adj);\n%\n% num=0;\n%\n% for i=1:length(deg)\n% if deg(i)>=(k-1); num=num+nchoosek(deg(i),k-1); end\n% end", "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/numStarMotifs.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731147976794, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.8123951326079333}} {"text": "function a = parter ( m, n )\n\n%*****************************************************************************80\n%\n%% PARTER returns the PARTER matrix.\n%\n% Formula:\n%\n% A(I,J) = 1 / ( i - j + 0.5 )\n%\n% Example:\n%\n% N = 5\n%\n% 2 -2 -2/3 -2/5 -2/7\n% 2/3 2 -2 -2/3 -2/5\n% 2/5 2/3 2 -2 -2/3\n% 2/7 2/5 2/3 2 -2\n% 2/9 2/7 2/5 2/3 2\n%\n% Properties:\n%\n% The diagonal entries are all 2, the first superdiagonals all -2.\n%\n% A is Toeplitz: constant along diagonals.\n%\n% A is generally not symmetric: A' ~= A.\n%\n% A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\n%\n% A is a special case of the Cauchy matrix.\n%\n% Most of the singular values are very close to Pi.\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% 17 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Seymour Parter,\n% On the distribution of the singular values of Toeplitz matrices,\n% Linear Algebra and Applications,\n% Volume 80, August 1986, pages 115-130.\n%\n% Evgeny Tyrtyshnikov,\n% Cauchy-Toeplitz matrices and some applications,\n% Linear Algebra and Applications,\n% Volume 149, 15 April 1991, pages 1-18.\n%\n% Parameters:\n%\n% Input, integer M, N, the order 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 a(i,j) = 1.0 / ( ( i - j ) + 0.5 );\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/parter.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.8856314768368161, "lm_q1q2_score": 0.8123921071130412}} {"text": "function [u,s,v] = svdsim(a,tol)\n%SVDSIM simple SVD program\n%\n% A simple program that demonstrates how to use the\n% QR decomposition to perform the SVD of a matrix.\n% A may be rectangular and complex.\n%\n% usage: [U,S,V]= SVDSIM(A)\n% or S = SVDSIM(A)\n%\n% with A = U*S*V' , S>=0 , U'*U = Iu , and V'*V = Iv\n%\n% The idea is to use the QR decomposition on A to gradually \"pull\" U out from\n% the left and then use QR on A transposed to \"pull\" V out from the right.\n% This process makes A lower triangular and then upper triangular alternately.\n% Eventually, A becomes both upper and lower triangular at the same time,\n% (i.e. Diagonal) with the singular values on the diagonal.\n%\n% Matlab's own SVD routine should always be the first choice to use,\n% but this routine provides a simple \"algorithmic alternative\"\n% depending on the users' needs.\n% \n%see also: SVD, EIG, QR, BIDIAG, HESS\n%\n\n% Paul Godfrey\n% October 23, 2006\n\nif ~exist('tol','var')\n tol=eps*1024;\nend\n \n%reserve space in advance\nsizea=size(a);\nloopmax=100*max(sizea);\nloopcount=0;\n\n% or use Bidiag(A) to initialize U, S, and V\nu=eye(sizea(1));\ns=a';\nv=eye(sizea(2));\n\nErr=realmax;\nwhile Err>tol & loopcount 0\n if nargin==1 && isstruct(varargin{1}) && isscalar(varargin{1})\n S = varargin{1};\n this.eigenvectors = S.eigenvectors;\n this.eigenvalues = S.eigenvalues;\n this.mean = S.mean;\n else\n this.compute(varargin{:});\n end\n end\n end\n\n function delete(this)\n %DELETE Destructor\n %\n % obj.delete()\n %\n % See also: cv.PCA\n %\n if isempty(this.id), return; end\n PCA_(this.id, 'delete');\n end\n\n function read(this, fname_or_str, varargin)\n %READ Read PCA objects from file\n %\n % obj.read(filename)\n % obj.read(str, 'FromString',true)\n % obj.read(..., 'OptionName', optionValue, ...)\n %\n % ## Input\n % * __filename__ Name of the file to read.\n % * __str__ String containing serialized object you want to load.\n %\n % ## Options\n % * __FromString__ Logical flag to indicate whether the input is a\n % filename or a string containing the serialized object.\n % default false\n %\n % Loads `eigenvalues`, `eigenvectors` and `mean` from specified\n % storage.\n %\n % See also: cv.PCA.write\n %\n PCA_(this.id, 'read', fname_or_str, varargin{:});\n end\n\n function varargout = write(this, filename)\n %WRITE Write PCA objects to file\n %\n % obj.write(filename)\n % str = obj.write(filename)\n %\n % ## Input\n % * __filename__ Name of the file to write to.\n %\n % ## Output\n % * __str__ optional output. If requested, the object is persisted\n % to a string in memory instead of writing to disk.\n %\n % Writes `eigenvalues`, `eigenvectors` and `mean` to the specified\n % file.\n %\n % See also: cv.PCA.read\n %\n [varargout{1:nargout}] = PCA_(this.id, 'write', filename);\n end\n\n function compute(this, data, varargin)\n %COMPUTE Performs Principal Component Analysis on the supplied dataset\n %\n % pca.compute(data)\n % pca.compute(..., 'OptionName', optionValue, ...)\n %\n % ## Input\n % * __data__ input samples stored as the matrix rows or as the\n % matrix columns\n %\n % ## Options\n % * __DataAs__ Data layout option. Default 'Row'. One of:\n % * __Row__ indicates that the input samples are stored as\n % matrix rows.\n % * __Col__ indicates that the input samples are stored as\n % matrix columns.\n % * __MaxComponents__ Maximum number of components that PCA should\n % retain. default 0 (all the components are retained).\n % * __RetainedVariance__ Percentage of variance that PCA should\n % retain. Using this parameter will let the PCA decided how many\n % components to retain but it will always keep at least 2.\n % default 1.0 (all the components are retained).\n % * __Mean__ Optional mean value. By default, the mean is computed\n % from the data. Not set by default.\n %\n % **Note**: `RetainedVariance` and `MaxComponents` are mutually\n % exclusive options, and shoudn't be used together.\n %\n % The method performs PCA of the supplied dataset. It is safe\n % to reuse the same PCA structure for multiple datasets. That\n % is, if the structure has been previously used with another\n % dataset, the existing internal data is reclaimed and the new\n % `eigenvalues`, `eigenvectors` and `mean` are allocated and\n % computed.\n %\n % The computed `eigenvalues` are sorted from the largest to the\n % smallest and the corresponding `eigenvectors` are stored as\n % cv.PCA.eigenvectors rows.\n %\n % See also: cv.PCA.PCA, cv.PCA.project, cv.PCA.backProject\n %\n PCA_(this.id, 'compute', data, varargin{:});\n\n % invalidate cached properties\n this.p_eigenvectors = [];\n this.p_eigenvalues = [];\n this.p_mean = [];\n end\n\n function Y = project(this, X)\n %PROJECT Projects vector(s) to the principal component subspace\n %\n % Y = pca.project(X)\n %\n % ## Input\n % * __X__ input vector(s); must have the same dimensionality and\n % the same layout as the input data used at PCA phase, that is,\n % if 'Row' was specified, then `size(X,2)==size(data,2)` (vector\n % dimensionality) and `size(X,1)` is the number of vectors to\n % project, and the same is true for the 'Col' case.\n %\n % ## Output\n % * __Y__ output vectors (PC coefficients); in case of 'Col', the\n % output matrix has as many columns as the number of input\n % vectors, this means that `size(Y,2)==size(X,2)` and the number\n % of rows match the number of principal components (for example,\n % `MaxComponents` parameter passed to the constructor).\n %\n % The method project one or more vectors to the principal\n % component subspace, where each vector projection is\n % represented by coefficients in the principal component basis.\n %\n % See also: cv.PCA, cv.PCA.backProject\n %\n Y = PCA_(this.id, 'project', X);\n end\n\n function X = backProject(this, Y)\n %BACKPROJECT Reconstructs vectors from their PC projections\n %\n % X = pca.backProject(Y)\n %\n % ## Input\n % * __Y__ coordinates of the vectors in the principal component\n % subspace, the layout and size are the same as of\n % cv.PCA.project output vectors.\n %\n % ## Output\n % * __X__ reconstructed vectors; the layout and size are the same\n % as of cv.PCA.project input vectors.\n %\n % The method is the inverse operation to cv.PCA.project. It\n % takes PC coordinates of projected vectors and reconstruct the\n % original vectors. Unless all the principal components have\n % been retained, the reconstructed vectors are different from\n % the originals. But typically, the difference is small if the\n % number of components is large enough (but still much smaller\n % than the original vector dimensionality). As a result, PCA is\n % used.\n %\n % See also: cv.PCA.compute, cv.PCA.project\n %\n X = PCA_(this.id, 'backProject', Y);\n end\n end\n\n %% Getters/Setters for dependent properties\n methods\n function value = get.eigenvectors(this)\n if isempty(this.p_eigenvectors)\n this.p_eigenvectors = PCA_(this.id, 'get', 'eigenvectors');\n end\n value = this.p_eigenvectors;\n end\n function set.eigenvectors(this, value)\n PCA_(this.id, 'set', 'eigenvectors', value);\n this.p_eigenvectors = value;\n end\n\n function value = get.eigenvalues(this)\n if isempty(this.p_eigenvalues)\n this.p_eigenvalues = PCA_(this.id, 'get', 'eigenvalues');\n end\n value = this.p_eigenvalues;\n end\n function set.eigenvalues(this, value)\n PCA_(this.id, 'set', 'eigenvalues', value);\n this.p_eigenvalues = value;\n end\n\n function value = get.mean(this)\n if isempty(this.p_mean)\n this.p_mean = PCA_(this.id, 'get', 'mean');\n end\n value = this.p_mean;\n end\n function set.mean(this, value)\n PCA_(this.id, 'set', 'mean', value);\n this.p_mean = value;\n end\n end\n\n methods (Hidden)\n function S = struct(this)\n %STRUCT Converts to a struct array\n %\n % S = struct(obj)\n %\n % ## Output\n % * __S__ output struct array\n %\n % See also: cv.PCA\n %\n S = struct('eigenvectors',{this.eigenvectors},...\n 'eigenvalues', {this.eigenvalues},...\n 'mean', {this.mean});\n end\n\n function S = saveobj(this)\n %SAVEOBJ Serialization before save\n %\n % S = obj.saveobj()\n %\n % ## Output\n % * __S__ output struct.\n %\n % Called by the `save` function, when saving object to a MAT-file.\n %\n % See also: cv.PCA.loadobj, saveobj, loadobj\n %\n S = struct(this);\n end\n end\n\n methods (Static, Hidden)\n function this = loadobj(S)\n %LOADOBJ Deserialization after load\n %\n % obj = loadobj(S)\n %\n % ## Input\n % * __S__ input struct.\n %\n % Called by the `load` function, when loading object from a\n % MAT-file.\n %\n % See also: cv.PCA.PCA, cv.PCA.saveobj, saveobj, loadobj\n %\n this = cv.PCA(S);\n end\n end\n\nend\n", "meta": {"author": "kyamagu", "repo": "mexopencv", "sha": "d29007b2a484d0fd92e6e941dc5fd4750014fa6a", "save_path": "github-repos/MATLAB/kyamagu-mexopencv", "path": "github-repos/MATLAB/kyamagu-mexopencv/mexopencv-d29007b2a484d0fd92e6e941dc5fd4750014fa6a/+cv/PCA.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897492587141, "lm_q2_score": 0.8633916152464016, "lm_q1q2_score": 0.8122699812197383}} {"text": "function weight = subset_weight ( n, t )\n\n%*****************************************************************************80\n%\n%% SUBSET_WEIGHT computes the Hamming weight of a set.\n%\n% Discussion:\n%\n% The Hamming weight is simply the number of elements in the set.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 22 August 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Donald Kreher, Douglas Simpson,\n% Combinatorial Algorithms,\n% CRC Press, 1998,\n% ISBN: 0-8493-3988-X,\n% LC: QA164.K73.\n%\n% Parameters:\n%\n% Input, integer N, the order of the master set, of which T\n% is a subset. N must be positive.\n%\n% Input, integer T(N), defines the subset T.\n% T(I) is 1 if I is an element of T, and 0 otherwise.\n%\n% Output, integer WEIGHT, the Hamming weight of the subset T.\n%\n\n%\n% Check.\n%\n subset_check ( n, t );\n\n weight = sum ( t(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/combo/subset_weight.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.9005297961287784, "lm_q1q2_score": 0.8122064429594765}} {"text": "function a = smoke ( n )\n\n%*****************************************************************************80\n%\n%% SMOKE returns the SMOKE matrix.\n%\n% Formula:\n%\n% W = exp ( 2 * PI * sqrt ( -1 ) / N )\n%\n% If ( J = I + 1 )\n% A(I,J) = 1\n% If ( I = N and J = 1 )\n% A(I,J) = 1\n% If ( I = J )\n% A(I,J) = W**I\n% Else\n% A(I,J) = 0\n%\n% Example:\n%\n% N = 5\n%\n% w 1 0 0 0\n% 0 w**2 1 0 0\n% 0 0 w**3 1 0\n% 0 0 0 w**4 1\n% 1 0 0 0 w**5\n%\n% Properties:\n%\n% A is generally not symmetric: A' /= A.\n%\n% The matrix has an interesting spectrum. The eigenvalues are\n% the N-th roots of unity times 2**(1/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% Lothar Reichel, Lloyd Trefethen,\n% Eigenvalues and pseudo-eigenvalues of Toeplitz matrices,\n% Linear Algebra and Applications,\n% Volume 162-164, 1992, pages 153-185.\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Output, complex A(N,N), the smoke matrix.\n%\n angle = 2.0 * pi / n;\n w = complex ( cos ( angle ), sin ( angle ) );\n\n for i = 1 : n\n for j = 1 : n\n if ( j + 1 == i )\n a(i,j) = 1.0;\n elseif ( i == n & j == 1 )\n a(i,j) = 1.0;\n elseif ( i == j )\n a(i,j) = w^i;\n else\n a(i,j) = 0.0;\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/test_mat/smoke.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542185, "lm_q2_score": 0.8757869981319863, "lm_q1q2_score": 0.8121727186303678}} {"text": "function genotypeFactor = genotypeGivenAlleleFreqsFactor(alleleFreqs, genotypeVar)\n% This function computes the probability of each genotype given the allele \n% frequencies in the population.\n\n% Note that we assume that the copies of the gene are independent. Thus,\n% knowing the allele for one copy of the gene does not affect the\n% probability of having each allele for the other copy of the gene. As a\n% result, the probability of a genotype is the product of the frequencies \n% of its constituent alleles (or twice that product for heterozygous \n% genotypes).\n\n% Input:\n% alleleFreqs: An n x 1 vector of the frequencies of the alleles in the \n% population, where n is the number of alleles\n% genotypeVar: The variable number for the genotype (goes in the .var\n% part of the factor)\n%\n% Output:\n% genotypeFactor: Factor in which the val has the probability of having \n% each genotype (note that this is the FULL CPD with no evidence \n% observed)\n\n% The number of genotypes is (number of alleles choose 2) + number of \n% alleles -- need to add number of alleles at the end to account for \n% homozygotes\n\ngenotypeFactor = struct('var', [], 'card', [], 'val', []);\nnumAlleles = length(alleleFreqs);\n\n% Each allele has an ID that is the index of its allele frequency in the \n% allele frequency list. Each genotype also has an ID. We need allele and\n% genotype IDs so that we know what genotype and alleles correspond to each\n% probability in the .val part of the factor. For example, the first entry\n% in .val corresponds to the probability of having the genotype with\n% genotype ID 1, which consists of having two copies of the allele with\n% allele ID 1. There is a mapping from a pair of allele IDs to genotype \n% IDs and from genotype IDs to a pair of allele IDs below; we compute this \n% mapping using generateAlleleGenotypeMappers(numAlleles). (A genotype \n% consists of 2 alleles.)\n\n[allelesToGenotypes, genotypesToAlleles] = generateAlleleGenotypeMappers(numAlleles);\n\n% One or both of these matrices might be useful.\n%\n% 1. allelesToGenotypes: n x n matrix that maps pairs of allele IDs to \n% genotype IDs, where n is the number of alleles -- if \n% allelesToGenotypes(i, j) = k, then the genotype with ID k comprises of \n% the alleles with IDs i and j\n%\n% 2. genotypesToAlleles: m x 2 matrix of allele IDs, where m is the \n% number of genotypes -- if genotypesToAlleles(k, :) = [i, j], then the \n% genotype with ID k is comprised of the allele with ID i and the allele \n% with ID j\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%INSERT YOUR CODE HERE\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% Fill in genotypeFactor.var. This should be a 1-D row vector.\n% Fill in genotypeFactor.card. This should be a 1-D row vector.\nm=size(genotypesToAlleles,1);\ngenotypeFactor.var = [genotypeVar] ;\ngenotypeFactor.card = [m];\ngenotypeFactor.val = zeros(1, prod(genotypeFactor.card));\n% Replace the zeros in genotypeFactor.val with the correct values.\n\nfor i=1:m\n\tk = genotypesToAlleles(i,:);\n\tgenotypeFactor.val(i) = alleleFreqs(k(1))*alleleFreqs(k(2));\n\tif k(1)!=k(2)\n\t\tgenotypeFactor.val(i)*=2;\n\tend\nend\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \n", "meta": {"author": "anhncs", "repo": "Probabilistic-Graphical-Models", "sha": "7fd4ef255db59ecbfe1a134cadbc4be5ca839894", "save_path": "github-repos/MATLAB/anhncs-Probabilistic-Graphical-Models", "path": "github-repos/MATLAB/anhncs-Probabilistic-Graphical-Models/Probabilistic-Graphical-Models-7fd4ef255db59ecbfe1a134cadbc4be5ca839894/2.Bayesian Network for Genetic Inheritance/genotypeGivenAlleleFreqsFactor.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167045, "lm_q2_score": 0.8757869900269367, "lm_q1q2_score": 0.8121727023233181}} {"text": "function area = sphere01_area ( )\n\n%*****************************************************************************80\n%\n%% SPHERE01_AREA returns the area of the unit sphere.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 02 January 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Output, real AREA, the area of the unit sphere.\n%\n r = 1.0;\n area = 4.0 * pi * r * r;\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_monte_carlo/sphere01_area.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.8976952832120991, "lm_q1q2_score": 0.8121005183153709}} {"text": "function alpha = sphericalAngle(p1, p2, p3)\n%SPHERICALANGLE Compute angle between points on the sphere.\n%\n% ALPHA = sphericalAngle(P1, P2, P3)\n% Computes angle (P1, P2, P3), i.e. the angle, measured at point P2,\n% between the direction (P2, P1) and the direction (P2, P3).\n% The result is given in radians, between 0 and 2*PI.\n%\n% Points are given either as [x y z] (there will be normalized to lie on\n% the unit sphere), or as [phi theta], with phi being the longitude in [0\n% 2*PI] and theta being the elevation on horizontal [-pi/2 pi/2].\n%\n%\n% NOTE: \n% this is an 'oriented' version of the angle computation, that is, the\n% result of sphericalAngle(P1, P2, P3) equals\n% 2*pi-sphericalAngle(P3,P2,P1). To have the more classical relation\n% (with results given betwen 0 and PI), it suffices to take the minimum\n% of angle and 2*pi-angle.\n% \n% Examples\n% % Use inputs as cartesian coordinates \n% p1 = [0 1 0];\n% p2 = [1 0 0];\n% p3 = [0 0 1];\n% alpha = sphericalAngle(p1, p2, p3)\n% alpha =\n% 1.5708\n%\n% % Use inputs as spherical coordinates \n% sph1 = [.1 0];\n% sph2 = [0 0];\n% sph3 = [0 .1];\n% alphas = sphericalAngle(sph1, sph2, sph3)\n% alphas =\n% 1.5708\n% \n%\n% See also:\n% geom3d, angles3d, spheres, sph2cart\n\n% ---------\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 21/02/2005.\n%\n\n% HISTORY\n% 23-05-2006 fix bug for points with angle from center > pi/2\n% 05-06-2013 fix bug for points given as spherical coordinates, better\n% support for multiple inputs\n\n% test if points are given as matlab spherical coordinates\nif size(p1, 2) == 2\n [x, y, z] = sph2cart(p1(:,1), p1(:,2), ones(size(p1,1), 1));\n p1 = [x y z];\n [x, y, z] = sph2cart(p2(:,1), p2(:,2), ones(size(p2,1), 1));\n p2 = [x y z];\n [x, y, z] = sph2cart(p3(:,1), p3(:,2), ones(size(p3,1), 1));\n p3 = [x y z];\nend\n\n% normalize points\np1 = normalizeVector3d(p1);\np2 = normalizeVector3d(p2);\np3 = normalizeVector3d(p3);\n\n% create the plane tangent to the unit sphere and containing central point\nplane = createPlane(p2, p2);\n\n% project the two other points on the plane\npp1 = planePosition(projPointOnPlane(p1, plane), plane);\npp3 = planePosition(projPointOnPlane(p3, plane), plane);\n\n% compute angle on the tangent plane\npp2 = zeros(max(size(pp1, 1), size(pp3,1)), 2);\nalpha = angle3Points(pp1, pp2, pp3);\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/z_geom3d/geom3d/sphericalAngle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218412907381, "lm_q2_score": 0.8807970670261976, "lm_q1q2_score": 0.8120260538362738}} {"text": "function value = r8vec_norm_l0 ( n, a )\n\n%*****************************************************************************80\n%\n%% R8VEC_NORM_L0 returns the l0 \"norm\" of an R8VEC.\n%\n% Discussion:\n%\n% An R8VEC is a vector of R8's.\n%\n% The l0 \"norm\" simply counts the number of nonzero entries in the vector.\n% It is not a true norm, but has some similarities to one. It is useful\n% in the study of compressive sensing.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 January 2015\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of entries in the vector.\n%\n% Input, real A(N), the vector.\n%\n% Output, real R8VEC_NORM_L0, the value of the norm.\n%\n value = sum ( a(1:n) ~= 0.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/r8lib/r8vec_norm_l0.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.9059898254600902, "lm_q1q2_score": 0.8119946301349883}} {"text": "function matrixOut = smooth2a(matrixIn,Nr,Nc)\n% Smooths 2D array data. Ignores NaN's.\n%\n%function matrixOut = smooth2a(matrixIn,Nr,Nc)\n% \n% This function smooths the data in matrixIn using a mean filter over a\n% rectangle of size (2*Nr+1)-by-(2*Nc+1). Basically, you end up replacing\n% element \"i\" by the mean of the rectange centered on \"i\". Any NaN\n% elements are ignored in the averaging. If element \"i\" is a NaN, then it\n% will be preserved as NaN in the output. At the edges of the matrix,\n% where you cannot build a full rectangle, as much of the rectangle that\n% fits on your matrix is used (similar to the default on Matlab's builtin\n% function \"smooth\").\n% \n% \"matrixIn\": original matrix\n% \"Nr\": number of points used to smooth rows\n% \"Nc\": number of points to smooth columns. If not specified, Nc = Nr.\n% \n% \"matrixOut\": smoothed version of original matrix\n% \n% \n% \tWritten by Greg Reeves, March 2009.\n% \tDivision of Biology\n% \tCaltech\n% \n% \tInspired by \"smooth2\", written by Kelly Hilands, October 2004\n% \tApplied Research Laboratory\n% \tPenn State University\n% \n% \tDeveloped from code written by Olof Liungman, 1997\n% \tDept. of Oceanography, Earth Sciences Centre\n% \tGďż˝teborg University, Sweden\n% \tE-mail: olof.liungman@oce.gu.se\n\n%\n% Initial error statements and definitions\n%\nif nargin < 2, error('Not enough input arguments!'), end\n\nN(1) = Nr; \nif nargin < 3, N(2) = N(1); else N(2) = Nc; end\n\nif length(N(1)) ~= 1, error('Nr must be a scalar!'), end\nif length(N(2)) ~= 1, error('Nc must be a scalar!'), end\n\n%\n% Building matrices that will compute running sums. The left-matrix, eL,\n% smooths along the rows. The right-matrix, eR, smooths along the\n% columns. You end up replacing element \"i\" by the mean of a (2*Nr+1)-by- \n% (2*Nc+1) rectangle centered on element \"i\".\n%\n[row,col] = size(matrixIn);\neL = spdiags(ones(row,2*N(1)+1),(-N(1):N(1)),row,row);\neR = spdiags(ones(col,2*N(2)+1),(-N(2):N(2)),col,col);\n\n%\n% Setting all \"NaN\" elements of \"matrixIn\" to zero so that these will not\n% affect the summation. (If this isn't done, any sum that includes a NaN\n% will also become NaN.)\n%\nA = isnan(matrixIn);\nmatrixIn(A) = 0;\n\n%\n% For each element, we have to count how many non-NaN elements went into\n% the sums. This is so we can divide by that number to get a mean. We use\n% the same matrices to do this (ie, \"eL\" and \"eR\").\n%\nnrmlize = eL*(~A)*eR;\nnrmlize(A) = NaN;\n\n%\n% Actually taking the mean.\n%\nmatrixOut = eL*matrixIn*eR;\nmatrixOut = matrixOut./nrmlize;\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/23287-smooth2a/smooth2a.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.8119726196989764}} {"text": "function y = Evaluate_FT(x,shift,boxlen,center,w)\n% Evaluate_FT -- 1d unequispaced Fourier transform followed by windowing\n% Usage:\n% y = Evaluate_FT(x,shift,boxlen,center,w)\n% Inputs:\n% x\t vector of length n\n% shift vector of shifts\n% boxlen half length of interval around each shift\n% center boolean variable: 0/1 = unbiased/biased FT\n% w tapering window of size 2*boxlen\n% Outputs:\n% y vector of length: (# shifts) * (2*boxlen)\n% Description:\n% Evaluates the FT at the frequency points \n% omega(j,k) = shift(j) + k, -boxlen <= k =0 is the sum of all\n% a1...an. Most multivariate polynomials will contain terms of\n% different powers. This function adds an extra variable so\n% that all of the terms have the same power. That is for each\n% polynomial f(x1,x2,...,xn), the homogenized polynomial is\n% x0^d*f(x1/x0,x2/x0,...,xn/x0), where d is the highest degree\n% of any monomial term in the polynomial.\n%\n%INPUTS: termMats Either a single term matrix of a cell array containing\n% multiple term matrices. Each term matrix is An (n+1)XnumTerms\n% matrix such that termMat(:,i)=[c,a1,a2,...,an] is a monomial\n% term where c is the value of of the monomial coefficient and\n% the monomial is x1^(a1-1)*x2^(a2-1)*x3^(a3-1)...xn^(an-1). The\n% number of variables and the maximum degree need not be the same\n% for each term matrix. Differing numbers of variables implies\n% that the missing coefficients all have zero exponents.\n% makeProjTransform An optional boolean variable indicating whether the\n% final output system should be a projective transformation of\n% the input system. In such an instance, a cell array must be\n% returned as termMats is expanded by one equation, which is a\n% linear function consisting of random complex numbers times each\n% of the variables. As noted in Section 8 of [1], for a system of\n% n simultaneous polynomial equations in n unknowns, the\n% homogenized system/ projective transform system has a number of\n% solutions exactly equal to the B�zout bound and has no\n% solutions at infinity. If omitted or an empty matrix is passed,\n% the default is false.\n%\n%OUTPUTS: termMats The homogenized equations. If a sinle term matrix is\n% passed, then this is a matrix. otherwise, this is a cell array\n% of term matrices like the input. All of the term matrices now\n% contain the same number of variables (with zeros for unused\n% variables) with one more variable than the equation with the\n% most variables on the input. This new variable is the\n% homogenizing variable.\n% alreadyHomogenized A boolean value indicating that the input system was\n% already homogenized. In such an instance, all exponents of\n% the added homogenization variable in the retunred system are\n% zero.\n%\n%Homogenization of multivariate polynomial systems is often used in\n%multivariate polynomial solving algorithms to better handle \"solutions at\n%infinite\", which are generally not solutions that one cares about. For\n%example, an application of homogenizing multivariate polynomials is in\n%Section 8 of [1].\n%\n%EXAMPLE:\n%Consider four equations in four unknowns.\n% termMats=cell(4,1);\n% termMats{1}=string2Terms('x1*x3-2*x2*x3-6*x1-x2-4*x4+12');\n% termMats{2}=string2Terms('x1*x3-3*x2*x3-7*x1+12');\n% termMats{3}=string2Terms('x1*x4^3-2*x1*x2-6*x4-x2+12');\n% termMats{4}=string2Terms('x1^2+x2^2+x3^2+x4^2-6');\n% [termMats1,alreadyHomogenized]=homogenizeMultiDimPolys(termMats)\n% %The new system will correspond to\n% %'x1*x3-2*x2*x3-6*x1*x5-x2*x5-4*x4*x5+12*x5^2'\n% %'x2*x3-3*x3*x4-7*x1*x5+12*x5^2'\n% %'x1*x4^3-2*x1*x2*x5^2-6*x4*x5^3-1*x2*x5^3+12*x5^4'\n% %'x1^2+x2^2+x3^2+x4^2-6*x5^2'\n% %The projective transformed solution is\n% [termMats2,alreadyHomogenized]=homogenizeMultiDimPolys(termMats,true)\n% %It is the same as the above solution except an extra equation consisting\n% %of \n% % 'c1*x1+c2*x2+c3*x3+c4*x4+c5*x5'\n% %has been added, where c1...c5 are random complex numbers (with both\n% %components between 0 and 1).\n%\n%REFERENCES:\n%[1] L. T. Watson, S. C. Billups, and A. P. Morgan, \"Algorithm 652 HOMPACK:\n% A suit of codes for globally convergent homotopy algorithms,\" ACM\n% Transactions on Mathematical Software, vol. 13, no. 3, pp. 281-310,\n% Sep. 1987.\n%\n%March 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<2||isempty(makeProjTransform))\n makeProjTransform=false; \nend\n\nisCell=true;\n%If only a single matrix is passed.\nif(~isa(termMats,'cell'))\n isCell=false;\n termMats={termMats};%Put it in a cell array.\nend\n\nnumPoly=length(termMats);\n\n%Determine the maximum number of variables.\nn=0;\nfor curPoly=1:numPoly\n n=max([n,size(termMats{curPoly},1)-1]);\nend\n\nalreadyHomogenized=false;\nfor curPoly=1:numPoly\n termMat=termMats{curPoly}; \n \n %The degrees of the terms.\n dTerms=sum(termMat(2:end,:),1);\n \n %The total degree of the polynomial.\n d=max(dTerms);\n \n numTerms=size(termMat,2);\n \n nCur=size(termMats,1)-1;\n \n %Augment to make have the same number of variables as the equation with\n %the most variables, plus one extra for the homogenization.\n termMat=[termMat;zeros(n-nCur,numTerms)];\n \n for i=1:numTerms\n %The degree of the term.\n deg=dTerms(i);\n \n %The homogenization makes all terms of degree d\n diff=d-deg;\n termMat(end,i)=diff;\n alreadyHomogenized=alreadyHomogenized||(d-deg~=0);\n end\n \n termMats{curPoly}=termMat;\nend\nalreadyHomogenized=~alreadyHomogenized;\n\n%If only a single equation was passed as a matrix, not a cell array, then\n%return a matrix.\nif(isCell==false&&makeProjTransform==false)\n termMats=termMats{1}; \n return;\nend\n\nif(makeProjTransform)\n termMat=zeros(n+2,n+1);\n \n termMat(1,:)=rand(1,n+1)+1j*rand(1,n+1);\n termMat(2:end,:)=eye(n+1,n+1);\n \n termMats{end+1}=termMat;\nend\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/homogenizeMultiDimPolys.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.894789454880027, "lm_q1q2_score": 0.8118534146850338}} {"text": "function [en,U,lam] = kentropy(X, A1, A2, A3, A4)\n% Quadratic Renyi Entropy for a kernel based estimator\n% \n% Given the eigenvectors and the eigenvalues of the kernel matrix, the entropy is computed by\n% \n% >> H = kentropy(X, U, lam)\n% \n% The eigenvalue decomposition can also be computed (or\n% approximated) implicitly:\n% \n% >> H = kentropy(X, kernel, sig2)\n% \n%\n% Full syntax\n% \n% >> H = kentropy(X, kernel, kernel_par)\n% >> H = kentropy(X, kernel, kernel_par, type)\n% >> H = kentropy(X, kernel, kernel_par, type, nb)\n% \n% Outputs \n% H : Quadratic Renyi entropy of the kernel matrix\n% Inputs \n% X : N x d matrix with the training data\n% kernel : Kernel type (e.g. 'RBF_kernel')\n% kernel_par : Kernel parameter (bandwidth in the case of the 'RBF_kernel')\n% type(*) : 'eig'(*), 'eigs', 'eign'\n% nb(*) : Number of eigenvalues/eigenvectors used in the eigenvalue decomposition approximation\n% \n%\n% >> H = kentropy(X, U, lam)\n% \n% Outputs \n% H : Quadratic Renyi entropy of the kernel matrix\n% Inputs \n% X : N x d matrix with the training data\n% U : N x nb matrix with principal eigenvectors\n% lam : nb x 1 vector with eigenvalues of principal components\n% \n% See also:\n% kernel_matrix, RBF_kernel, demo_fixedsize\n\n% Copyright (c) 2011, KULeuven-ESAT-SCD, License & help @ http://www.esat.kuleuven.be/sista/lssvmlab\n\nn= size(X,1);\n\nif isstr(A1), % kernel_matrix\n\n kernel = A1;\n kernel_par = A2;\n eval('etype = A3;','etype =''eig'';');\n if ~(strcmp(etype, 'eig') |strcmp(etype, 'eigs') |strcmp(etype,'eign')),\n error('type has to be ''eig'', ''eigs'' or ''eign''...');\n end\n eval('nb = A4;',' ');\n \n if strcmp(etype,'eign'),\n eval('[U,lam] = eign(X,kernel,kernel_par,nb);','[U,lam] = eign(X,kernel,kernel_par);');\n else\n omega = kernel_matrix(X, kernel, kernel_par);\n eval('[U,lam] = feval(etype,omega,nb);','[U,lam] = feval(etype,omega);');\n if size(lam,1)==size(lam,2), lam = diag(lam); end\n %onen = ones(n,1)./n; en = -log(onen'*omega*onen);\n end\n \n\nelse\n U = A1;\n lam = A2;\nend \nen = -log((sum(U,1)/n).^2 * lam);\n ", "meta": {"author": "peterhcharlton", "repo": "RRest", "sha": "f5022e7029c5b6d6b8159b665dccc2c8f267976e", "save_path": "github-repos/MATLAB/peterhcharlton-RRest", "path": "github-repos/MATLAB/peterhcharlton-RRest/RRest-f5022e7029c5b6d6b8159b665dccc2c8f267976e/RRest_v3.0/Algorithms/extract_resp_sig/feat_based_extraction/LSSVMlabv1_8_R2009b_R2011a/kentropy.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678382, "lm_q2_score": 0.8688267830311354, "lm_q1q2_score": 0.8118275447375578}} {"text": "function s = ellipsoidSurfaceArea(elli)\n%ELLIPSOIDSURFACEAREA Approximated surface area of an ellipsoid.\n%\n% S = ellipsoidSurfaceArea(ELLI)\n% Computes an approximation of the surface area of an ellipsoid. \n% ELLI is a 1-by-9 row vector given by [XC YC ZC A B C THETA PHI PSI],\n% where (XC YC ZC) is the center, (A B C) is the length of each semi axis\n% and (THETA PHI PSI) representes the orientation.\n% If ELLI is a 1-by-3 row vector, it is assumed to contain only the\n% lengths of semi-axes.\n%\n% This functions computes an approximation of the surface area, given by:\n% S = 4 * pi * ( (a^p * b^p + a^p * c^p + b^p * c^p) / 3) ^ (1/p)\n% with p = 1.6075. The resulting error should be less than 1.061%.\n%\n% Example\n% ellipsoidSurfaceArea\n%\n% See also \n% geom3d, ellipsePerimeter, oblateSurfaceArea, prolateSurfaceArea\n%\n% References\n% * http://en.wikipedia.org/wiki/Ellipsoid\n% * http://mathworld.wolfram.com/Ellipsoid.html\n%\n\n% ------\n% Author: David Legland\n% E-mail: david.legland@grignon.inra.fr\n% Created: 2012-02-24, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2012-2022 INRA - Cepia Software Platform\n\n%% Parse input argument\n\nif size(elli, 2) == 9\n a = elli(:, 4);\n b = elli(:, 5);\n c = elli(:, 6);\n \nelseif size(elli, 2) == 3\n a = elli(:, 1);\n b = elli(:, 2);\n c = elli(:, 3); \nend\n\np = 1.6075;\ns = 4 * pi * ( (a.^p .* b.^p + a.^p .* c.^p + b.^p .* c.^p) / 3) .^ (1 / p);\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/ellipsoidSurfaceArea.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480347, "lm_q2_score": 0.8670357563664174, "lm_q1q2_score": 0.8117925781332828}} {"text": "% Euclidean projection on the nonnegative orthant\n% Section 8.1.1, Boyd & Vandenberghe \"Convex Optimization\"\n% Joelle Skaf - 10/07/05\n%\n% The projection of x0 on the proper cone K = R+^n is given by\n% minimize || x - x0 ||^2\n% s.t. x >= 0\n% It is also given by: P_K(x0)_k = max{x0_k,0}\n\n% Input data\nrandn('seed',0);\nn = 10;\nx0 = randn(n,1);\n\nfprintf(1,'Computing the analytical solution...');\n\n% Analytical solution\npk_x0 = max(x0,0);\n\nfprintf(1,'Done! \\n');\n\n% Solution via CVX\nfprintf(1,'Computing the solution via a QP...');\n\ncvx_begin quiet\n variable x(n)\n minimize ( norm(x - x0) )\n x >= 0; %#ok\ncvx_end\n\nfprintf(1,'Done! \\n');\n\n% Verification\ndisp('-----------------------------------------------------------------');\ndisp('Verifying that the analytical solution and the solution obtained via QP are equal: ');\ndisp([pk_x0 x])\ndisp('They should be equal!');\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/cvxbook/Ch08_geometric_probs/eucl_proj_cone1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.867035752930664, "lm_q1q2_score": 0.8117925764579146}} {"text": "function quad = fibonacci_lattice_q2 ( k, f )\n\n%*****************************************************************************80\n%\n%% FIBONACCI_LATTICE_Q2 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^3 *( 10 - 15 * X + 6 * X^2 )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 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) = ( 10.0 - 15.0 * x(i) + 6.0 * x(i)^2 ) * x(i)^3;\n dphi = dphi * 30.0 * ( 1.0 - x(i) )^2 * x(i)^2;\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_q2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.8670357546485407, "lm_q1q2_score": 0.8117925749833842}} {"text": "classdef Quadrature_Quadrilateral < Quadrature\n\n methods (Access = public)\n function computeQuadrature(obj,order)\n computeQuadrature@Quadrature(obj,order);\n switch order\n case 'CONSTANT'\n obj.ngaus = 1;\n obj.posgp(:,1) = [0,0];\n obj.weigp = 4;\n \n case 'LINEAR'\n obj.ngaus = 4;\n % Compute WEIGP and POSGP\n a = 0.577350269189626;\n obj.posgp(:,1) = [-a,-a];\n obj.posgp(:,2) = [+a,-a];\n obj.posgp(:,3) = [-a,+a];\n obj.posgp(:,4) = [+a,+a];\n \n obj.weigp = [1,1,1,1];%1*ones(1,obj.ngaus);\n\n case 'QUADRATIC' %SERENDIPITY, QUADRILATERAL QUADRATIC NOT IMPLEMENTED\n % Copied from down below\n obj.ngaus = 9;\n % Compute WEIGP and POSGP\n a = 0.77459667;\n obj.posgp(:,1) = [ 0,+a];\n obj.posgp(:,2) = [ 0, 0];\n obj.posgp(:,3) = [+a,+a];\n obj.posgp(:,4) = [-a,-a];\n obj.posgp(:,5) = [-a, 0];\n obj.posgp(:,6) = [+a, 0];\n obj.posgp(:,7) = [+a,-a];\n obj.posgp(:,8) = [-a,+a];\n obj.posgp(:,9) = [ 0,-a];\n \n obj.weigp =(4/9)*ones(1,obj.ngaus);\n\n case 'QUADRATICMSS' %SERENDIPITY, QUADRILATERAL QUADRATIC NOT IMPLEMENTED\n obj.ngaus = 9;\n % Compute WEIGP and POSGP\n a = 0.77459667;\n obj.posgp(:,1) = [ 0,+a];\n obj.posgp(:,2) = [ 0, 0];\n obj.posgp(:,3) = [+a,+a];\n obj.posgp(:,4) = [-a,-a];\n obj.posgp(:,5) = [-a, 0];\n obj.posgp(:,6) = [+a, 0];\n obj.posgp(:,7) = [+a,-a];\n obj.posgp(:,8) = [-a,+a];\n obj.posgp(:,9) = [ 0,-a];\n \n obj.weigp =(4/9)*ones(1,obj.ngaus);\n \n case 'QUADRATICMASS'\n posgl(1) =-0.774596669241483;\n posgl(2) = 0.0;\n posgl(3) = 0.774596669241483;\n weigl(1) = 0.555555555555556;\n weigl(2) = 0.888888888888889;\n weigl(3) = 0.555555555555556;\n obj.ngaus = 9;\n igaus = 0;\n nlocs = 3;\n for ilocs = 1:nlocs\n for jlocs = 1:nlocs\n igaus = igaus+1;\n obj.weigp( igaus) = weigl(ilocs)*weigl(jlocs);\n obj.posgp(1,igaus) = posgl(ilocs);\n obj.posgp(2,igaus) = posgl(jlocs);\n end\n end\n \n otherwise\n error('Invalid interpolation order for element Quadrilateral.');\n end\n end\n end\nend", "meta": {"author": "SwanLab", "repo": "Swan", "sha": "f8355f3561bb1a1603f56b3676873147d22a511e", "save_path": "github-repos/MATLAB/SwanLab-Swan", "path": "github-repos/MATLAB/SwanLab-Swan/Swan-f8355f3561bb1a1603f56b3676873147d22a511e/FEM/Quadrature/Quadrature_Quadrilateral.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9643214511730025, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.8117905374457854}} {"text": "function [VIn,MIn] = partition_distance(Cx,Cy)\n%PARTITION_DISTANCE Distance between community partitions\n%\n% This function quantifies the distance between pairs of community\n% partitions with information theoretic measures.\n%\n% VIn = partition_distance(Cx,Cy)\n% [VIn MIn] = partition_distance(Cx,Cy)\n%\n% Inputs: Cx, Community affiliation vector X\n% Cy, Community affiliation vector Y\n%\n% Outputs: VIn, Normalized variation of information\n% MIn, Normalized mutual information\n%\n% (Definitions:\n% VIn = [H(X) + H(Y) - 2MI(X,Y)]/log(n)\n% MIn = 2MI(X,Y)/[H(X)+H(Y)]\n% where H is entropy, MI is mutual information and n is number of nodes)\n%\n% Reference: Meila M (2007) J Multivar Anal 98, 873-895.\n%\n% 2011, Mika Rubinov, UNSW\n\n% Modification History:\n% Mar 2011: Original\n\n%#ok<*ASGLU>\n\nn = numel(Cx); %n\n\n[dum,dum,Cx] = unique(Cx);\n[dum,dum,Cy] = unique(Cy);\n[dum,dum,Cxy] = unique([Cx(:) Cy(:)],'rows');\n\nPx = hist(Cx,1:max(Cx))/n; %P(x)\nPy = hist(Cy,1:max(Cy))/n; %P(y)\nPxy = hist(Cxy,1:max(Cxy))/n; %P(x,y)\n\nHx = -sum(Px.*log(Px)); %H(x)\nHy = -sum(Py.*log(Py)); %H(y)\nHxy = -sum(Pxy.*log(Pxy)); %H(x,y)\n\nVIn = (2*Hxy-Hx-Hy)/log(n); %VIn\nMIn = 2*(Hx+Hy-Hxy)/(Hx+Hy); %MIn", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/bct/partition_distance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9643214460461698, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.8117905197362593}} {"text": "function result = fit_ML_log_normal( x,hAx )\n% fit_ML_normal - Maximum Likelihood fit of the log-normal distribution of i.i.d. samples!.\n% Given the samples of a log-normal distribution, the PDF parameter is found\n%\n% fits data to the probability of the form: \n% p(x) = sqrt(1/(2*pi))/(s*x)*exp(- (log(x-m)^2)/(2*s^2))\n% with parameters: m,s\n%\n% format: result = fit_ML_log_normal( x,hAx )\n%\n% input: x - vector, samples with log-normal distribution to be parameterized\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% m,s - fitted parameters\n% CRB_m,CRB_s - Cram?r-Rao Bound for the estimator value\n% RMS - RMS error of the estimation \n% type - 'ML'\n%\n\n%\n% Algorithm\n% ===========\n%\n% We use the ML algorithm to estimate the PDF from the samples.\n% The log-normal destribution is given by:\n%\n% p(x;m,s) = sqrt(1/(2*pi))/(s*x)*exp(- (log(x-m)^2)/(2*s^2))\n%\n% where x are the samples which distribute by the function p(x;m,s)\n% and are assumed to be i.i.d !!!\n%\n% The ML estimator is given by:\n%\n% a = parameters vector = [m,s]\n% f(Xn,a) = sqrt(1/(2*pi))/(s*Xn)*exp(- (log(Xn-m)^2)/(2*s^2))\n% L(a) = f(X,a) = product_by_n( f(Xn,a) )\n% = (2*pi*s^2)^(-N/2) * PI{1/Xn} * exp(-sum((log(Xn)-m)^2)/(2*s^2))\n% log(L(a)) = -N/2*log(2*pi) - N*log(s) - sum(log(Xn)) - sum((log(Xn)-m)^2)/(2*s^2)\n%\n% The maximum likelihood point is found by the derivative of log(L(a)) with respect to \"a\":\n%\n% diff(log(L(a)),s^2) = N/(2*s^4) * ( sum( (log(Xn)-m)^2 )/N - s^2 )\n% = J(s^2) * (s^2_estimation - s^2) \n% diff(log(L(a)),m) = 2*N/(s^2) * ( sum(log(Xn))/N - m )\n% = J(m) * (m_estimator - m)\n%\n% Therefore, the (efficient) estimators are given by:\n%\n% m = sum( log( Xn ) )/N\n% s^2 = sum(( log(Xn)-m)^2)/N\n%\n% The Cram?r-Rao Bounds for these estimator are:\n%\n% VAR( m ) = 1/J(m) = (s^2) / N\n% VAR( s^2 ) = 1/J(s^2) = (2*s^4) / N\n%\n% NOTE: the ML estimator does not detect a deviation from the model.\n% therefore, check the RMS value !\n%\n\nif (nargin<1)\n error( 'fit_ML_log_normal - insufficient input arguments' );\nend\n\n% Estimation\n% =============\nlnx = log(x(:)); % should be column vectors !\nN = length(x);\nm = sum( lnx )/N;\ns2 = (lnx-m)'*(lnx-m)/N;\nCRB_m = s2 / N;\nCRB_s2 = (2*s2^2) / N;\n[n,x_c] = hist( x,100 );\nn = n / sum(n*abs(x_c(2)-x_c(1)));\ny = sqrt(1/(2*pi))./(sqrt(s2)*x_c).*exp(- ((log(x_c)-m).^2)/(2*s2));\nRMS = sqrt( (y-n)*((y-n)')/ (x_c(2)-x_c(1))^2 / (length(x_c)-1) );\n\n% finish summarizing results\n% ============================\nresult = struct( 'm',m,'s2',s2,'CRB_m',CRB_m,'CRB_s2',CRB_s2,'RMS',RMS,'type','ML' );\n\n% plot distribution if asked for\n% ===============================\nif (nargin>1)\n xspan = linspace(min(x),max(x),100);\n if ishandle( hAx )\n plot_log_normal( xspan,result,hAx,1 );\n else\n figure;\n plot_log_normal( xspan,result,gca,1 );\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_ML_log_normal.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778012346835, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.8117407039019737}} {"text": "function [X,E0,R0]=totalLeastSquares(A,B,d,t)\n%%TOTALLEASTSQUARES Solve the total least squares problem. That is, given\n% an mXn matrix A and an mXk matrix or vector B, find the an nXk\n% matrix or vector X such that (A+E0)*X=(B+R0), where the error\n% terms E0 and R0 are chosen to minimize the Frobenius norm of\n% D*[E0,R0]*T where D=diag(d) and T=diag(t) are nonsingular\n% diagonal matrices. This problem is essentially just solving\n% A*X=B for X where both A and B can be noisy, whereas the normal\n% least squares problem solves for the case where only B is noisy.\n%\n%INPUTS: A A real mXn matrix.\n% B A real nXk matrix.\n% d Optional mX1 vector of real diagonal elements for the matrix D,\n% which affects how the errors are weighted. If omitted, a vector\n% of ones is used (D is just an identity matrix).\n% t Optional (n+k)X1 vector of real diagonal elements for the matrix\n% T, which affects show errors are weighted. If omitted, a vector\n% of ones is used (T is just an identity matrix).\n%\n%OUTPUTS: X The nXk real solution of the total least squares problem.\n% E0,R0 The error matrices associated with the solution to the problem.\n% They are such that (A+E0)*X=(B+R0) and the Frobenius norm of\n% D*[E0,R0]*T, which is computed via norm(D*[E0,R0]*T,'fro'), is\n% minimized.\n%\n%The algorithm for solving the total least squares problem is taken from\n%Chapter 6.3.1 of [1].\n%\n%REFERENCES:\n%[1] G. H. Golub and C. F. Van Loan, Matrix Computations, 4th ed.\n% Baltimore: Johns Hopkins University Press, 2013.\n%\n%April 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nm=size(A,1);\nn=size(A,2);\nk=size(B,2);\n\nif(nargin<4)\n t=ones(n+k,1);\nend\n\nif(nargin<3)\n d=ones(m,1); \nend\n\nD=diag(d);\nT=diag(t);\n\n[U,Sigma,V]=svd(D*[A,B]*T);\n\nV12=V(1:n,(n+1:end));\nV22=V((n+1):end,(n+1):end);\n\nT1=diag(t(1:n));\nT2=diag(t((n+1):end));\n\nX=-T1*V12/V22/T2;\n\nif(nargout>1)\n U2=U(:,(n+1):end);\n Sigma2=Sigma((n+1):end,(n+1):end);\n\n ERMat=-D\\(U2*Sigma2*[V12',V22'])/T;\n\n E0=ERMat(:,1:n);\n R0=ERMat(:,(n+1):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/Basic_Matrix_Operations/totalLeastSquares.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.938124016006303, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.8116874894624186}} {"text": "function [Xsol, Ssol] = generalized_eigenvalue_computation(A, B, p)\n% Returns orthonormal basis of the dominant invariant p-subspace of B^-1 A.\n%\n% function [Xsol, Ssol] = generalized_eigenvalue_computation(A, B, p)\n%\n% Input: A is a real, symmetric matrix of size nxn,\n% B is a symmetric positive definite matrix, same size as A, and\n% an integer p < n.\n% Output: Xsol: a real, orthonormal matrix X of size nxp such that\n% trace(X'*A*X) is maximized, subject to X'*B*X being identity. \n% That is, the columns of X form an orthonormal basis of a dominant\n% subspace of dimension p of B^(-1)*A. These are thus eigenvectors\n% associated with the largest eigenvalues of B^(-1)*A (in no\n% particular order). Sign is important: 2 is deemed a larger\n% eigenvalue than -5.\n% Ssol: the eigenvalues associated with the eigenvectors Xsol.\n% \n% We intend to solve the homogeneous system A*X = B*X*S,\n% where S is a diagonal matrix of dominant eigenvalues of B^-1 A.\n%\n%\n% The optimization is performed on the generalized Grassmann manifold, \n% since only the space spanned by the columns of X matters. \n%\n% The optimization problem that we are solving here is \n% maximize trace(X'*A*X) subject to X'*B*X = eye(p). \n% Consequently, the solutions remain invariant to transformation\n% X --> XO, where O is a p-by-p orthogonal matrix. The search space, in\n% essence, is set of equivalence classes\n% [X] = {XO : X'*B*X = I and O is orthogonal matrix}. This space is called\n% the generalized Grassmann manifold.\n%\n% See also dominant_invariant_subspace nonlinear_eigenspace\n\n\n% This file is part of Manopt and is copyrighted. See the license file.\n%\n% Main author: Bamdev Mishra, June 30, 2015.\n% Contributors:\n% Change log:\n \n % Generate some random data to test the function\n if ~exist('A', 'var') || isempty(A)\n n = 128;\n A = randn(n);\n A = (A+A')/2;\n end\n if ~exist('B', 'var') || isempty(B)\n n = size(A, 1);\n e = ones(n, 1);\n B = spdiags([-e 2*e -e], -1:1, n, n); % Symmetric positive definite\n end\n \n if ~exist('p', 'var') || isempty(p)\n p = 3;\n end\n \n % Make sure the input matrix is square and symmetric\n n = size(A, 1);\n\tassert(isreal(A), 'A must be real.')\n assert(size(A, 2) == n, 'A must be square.');\n assert(norm(A-A', 'fro') < n*eps, 'A must be symmetric.');\n\tassert(p <= n, 'p must be smaller than n.');\n \n % Define the cost and its derivatives on the generalized \n % Grassmann manifold, i.e., the column space of all X such that\n % X'*B*X is identity. \n gGr = grassmanngeneralizedfactory(n, p, B);\n \n problem.M = gGr;\n problem.cost = @(X) -trace(X'*A*X);\n problem.egrad = @(X) -2*(A*X); % Only Euclidean gradient needed.\n problem.ehess = @(X, H) -2*(A*H); % Only Euclidean Hessian needed.\n \n % Execute some checks on the derivatives for early debugging.\n % These things can be commented out of course.\n % checkgradient(problem);\n % pause;\n % checkhessian(problem);\n % pause;\n \n % Issue a call to a solver. A random initial guess will be chosen and\n % default options are selected except for the ones we specify here.\n options.Delta_bar = 8*sqrt(p);\n [Xsol, costXsol, info] = trustregions(problem, [], options); %#ok\n \n % To extract the eigenvalues, solve the small p-by-p symmetric \n % eigenvalue problem.\n Ssol = eig(Xsol'*(A*Xsol));\n \nend\n", "meta": {"author": "MIT-SPARK", "repo": "GlobalOptimizationTutorial", "sha": "ae1e947a846ca9199d9a3579409d73f4f7fa4ccf", "save_path": "github-repos/MATLAB/MIT-SPARK-GlobalOptimizationTutorial", "path": "github-repos/MATLAB/MIT-SPARK-GlobalOptimizationTutorial/GlobalOptimizationTutorial-ae1e947a846ca9199d9a3579409d73f4f7fa4ccf/SE-Sync/manopt/examples/generalized_eigenvalue_computation.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661945, "lm_q2_score": 0.8652240773641088, "lm_q1q2_score": 0.8116874891957474}} {"text": "function cdf = beta_cdf ( x, a, b )\n\n%*****************************************************************************80\n%\n%% BETA_CDF evaluates the Beta CDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the CDF.\n%\n% Input, real A, B, the parameters of the PDF.\n% 0.0D+00 < A,\n% 0.0D+00 < B.\n%\n% Output, real CDF, the value of the CDF.\n%\n if ( x <= 0.0 )\n cdf = 0.0;\n elseif ( x <= 1.0 )\n cdf = beta_inc ( a, b, x );\n else\n cdf = 1.0;\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/prob/beta_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582574225517, "lm_q2_score": 0.8723473879530491, "lm_q1q2_score": 0.8116828304619088}} {"text": "function value = triangle_orientation_2d ( t )\n\n%*****************************************************************************80\n%\n%% TRIANGLE_ORIENTATION_2D determines the orientation of a triangle in 2D.\n%\n% Discussion:\n%\n% Three distinct non-colinear points in the plane define a circle.\n% If the points are visited in the order P1, P2, and then\n% P3, this motion defines a clockwise or counterclockwise\n% rotation along the circle.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 July 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real T(2,3), the triangle vertices.\n%\n% Output, integer VALUE, reports if the three points lie\n% clockwise on the circle that passes through them. The possible\n% return values are:\n% 0, the points are distinct, noncolinear, and lie counterclockwise\n% on their circle.\n% 1, the points are distinct, noncolinear, and lie clockwise\n% on their circle.\n% 2, the points are distinct and colinear.\n% 3, at least two of the points are identical.\n%\n dim_num = 2;\n\n if ( all ( t(1:dim_num,1) == t(1:dim_num,2) ) | ...\n all ( t(1:dim_num,2) == t(1:dim_num,3) ) | ...\n all ( t(1:dim_num,3) == t(1:dim_num,1) ) ) \n value = 3;\n return\n end\n\n det = ( t(1,1) - t(1,3) ) * ( t(2,2) - t(2,3) ) ...\n - ( t(1,2) - t(1,3) ) * ( t(2,1) - t(2,3) );\n\n if ( det == 0.0 )\n value = 2;\n elseif ( det < 0.0 )\n value = 1;\n elseif ( 0.0 < det )\n value = 0;\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/triangle_orientation_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582574225518, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.8116828227421063}} {"text": "function anss = rombquad(f,a,b,m)\n%ROMBQUAD(f,a,b,m) evaluates the integral of f from a to b.\n% f is an inline function or function handle.\n% a is the lower limit of integration.\n% b is the upper limit of integration.\n% m - is the exponent in the relative error. For example m = 10 implies an\n% estimated relative error of 1e-10.\n%\n% Example: \n%\n% f = @(x) x.^2; % Vectoized function handle.\n% rombquad(f,0,2); % The integral from 0 to 2.\n%\n% See also quad, quadl, quadv and gaussquad (on the FEX)\n%\n% Author: Matt Fig\n% Contact: popkenai@yahoo.com\n \nif nargin<3\n error ('Not enough arguments. See help.')\nelseif nargin<4 || floor(m)~=m || m <1\n m = 10;\nend\n\nif isinf(a) || isinf(b)\n error('Infinite limits not allowed.') \nend\n\nh = 2.^((1:m)-1)*(b-a)/2^(m-1); % These are the intervals used.\nk1 = 2.^((m-2):-1:-1)*2+1; % Index into the intervals.\nf1 = feval(f,a:h(1):b); % Function evaluations.\nR = zeros(1,m); % Pre-allocation.\n% Define the starting vector:\nfor ii = 1:m\n\tR(ii) = 0.5*h(ii)*(f1(1)+2*...\n sum(f1(k1(end-ii+1):k1(end-ii+1)-1:end-1)) + f1(end)); \nend\n% Interpolations:\nfor jj = 2:m\n jpower = (4^(jj-1)-1);\n for kk = 1:(m-jj+1)\n R(kk) = R(kk)+(R(kk)-R(kk+1))/jpower;\n end \nend\nanss = R(1);", "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/9626-rombquad/rombquad.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.8723473663814338, "lm_q1q2_score": 0.8116828053437699}} {"text": "% vgg_wedge Wedge product of N-1 N-vectors (generalization of cross product).\n%\n% Y = vgg_wedge(X) Wedge product of columns/rows of X.\n% Y ... double (1,N).\n% X ... double (N,N-1).\n% It is Y = X(:,1) \\wedge X(:,2) \\wedge ... \\wedge X(:,N-1). For N=3,\n% wedge product is the same as cross (vector) product. E.g., for N=4,\n% wedge product of three 4-vectors is in fact computation of a plane in\n% 3-D projective space from 3 points in the plane.\n% The sign is chosen so that for any square matrix X it is: det(X) == wedge(X(:,1:end-1))*X(:,end)\n% Works also dually for\n% Y ... double (N,1).\n% X ... double (N-1,N).\n%\n% Y = vgg_wedge(X_1,X_2,...,X_{N-1}) Wedge product for each (N-1)-tuple of corresponding columns of X_n.\n% X_n ... double (N,K)\n% Y ... double (K,N)\n% Equivalent to\n% for k = 1:K, Y(k,:) = wedge([X_1(:,k) ... X_{N-1}(:,k)]); end\n% E.g.: wedge(X1,X2) is the same as cross(X1,X2)' but faster.\n% Dual form is not available.\n\nfunction Y = vgg_wedge(varargin)\n\nif nargin == 1\n\n X = varargin{1};\n \n [N,Nm1] = size(X);\n if Nm1>N\n Y = vgg_wedge(X')';\n return\n end\n\n switch N\n case 3 % make it faster for special case N==3\n Y = [X(2,1).*X(3,2)-X(3,1).*X(2,2),...\n X(3,1).*X(1,2)-X(1,1).*X(3,2),...\n X(1,1).*X(2,2)-X(2,1).*X(1,2)];\n otherwise\n for n = 1:N\n Y(n) = (-1)^(n+N)*det(X([1:n-1 n+1:N],:));\n end\n end\n\nelse\n \n N = nargin + 1;\n switch N\n case 3 % make it faster for special case N==3\n X1 = varargin{1};\n X2 = varargin{2};\n Y = [(X1(2,:).*X2(3,:)-X1(3,:).*X2(2,:))',...\n (X1(3,:).*X2(1,:)-X1(1,:).*X2(3,:))',...\n (X1(1,:).*X2(2,:)-X1(2,:).*X2(1,:))'];\n otherwise\n for k = 1:size(varargin{1},2)\n for n = 1:N-1\n\tX(:,n) = varargin{n}(:,k);\n end\n Y(k,:) = vgg_wedge(X);\n end\n end\n\nend\n\n \nreturn", "meta": {"author": "jmmanley", "repo": "VGG-Multiple-View-Geometry", "sha": "f114712de03082bb97229eaf2a65981908b64127", "save_path": "github-repos/MATLAB/jmmanley-VGG-Multiple-View-Geometry", "path": "github-repos/MATLAB/jmmanley-VGG-Multiple-View-Geometry/VGG-Multiple-View-Geometry-f114712de03082bb97229eaf2a65981908b64127/vgg_numerics/vgg_wedge.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741254760638, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.8115481988625182}} {"text": "function pdf = beta_pdf(x, a, b)\n% PURPOSE: pdf of the beta(a,b) distribution\n%--------------------------------------------------------------\n% USAGE: pdf = beta_pdf(x,a,b)\n% where: x = vector of components\n% a = beta distribution parameter, a = scalar\n% b = beta distribution parameter b = scalar\n% NOTE: mean[(beta(a,b)] = a/(a+b), variance = ab/((a+b)*(a+b)*(a+b+1))\n%--------------------------------------------------------------\n% RETURNS: pdf at each element of x of the beta(a,b) distribution\n%--------------------------------------------------------------\n% SEE ALSO: beta_d, beta_pdf, beta_inv, beta_rnd\n%--------------------------------------------------------------\n\n% Anders Holtsberg, 18-11-93\n% Copyright (c) Anders Holtsberg\n% documentation modified by LeSage to\n% match the format of the econometrics toolbox\n \n\nif (nargin ~=3)\n error('Wrong # of arguments to beta_pdf');\nend\n\nif any(any((a<=0)|(b<=0)))\n error('Parameter a or b is nonpositive');\nend\n\nI = find((x<0)|(x>1));\n\npdf = x.^(a-1) .* (1-x).^(b-1) ./ beta(a,b);\npdf(I) = 0*I;\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/OldVersions/v2dot0/Auxiliary/beta_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.939913343093499, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.8115132945293346}} {"text": "function y = acoshplus1(x)\n%ACOSHPLUS1 Inverse hyperbolic cosine of argument plus one.\n%\n% ACOSHPLUS1(X) is ACOSH(X+1) calculated in a way that is numerically better\n% when X is close to one.\n%\n% This illustrates the difference\n%\n% x = 2e-15*(0:0.01:1);\n% plot(x, acosh(x+1), 'b-', x, acoshplus1(x), 'r-');\n%\n% See also COSHMINUS1.\n\n% Author: Peter J. Acklam\n% Time-stamp: 2003-10-13 14:54:17 +0200\n% E-mail: pjacklam@online.no\n% URL: http://home.online.no/~pjacklam\n\n % check number of input arguments\n error(nargchk(1, 1, nargin));\n\n y = 2 * asinh(sqrt(x / 2));\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/acoshplus1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8740772236840656, "lm_q1q2_score": 0.8115009833705478}} {"text": "function geometry_test060 ( )\n\n%*****************************************************************************80\n%\n%% TEST060 tests PLANE_IMP_TRIANGLE_INT_3D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 April 2009\n%\n% Author:\n%\n% John Burkardt\n%\n dim_num = 3;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TEST060\\n' );\n fprintf ( 1, ' PLANE_IMP_TRIANGLE_INT_3D finds the\\n' );\n fprintf ( 1, ' intersection points of an implicit plane\\n' );\n fprintf ( 1, ' and a triangle.\\n' );\n \n a = 1.0;\n b = -2.0;\n c = -3.0;\n d = 6.0;\n \n fprintf ( 1, '\\n' );\n fprintf ( 1, ' The implicit plane: A*X + B*Y + C*Z + D = 0.\\n' );\n fprintf ( 1, ' A,B,C,D = %f %f %f %f\\n', a, b, c, d );\n\n for i = 1 : 4\n \n if ( i == 1 )\n t(1:dim_num,1:3) = [ ...\n 3.0, 0.0, -7.0; ...\n 13.0, -4.0, -1.0; ...\n 5.0, 1.0, -2.0 ]';\n elseif ( i == 2 )\n t(1:dim_num,1:3) = [ ...\n 3.0, 0.0, -7.0; ...\n 13.0, -4.0, -1.0; ...\n 9.0, 3.0, 8.0 ]';\n elseif ( i == 3 )\n t(1:dim_num,1:3) = [ ...\n -6.0, 0.0, 0.0; ...\n 0.0, 3.0, 0.0; ...\n 0.0, 0.0, 2.0 ]';\n elseif ( i == 4 )\n t(1:dim_num,1:3) = [ ...\n -4.0, 1.0, 0.0; ...\n 0.0, 6.0, -2.0; ...\n 0.0, 0.0, 1.0 ]';\n end\n \n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Case %d\\n', i );\n\n r8mat_transpose_print ( dim_num, 3, t, ' Triangle vertices:' );\n\n [ num_int, pint ] = plane_imp_triangle_int_3d ( a, b, c, d, t );\n \n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Number of intersection points is %d\\n', num_int );\n\n r8mat_transpose_print ( dim_num, num_int, pint, ' Intersection points:' );\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_test060.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087926320945, "lm_q2_score": 0.8740772253241802, "lm_q1q2_score": 0.8115009814304334}} {"text": "function D = diffmat(n, p)\n%DIFFMAT Trigonometric differentiation matrix.\n% D = DIFFMAT(N) is the matrix that maps function values at N equally-spaced \n% points in [0 2*pi) to values of the derivative of the Fourier interpolant \n% at those points.\n%\n% D = DIFFMAT(N, K) is the same, but for the Kth derivative.\n%\n% See also DIFF.\n\n% Copyright 2017 by The University of Oxford and The Chebfun Developers.\n% See http://www.chebfun.org/ for Chebfun information.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% References for the rectangular differentiation matrices:\n%\n% J.A.C. Weideman and S.C. Reddy, A MATLAB differentiation matrix suite, ACM\n% Transcations on Mathematical Software, Vol. 26, No. 4, Page 465--519, 2000. \n% \n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n% grid spacing:\nh = 2*pi/n;\n\n% sign of entries in a column:\nsgn = (-1).^(1:n-1).';\n\n% indices:\nn1 = floor((n-1)/2);\nn2 = ceil((n-1)/2);\n\n% grid points on [-1 0):\nv = (1:n2)'*h/2;\n\n% For different p:\nif ( p == 0 ) % Zeroth-derivative\n D = eye(n);\nelse\n switch p\n case 1 % 1st-derivative\n \n % Forming the first column by 'flipping trick':\n if ( rem(n, 2) ) % n is odd\n tmp = csc(v);\n col = [0; (pi/2)*sgn.*[tmp; flipud(tmp(1:n1))]];\n else % n is even\n tmp = cot(v);\n col = [0; (pi/2)*sgn.*[tmp; -flipud(tmp(1:n1))]];\n end\n \n % Form the first row:\n row = -col;\n \n case 2 % 2nd-derivative\n \n % Form the first column by 'flipping trick':\n if ( rem(n, 2) ) % n is odd\n tmp = csc(v).*cot(v);\n col = pi^2*[-pi^2/(3*h^2)+1/12; ...\n -0.5*sgn.*[tmp; -flipud(tmp(1:n1))]];\n else % n is even\n tmp = csc(v).^2;\n col = pi^2*[-pi^2/(3*h^2)-1/6; ...\n -0.5*sgn.*[tmp; flipud(tmp(1:n1))]];\n end\n \n % Form the first row:\n row = col;\n \n otherwise % pth-derivative for p >= 3\n \n % Form the first column using FFT:\n n3 = (-n/2)*rem(p+1,2)*ones(rem(n+1,2));\n waveNumber = 1i*[(0:n1) n3 (-n1:-1)];\n col = pi^p*real(ifft(waveNumber.^p.*fft(eye(1,n))));\n \n % Form the first row:\n if ( rem(p,2) ) % p is odd\n col = [0 col(2:n)]';\n row = -col;\n else % p is even\n row = col;\n end\n end\n \n % Form the differentiation matrix which is toeplitz:\n D = toeplitz(col, row);\n \nend\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/diffmat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8791467754256017, "lm_q1q2_score": 0.8114869048893808}} {"text": "function distance = cylinder_point_dist_3d ( p1, p2, r, p )\n\n%*****************************************************************************80\n%\n%% CYLINDER_POINT_DIST_3D determines the distance from a cylinder to a point in 3D.\n%\n% Discussion:\n%\n% We are computing the distance to the SURFACE of the cylinder.\n%\n% The surface of a (right) (finite) cylinder in 3D is defined by an axis,\n% which is the line segment from point P1 to P2, and a radius R. The points\n% on the surface of the cylinder are:\n% * points at a distance R from the line through P1 and P2, and whose nearest\n% point on the line through P1 and P2 is strictly between P1 and P2,\n% PLUS\n% * points at a distance less than or equal to R from the line through P1\n% and P2, whose nearest point on the line through P1 and P2 is either\n% P1 or P2.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 August 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real P1(3), P2(3), the first and last points\n% on the axis line of the cylinder.\n%\n% Input, real R, the radius of the cylinder.\n%\n% Input, real P(3), the point.\n%\n% Output, real DISTANCE, the distance from the point\n% to the cylinder.\n%\n dim_num = 3;\n\n axis(1:dim_num) = p2(1:dim_num) - p1(1:dim_num);\n \n axis_length = r8vec_norm ( dim_num, axis );\n\n if ( axis_length == 0.0 )\n distance = - r8_huge ( );\n return\n end\n\n axis(1:dim_num) = axis(1:dim_num) / axis_length;\n \n p_dot_axis = ( p(1:dim_num) - p1(1:dim_num) ) * axis(1:dim_num)';\n%\n% Case 1: Below bottom cap.\n%\n if ( p_dot_axis <= 0.0 )\n\n distance = disk_point_dist_3d ( p1, r, axis, p );\n%\n% Case 2: between cylinder planes.\n%\n elseif ( p_dot_axis <= axis_length )\n \n p_length = r8vec_norm ( dim_num, p(1:dim_num) - p1(1:dim_num) );\n off_axis_component = sqrt ( p_length.^2 - p_dot_axis.^2 );\n \n distance = abs ( off_axis_component - r );\n \n if ( off_axis_component < r )\n distance = min ( distance, axis_length - p_dot_axis );\n distance = min ( distance, p_dot_axis );\n end\n%\n% Case 3: Above the top cap.\n%\n elseif ( axis_length < p_dot_axis )\n\n distance = disk_point_dist_3d ( p2, r, axis, p );\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/geometry/cylinder_point_dist_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.8791467706759584, "lm_q1q2_score": 0.8114868967828023}} {"text": "% Numerical solution for wave propagation\n\n% Copyright 2001 P. Wesseling\n% This program and its subprograms may be freely used, modified and distributed\n% under the GNU General Public License: http://www.gnu.org/copyleft/gpl.html\n\n% Theory in Section 9.3 of:\n\n% \tP. Wesseling: Principles of Computational Fluid Dynamics\n% \tSpringer, Heidelberg, 2000 ISBN 3-5453-0. XII, 642 pp.\n% See http://ta.twi.tudelft.nl/nw/users/wesseling/cfdbook.html\n\n% Equation (9.34) is solved with the kappa scheme\n% dy/dt + c dy/dx = 0\n% Known exact solution f(x-ct)\n% Boundary conditions using upwind schemes or extrapolation \n% Uniform vertex-centred grid\n% This program generates Figs. 9.6 and 9.7 in the book\n\n% Functions called: exact_solution\n\n\t\t% ...............Input.........................................\nkappa = 0;\t% Parameter of kappa-scheme \nc = 1;\t\t% Velocity \nsigma = 0.7;\t% CFL number\t \nJ = 31;\t\t% Number of grid cells\nbc = 2;\t\t% Governs choice of numerical boundary conditions; see page 350\n\t\t% Enter 1 for boundary conditions using upwind schemes\n\t\t% or 2 for extrapolation using equation (9.36)\nT = 0.4;\t% Final time\n\t\t% ..............End of input...................................\n\nh = 1.0/(J-1);\t\t% Size of grid cells \ndt = sigma*h/c;\t\t% Time step\nn = floor(T/dt);\t% Number of time steps\n\n% \tDefinition of grid numbering \n\t\t\n% x=0 \t\t\t x=1\n% grid |------|------|------|------|\n% 1 2 3 J\n\nx = [0:J-1]'*h;\t\t% Location of grid nodes \n\nsig2 = sigma^2; sig4 = sigma/4; \n\nynew = zeros(J,1); yright = zeros(n+1,1); \nt = 0;\tyright(1) = exact_solution(t,1,c); yold = exact_solution(t,x,c);\nfor i = 1:n, t = t + dt;\n a = 2*yold(1) - yold(2);\t% Extrapolated inflow value\n ynew(1) = exact_solution(t,0,c);\n if bc == 1\n ynew(2) = yold(2) - sigma*(yold(2) - yold(1));\n else\n ynew(2) = yold(2) +sig4*(-1+kappa + (1-3*kappa)*sigma +2*kappa*sig2)*a +...\n sig4*(5-3*kappa+(9*kappa-1)*sigma-6*kappa*sig2)*yold(1)...\n +sig4*(-3+3*kappa -(1+9*kappa)*sigma+6*kappa*sig2)*yold(2)+...\n sig4*(-1-kappa+(1+3*kappa)*sigma-2*kappa*sig2)*yold(3);\n end\n for j = 3:J-1\n ynew(j) = yold(j) +sig4*(-1+kappa + (1-3*kappa)*sigma +2*kappa*sig2)*...\n yold(j-2)+sig4*(5-3*kappa+(9*kappa-1)*sigma-6*kappa*sig2)*yold(j-1)...\n +sig4*(-3+3*kappa -(1+9*kappa)*sigma+6*kappa*sig2)*yold(j)+...\n sig4*(-1-kappa+(1+3*kappa)*sigma-2*kappa*sig2)*yold(j+1);\n end\n if bc == 1\t\t% Fully upwind scheme at outflow\n ynew(J) = (1-1.5*sigma+0.5*sig2)*yold(J) + sigma*(2-sigma)*yold(J-1)...\n +sigma*0.5*(sigma-1)*yold(J-2); \n else\t\t\t% Extrapolation at outflow\n ynew(J) = yold(J) +sig4*(-1+kappa + (1-3*kappa)*sigma +2*kappa*sig2)*...\n yold(J-2)+sig4*(5-3*kappa+(9*kappa-1)*sigma-6*kappa*sig2)*yold(J-1)...\n +sig4*(-3+3*kappa -(1+9*kappa)*sigma+6*kappa*sig2)*yold(J)+... \n sig4*(-1-kappa+(1+3*kappa)*sigma-2*kappa*sig2)*(2*yold(J) - yold(J-1));\n end\n yright(i+1) = ynew(J); yold = ynew;\nend\n\nyexact = exact_solution(t,x,c);\terror = ynew - yexact;\nnorm1 = norm(error,1)/J\t\t\t% Compute error norms\nnorm2 = norm(error,2)/sqrt(J)\nnorminf = norm(error,inf)\n\nfigure(1), clf, hold on\nxx = 0:0.005:1;\tplot (xx,exact_solution(t,xx,c),'-'); plot (x,ynew,'o');\ns1 = ['kappa=',num2str(kappa),' bc =', num2str(bc),' sigma=',...\n\tnum2str(sigma),' cells=',num2str(J-1),' t=',num2str(t)];\ntitle(s1,'fontsize',18);\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/cfdbook/chap9.3/numerical_experiments/kappa_scheme.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039739, "lm_q2_score": 0.8791467643431002, "lm_q1q2_score": 0.811486894659798}} {"text": "% Spectral factorization using Kolmogorov 1939 approach\n% (code follows pp. 232-233, Signal Analysis, by A. Papoulis)\n%\n% Computes the minimum-phase impulse response which satisfies\n% given auto-correlation.\n%\n% Input:\n% r: top-half of the auto-correlation coefficients\n% starts from 0th element to end of the auto-corelation\n% should be passed in as a column vector\n% Output\n% h: impulse response that gives the desired auto-correlation\n\nfunction h = spectral_fact(r)\n\n% length of the impulse response sequence\nnr = length(r);\nn = (nr+1)/2;\n\n% over-sampling factor\nmult_factor = 30; % should have mult_factor*(n) >> n\nm = mult_factor*n;\n\n% computation method:\n% H(exp(jTw)) = alpha(w) + j*phi(w)\n% where alpha(w) = 1/2*ln(R(w)) and phi(w) = Hilbert_trans(alpha(w))\n\n% compute 1/2*ln(R(w))\nw = 2*pi*[0:m-1]/m;\nR = exp( -j*kron(w',[-(n-1):n-1]) )*r;\nR = abs(real(R)); % remove numerical noise from the imaginary part\nfigure; plot(20*log10(R));\nalpha = 1/2*log(R);\n\n% find the Hilbert transform\nalphatmp = fft(alpha);\nalphatmp(floor(m/2)+1:m) = -alphatmp(floor(m/2)+1:m);\nalphatmp(1) = 0;\nalphatmp(floor(m/2)+1) = 0;\nphi = real(ifft(j*alphatmp));\n\n% now retrieve the original sampling\nindex = find(rem([0:m-1],mult_factor)==0);\nalpha1 = alpha(index);\nphi1 = phi(index);\n\n% compute the impulse response (inverse Fourier transform)\nh = ifft(exp(alpha1+j*phi1),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/antenna_array_design/spectral_fact.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545362802363, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.8114791526067859}} {"text": "% Finding a point that satisfies many linear inequalities\n% Section 11.4.1, Boyd & Vandenberghe \"Convex Optimization\"\n% Written for CVX by Almir Mutapcic - 02/18/06\n%\n% We consider a set of linear inequalities A*x <= b which are\n% infeasible. Here A is a matrix in R^(m-by-n) and b belongs\n% to R^m. We apply a heuristic to find a point x that violates\n% only a small number of inequalities.\n%\n% We use the sum of infeasibilities heuristic:\n%\n% minimize sum( max( Ax - b ) )\n%\n% which is equivalent to the following LP (book pg. 580):\n%\n% minimize sum( s )\n% s.t. Ax <= b + s\n% s >= 0\n%\n% with variables x in R^n and s in R^m.\n\n% problem dimensions (m inequalities in n-dimensional space)\nm = 150;\nn = 10;\n\n% fix random number generator so we can repeat the experiment\nseed = 0;\nrandn('state',seed);\n\n% construct infeasible inequalities\nA = randn(m,n);\nb = randn(m,1);\n\nfprintf(1, ['Starting with an infeasible set of %d inequalities ' ...\n 'in %d variables.\\n'],m,n);\n\n% sum of infeasibilities heuristic\ncvx_begin\n variable x(n)\n minimize( sum( max( A*x - b, 0 ) ) )\ncvx_end\n\n% full LP version of the sum of infeasibilities heuristic\n% cvx_begin\n% variables x(n) s(m)\n% minimize( sum( s ) )\n% subject to\n% A*x <= b + s;\n% s >= 0;\n% cvx_end\n\n% number of satisfied inequalities\nnv = length( find( A*x > b ) );\nfprintf(1,'\\nFound an x that violates %d out of %d inequalities.\\n',nv,m);\n", "meta": {"author": "cvxr", "repo": "CVX", "sha": "a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd", "save_path": "github-repos/MATLAB/cvxr-CVX", "path": "github-repos/MATLAB/cvxr-CVX/CVX-a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd/examples/sparse_heuristics/sparse_infeas.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.948154531885212, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.8114791505883445}} {"text": "function H=chi2test(x, alpha)\n% CHI2TEST: Single sample Pearson Chi Square goodness-of-fit hypothesis test.\n% H=CHI2TEST(X,ALPHA) performs the particular case of Pearson Chi Square\n% test to determine whether the null hypothesis of composite normality PDF is \n% a reasonable assumption regarding the population distribution of a random sample X\n% with the desired significance level ALPHA.\n%\n% H indicates the result of the hypothesis test according to the MATLAB rules \n% of conditional statements:\n% H=1 => Do not reject the null hypothesis at significance level ALPHA.\n% H=0 => Reject the null hypothesis at significance level ALPHA.\n% \n% The Chi Square hypotheses and test statistic in this particular case are:\n% \n% Null Hypothesis: X is normal with unknown mean and variance.\n% Alternative Hypothesis: X is not normal.\n%\n% The random sample X is shifted by its estimated mean and normalized by its\n% estimated standard deviation. The tested bins XP of the assumed normal distribution\n% are chosen [-inf, -1.6:0.4:1.6, inf] to avoid unsufficient statistics. \n% \n% Let E(x) be the expected frequency X falls within XP according to the normal\n% distribution and O(x) be the observed frequency. The Pearson statistic, \n% X2=SUM((E(x)-O(x))^2/E(x)) distributes Chi Square with length(XP)-3 degrees\n% of freedom. \n%\n% The decision to reject the null hypothesis is taken when the P value (probability that Chi2\n% random value with length(XP)-3 degrees of freedomd is greater than X2) is less than \n% significance level ALPHA. \n%\n% X must be a row vector representing a random sample. ALPHA must be a scalar.\n% The function doesn't check the formats of X and ALPHA, as well as a number of the\n% input and output parameters.\n%\n% The asymptotic limit of the Chi Square test presented is reached when LENGTH(X)>90.\n%\n% Acknowledge: Dr. S. Loyka\n%\n% Author: G. Levin, May, 2003.\n%\n% References:\n% W. T. Eadie, D. Drijard, F. E. James, M Roos and B. Sadoulet, \"Statistical Methods\n% in Experimental Physics\", North-Holland, Sec. Reprint, 1982.\n\n%Normalize x\nN=length(x);\nx=(x-mean(x))/std(x); %standardization\n\nxp=[-inf, -1.6:.4:1.6, inf]; %tested bins\nE=0.5*N*diff(erfc(-xp/sqrt(2))); %expected frequency\nS=histc(x, xp); \nO=S(1:end-1); %%observed frequency\n%plot(xp(2:end),E,'k-',xp(2:end),O,'k.');\nx2=sum((E-O).^2./E); %statistics\n\npval=1-gammainc(x2/2,(length(O)-3)/2); %p value\n\nH=(pval>=alpha);", "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/3596-pearson-chi-square-hypothesis-test/chi2test.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566341975270266, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.8111949615777446}} {"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n\n\n% DTFT properties\n\n% time difference \n\nsyms w\nn=0:4;\nx=[1,1,1,1,0];\nx1=[0,1,1,1,1];\nL=x-x1;\nLeft=sum(L.*exp(-j*w*n));\nsubplot(211);\nezplot(abs(Left));\ntitle('| DTFT of x[n]-x[n-1] |')\nw1=-2*pi:.1:2*pi;\nLeft=subs(Left,w,w1);\nsubplot(212);\nplot(w1,angle(Left));\ntitle('Phase of DTFT of x[n]-x[n-1]')\nxlim([-2*pi 2*pi])\n\n\nfigure\nX= sum(x.*exp(-j*w*n));\nRight=(1-exp(-j*w))*X;\nsubplot(211);\nezplot(abs(Right));\ntitle('| (1-exp(jw))*X(w) |')\nsubplot(212);\nRight=subs(Right,w,w1);\nplot(w1,angle(Right));\ntitle('\\angle (1-exp(jw))*X(w)')\nxlim([-2*pi 2*pi])\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/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/7/c72f.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566341999997376, "lm_q2_score": 0.8479677506936879, "lm_q1q2_score": 0.8111949508104331}} {"text": "function polinomio=trigpol(N)\n\n% TRIGPOL generate trigonometric polynomial.\n%\n% TRIGPOL(N) generates the following polynomial in e^jw:\n% \n% P(e^jw)=sum(k=0,...,N-1){ (N-1+k) ( e^(-jw) - 2 + e^jw )\n% k \n% \n% The output of the function is a vector of size 2*N-1 holding\n% the coefficients corresponding to the different powers of e^jw. \n%\n% See also: NUMCOMB, DAUB, SPLINE\n\n\n%--------------------------------------------------------\n% Copyright (C) 1994, 1995, 1996, by Universidad de Vigo \n% \n% \n% Uvi_Wave is free software; you can redistribute it and/or modify it \n% under the terms of the GNU General Public License as published by the \n% Free Software Foundation; either version 2, or (at your option) any \n% later version. \n% \n% Uvi_Wave is distributed in the hope that it will be useful, but WITHOUT \n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \n% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License \n% for more details. \n% \n% You should have received a copy of the GNU General Public License \n% along with Uvi_Wave; see the file COPYING. If not, write to the Free \n% Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. \n% \n% Author: Nuria Gonzalez Prelcic\n% e-mail: Uvi_Wave@tsc.uvigo.es\n%--------------------------------------------------------\n\n\n%The polynomial is constructed from a sum. \n%coefs holds the coefficients of each term in the sum.\n\ncoefs=zeros(N,2*N-1);\ncoefs(1,N)=1;\n\n \nfor i=1:N-1\n\tfila=[1 -2 1];\n\tfor j=2:i\n\t\tfila=conv(fila,[1 -2 1]);\n\tend;\n\tfila=numcomb(N-1+i,i)*(-0.25)^i*fila;\n\tfila=[ zeros(1,(N-i-1)) fila zeros(1,(N-i-1))];\n\tcoefs(i+1,:)=fila;\nend\n\nfor i=0:(2*(N-1))\n\tpolinomio(i+1)=0;\n\tfor j=1:N\n\t\tpolinomio(i+1)=polinomio(i+1)+coefs(j,i+1);\n\tend\nend;\n", "meta": {"author": "alexandrebarachant", "repo": "kaggle-seizure-prediction-challenge-2016", "sha": "00f937cc7710977dc812d9fc675864e2b8288658", "save_path": "github-repos/MATLAB/alexandrebarachant-kaggle-seizure-prediction-challenge-2016", "path": "github-repos/MATLAB/alexandrebarachant-kaggle-seizure-prediction-challenge-2016/kaggle-seizure-prediction-challenge-2016-00f937cc7710977dc812d9fc675864e2b8288658/Andriy/code/trigpol.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8688267796346599, "lm_q1q2_score": 0.8109896855585278}} {"text": "function r = spm_invIcdf(F,n,p)\n% Inverse Cumulative Distribution Function (CDF) of Binomial distribution\n% FORMAT r = spm_invIcdf(F,n,p)\n%\n% F - CDF (lower tail p-value)\n% n - Binomial n\n% p - Binomial p [Defaults to 0.5]\n% r - ordinate\n%__________________________________________________________________________\n%\n% spm_invIcdf returns the inverse Cumulative Distribution Function for\n% the Binomial family of distributions.\n%\n% Definition:\n%--------------------------------------------------------------------------\n% The Bin(n,p) distribution is the distribution of the number of\n% successes from n identical independent Bernoulli trials each with\n% success probability p. If random variable R is the number of\n% successes from such a set of Bernoulli trials, then the CDF F(r) is\n% the probability of r or less sucesses.\n%\n% The Binomial distribution is discrete, defined for p in [0,1] and r\n% in {0,1,...,n}, so F(r) is a discrete function. This inverse CDF\n% function returns the smallest Whole r such that the F(r) equals or\n% exceeds the given CDF probability F. I.e. F(r) is treated as a step\n% function.\n%\n% Algorithm:\n%--------------------------------------------------------------------------\n% r is found by direct summation of the Binomial PDFs until F is exceeded.\n%\n% References:\n%--------------------------------------------------------------------------\n% Evans M, Hastings N, Peacock B (1993)\n% \"Statistical Distributions\"\n% 2nd Ed. Wiley, New York\n%\n% Abramowitz M, Stegun IA, (1964)\n% \"Handbook of Mathematical Functions\"\n% US Government Printing Office\n%\n% Press WH, Teukolsky SA, Vetterling AT, Flannery BP (1992)\n% \"Numerical Recipes in C\"\n% Cambridge\n%\n%__________________________________________________________________________\n% Copyright (C) 1999-2011 Wellcome Trust Centre for Neuroimaging\n\n% Andrew Holmes\n% $Id: spm_invIcdf.m 4182 2011-02-01 12:29:09Z guillaume $\n\n\n%-Format arguments, note & check sizes\n%--------------------------------------------------------------------------\nif nargin<3, p=0.5; end\nif nargin<2, error('Insufficient arguments'), end\nad = [ndims(F);ndims(n);ndims(p)];\nrd = max(ad);\nas = [[size(F),ones(1,rd-ad(1))];...\n [size(n),ones(1,rd-ad(2))];...\n [size(p),ones(1,rd-ad(3))]];\nrs = max(as);\nxa = prod(as,2)>1;\nif sum(xa)>1 && any(any(diff(as(xa,:)),1))\n error('non-scalar args must match in size');\nend\n\n%-Computation\n%--------------------------------------------------------------------------\n%-Initialise result to zeros\nr = zeros(rs);\n\n%-Only defined for whole n, p&F in [0,1]. Return NaN if undefined.\nmd = ( F>=0 & F<=1 & n==floor(n) & n>=0 & p>=0 & p<=1 );\nif any(~md(:))\n r(~md) = NaN;\n warning('Returning NaN for out of range arguments');\nend\n\n%-Non-zero only where defined, & F>0\nQ = find( md & F>0 );\nif isempty(Q), return, end\nif xa(1), QF=Q; else QF=1; end\nif xa(2), Qn=Q; else Qn=1; end\nif xa(3), Qp=Q; else Qp=1; end\n\n%-Compute by directly summing Bin PDF's for successive r & comparing with F\ntr = 0;\nFtr = spm_Ipdf(tr,n(Qn),p(Qp));\nwhile any(F(QF)>Ftr) && any(n(Qn)>tr)\n tr = tr+1;\n i = find(Ftr=0.\n% It is allowable to pass a scalar for this and a matrix for p.\n% p The exponent of the t term in the integral, or a matrix for\n% multiple values to be done in parallel. p>-1. It is allowable to\n% pass a scalar for this and a matrix for u. \n%\n%OUTPUTS: val The value or values of Person's gamma function at the desired\n% points.\n%\n%Pearson's incomplete gamma function is defined in terms of an integral in\n%Section 6.5.6 of [1]. In Equation 1.7 of [2], Pearson's incomplete gamma\n%function is expressed in terms of Tricomi's incomplete gamma function and\n%Equation 1.3 expressed tricomi's gamma function in terms of the type of\n%agmma function used in gammainc. Thus, this function uses the\n%transformations and the gammainc function to express the result.\n%\n%REFERENCE\n%[1] Abramowitz, M. and Stegun, I. A. (Eds.). \"Gamma function and related\n% functions.\" in Ch. 6 in Handbook of Mathematical Functions with\n% Formulas, Graphs, and Mathematical Tables, 9th printing. New York:\n% Dover, 1972.\n%[2] W. Gautschi, \"A computational procedure for incomplete gamma\n% functions,\" ACM Transactions on Mathematical Software, vol. 5, no. 4,\n% pp. 466-481, Dec. 1979.\n%\n%March 2017 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(isscalar(u)&&~isscalar(p))\n u=u*ones(size(p));\nelseif(~isscalar(u)&&isscalar(p))\n p=p*ones(size(u));\nend\n\nval=gammainc(sqrt(1+p).*u,1+p);\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/PearsonsGammaInc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.8991213847035618, "lm_q1q2_score": 0.8109361723147324}} {"text": "function fd1d_advection_lax ( )\n\n%*****************************************************************************80\n%\n%% FD1D_ADVECTION_LAX solves the advection equation using the LAX method.\n%\n% Discussion:\n%\n% The Lax method is stable for the advection problem, if the time step\n% satisifies the Courant-Friedrichs-Levy (CFL) condition:\n%\n% dt <= dx / c\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 27 January 2013\n%\n% Author:\n%\n% John Burkardt\n%\n timestamp ( );\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'FD1D_ADVECTION_LAX:\\n' );\n fprintf ( 1, ' MATLAB version\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Solve the constant-velocity advection equation in 1D,\\n' );\n fprintf ( 1, ' du/dt = - c du/dx\\n' );\n fprintf ( 1, ' over the interval:\\n' );\n fprintf ( 1, ' 0.0 <= x <= 1.0\\n' );\n fprintf ( 1, ' with periodic boundary conditions, and\\n' );\n fprintf ( 1, ' with a given initial condition\\n' );\n fprintf ( 1, ' u(0,x) = (10x-4)^2 (6-10x)^2 for 0.4 <= x <= 0.6\\n' );\n fprintf ( 1, ' = 0 elsewhere.\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' We modify the FTCS approach using the Lax method:\\n' );\n fprintf ( 1, ' du/dt = (u(t+dt,x)-0.5*u(t,x-dx)-0.5*u(t,x+dx))/dt\\n' );\n fprintf ( 1, ' du/dx = (u(t,x+dx)-u(t,x-dx))/2/dx\\n' );\n\n nx = 101;\n dx = 1.0 / ( nx - 1 );\n x = linspace ( 0.0, 1.0, nx );\n nt = 1000;\n dt = 1.0 / nt;\n c = 1.0;\n\n u = zeros ( 1, nx );\n i = find ( 0.4 <= x & x <= 0.6 );\n u(i) = ( 10.0 * x(i) - 4.0 ).^2 .* ( 6.0 - 10.0 * x(i) ).^2;\n\n iplot = 1;\n uplot(iplot,:) = u(:)';\n tplot(iplot) = 0.0;\n plotstep = ceil ( nt / 50 );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Number of nodes NX = %d\\n', nx );\n fprintf ( 1, ' Number of time steps NT = %d\\n', nt );\n fprintf ( 1, ' Constant velocity C = %g\\n', c );\n fprintf ( 1, ' CFL condition: dt (%g) <= dx / c (%g)\\n', dt, dx / c );\n\n im1 = [ nx, 1:nx-2, nx-1 ];\n i = [ 1, 2:nx-1, nx ];\n ip1 = [ 2, 3:nx, 1 ];\n\n for j = 1 : nt\n\n unew(i) = 0.5 * ( u(im1) + u(ip1) ) - c * dt / dx / 2.0 * ( u(ip1) - u(im1) );\n u(i) = unew(i);\n\n if ( rem ( j, plotstep ) < 1 )\n iplot = iplot + 1;\n uplot(iplot,:) = u(:)';\n tplot(iplot) = j * dt;\n end\n\n end\n%\n% Plot.\n%\n mesh ( x, tplot, uplot );\n xlabel ( '<--X-->' );\n ylabel ( '<--T-->');\n title ( 'U(X,T)');\n\n filename = 'fd1d_advection_lax.png';\n print ( '-dpng', filename );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Saving plot as \"%s\".\\n', filename );\n%\n% Terminate.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'FD1D_ADVECTION_LAX\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\n fprintf ( 1, '\\n' );\n timestamp ( );\n\n return\nend\nfunction timestamp ( )\n\n%*****************************************************************************80\n%\n%% TIMESTAMP prints the current YMDHMS date as a timestamp.\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 t = now;\n c = datevec ( t );\n s = datestr ( c, 0 );\n fprintf ( 1, '%s\\n', 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/fd1d_advection_lax/fd1d_advection_lax.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.8887587905460026, "lm_q1q2_score": 0.8109356584359247}} {"text": "function dist = lines_exp_dist_3d_2 ( p1, p2, q1, q2 )\n\n%*****************************************************************************80\n%\n%% LINES_EXP_DIST_3D_2 computes the distance between two explicit lines in 3D.\n%\n% Discussion:\n%\n% The explicit form of a line in 3D is:\n%\n% the line through the points P1 and P2.\n%\n% This routine uses a method that is essentially independent of dimension.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 August 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real P1(3,1), P2(3,1), two points on the first line.\n%\n% Input, real Q1(3,1), Q2(3,1), two points on the second line.\n%\n% Output, real DIST, the distance between the lines.\n%\n dim_num = 3;\n%\n% Let U = (P2-P1) and V = (Q2-Q1) be the direction vectors on\n% the two lines.\n%\n u(1:dim_num,1) = p2(1:dim_num,1) - p1(1:dim_num,1);\n v(1:dim_num,1) = q2(1:dim_num,1) - q1(1:dim_num,1);\n%\n% Let SN be the unknown coordinate of the nearest point PN on line 1,\n% so that PN = P(SN) = P1 + SN * (P2-P1).\n%\n% Let TN be the unknown coordinate of the nearest point QN on line 2,\n% so that QN = Q(TN) = Q1 + TN * (Q2-Q1).\n%\n% Let W0 = (P1-Q1).\n%\n w0(1:dim_num,1) = p1(1:dim_num,1) - q1(1:dim_num,1);\n%\n% The vector direction WC = P(SN) - Q(TC) is unique (among directions)\n% perpendicular to both U and V, so\n%\n% U dot WC = 0\n% V dot WC = 0\n%\n% or, equivalently:\n%\n% U dot ( P1 + SN * (P2 - P1) - Q1 - TN * (Q2 - Q1) ) = 0\n% V dot ( P1 + SN * (P2 - P1) - Q1 - TN * (Q2 - Q1) ) = 0\n%\n% or, equivalently:\n%\n% (u dot u ) * sn - (u dot v ) tc = -u * w0\n% (v dot u ) * sn - (v dot v ) tc = -v * w0\n%\n% or, equivalently:\n%\n% ( a -b ) * ( sn ) = ( -d )\n% ( b -c ) ( tc ) ( -e )\n%\n a = u' * u;\n b = u' * v;\n c = v' * v;\n d = u' * w0;\n e = v' * w0;\n%\n% Check the determinant.\n%\n det = - a * c + b * b;\n\n if ( det == 0.0 )\n sn = 0.0;\n if ( abs ( b ) < abs ( c ) )\n tn = e / c;\n else\n tn = d / b;\n end\n else\n sn = ( c * d - b * e ) / det;\n tn = ( b * d - a * e ) / det;\n end\n\n pn(1:dim_num,1) = p1(1:dim_num,1) + sn * ( p2(1:dim_num,1) - p1(1:dim_num,1) );\n qn(1:dim_num,1) = q1(1:dim_num,1) + tn * ( q2(1:dim_num,1) - q1(1:dim_num,1) );\n\n dist = sqrt ( sum ( ( pn(1:dim_num,1) - qn(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/lines_exp_dist_3d_2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602594, "lm_q2_score": 0.8705972768020108, "lm_q1q2_score": 0.8109287170403714}} {"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\nJ = sum(sum(((X * Theta') .* R .- Y) .^ 2)) / 2;\nX_grad = ((X * Theta') .* R .- Y) * Theta;\nTheta_grad = ((X * Theta') .* R .- Y)' * X;\n\noffset = (lambda / 2) * (sum(sum(Theta .^ 2)) + sum(sum(X .^ 2)));\nJ = J + offset;\nX_grad = X_grad + lambda * X;\nTheta_grad = Theta_grad + lambda * Theta;\n% =============================================================\n\ngrad = [X_grad(:); Theta_grad(:)];\n\nend\n", "meta": {"author": "ecmadao", "repo": "Coding-Guide", "sha": "baac530f78b239488003de039b346ca0ba24ed6c", "save_path": "github-repos/MATLAB/ecmadao-Coding-Guide", "path": "github-repos/MATLAB/ecmadao-Coding-Guide/Coding-Guide-baac530f78b239488003de039b346ca0ba24ed6c/Notes/ml/coursera/machine-learning-ex8/ex8/cofiCostFunc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.8705972667296309, "lm_q1q2_score": 0.8109287109710952}} {"text": "function variance = normal_truncated_ab_variance ( mu, s, a, b )\n\n%*****************************************************************************80\n%\n%% NORMAL_TRUNCATED_AB_VARIANCE returns the variance of the truncated Normal PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 August 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real MU, S, the mean and standard deviation of the\n% parent Normal distribution.\n%\n% Input, real A, B, the lower and upper truncation limits.\n%\n% Output, real VARIANCE, the variance of the PDF.\n%\n alpha = ( a - mu ) / s;\n beta = ( b - mu ) / s;\n\n alpha_pdf = normal_01_pdf ( alpha );\n beta_pdf = normal_01_pdf ( beta );\n\n alpha_cdf = normal_01_cdf ( alpha );\n beta_cdf = normal_01_cdf ( beta );\n\n variance = s * s * ( 1.0 ...\n + ( alpha * alpha_pdf - beta * beta_pdf ) / ( beta_cdf - alpha_cdf ) ...\n - ( ( alpha_pdf - beta_pdf ) / ( beta_cdf - alpha_cdf ) ) ^ 2 );\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/prob/normal_truncated_ab_variance.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029486, "lm_q2_score": 0.8652240947405564, "lm_q1q2_score": 0.8108973585726966}} {"text": "function [x, y, z]=splat(r, theta, phi)\n% % mapping, delaunay, flat projection\n% % \n% % Syntax;\n% % \n% % [x, y, z]=splat(r, theta, phi);\n% % \n% % ***********************************************************\n% % \n% % Description\n% % \n% % Program maps the spherical coordinates r, theta, and phi from a \n% % sphere to a flat plane to aid in triangularization of hemispherical \n% % coordinates. \n% % \n% % ***********************************************************\n% % \n% % Input Variables\n% % \n% % r, theta, phi, are matrices of spherical coordinates.\n% % \n% % ***********************************************************\n% % \n% % Output Variables\n% % \n% % x, y, and z, are matrices of rectangular coordinates.\n% % \n% % ***********************************************************\n% % \n% Example\n% \n% phi=pi/4:pi/320:pi/2;\n% theta=0:(pi/16):(5*pi);\n% r=ones(size(phi));\n% [x, y, z]=spherical_to_rectangular(r, theta, phi);\n% [x10, y10, z]=splat(r, theta, phi);\n% TRI = delaunay(x10, y10);\n%\n% figure(1);\n% h=trisurf(TRI,x,y,z, 'FaceColor', [1 1 1], 'EdgeColor', 0.5*[1 1 1],...\n% 'LineWidth', 1 );\n% hold on;\n% plot3(x,y,z, '-r', 'Linewidth', 3 );\n%\n% TRI2 = delaunay(x, y);\n%\n% figure(2);\n% h=trisurf(TRI2,x,y,z, 'FaceColor', [1 1 1], 'EdgeColor', 0.5*[1 1 1],...\n% 'LineWidth', 1 );\n% hold on;\n% plot3(x,y,z, '-r', 'Linewidth', 3 );\n%\n% % ***********************************************************\n% % \n% % This program was written by Edward L. Zechmann \n% % \n% % date January 2007 \n% % \n% % modified 11 March 2008 added comments\n% % \n% % ***********************************************************\n% % \n% % Feel free to modify this code.\n% % \n\nx=r.*phi.*cos(theta);\ny=r.*phi.*sin(theta);\nz=r.*cos(phi);\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/19169-make-icosahedron/splat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377284730286, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.8108677497224714}} {"text": "function [pdf]=gsp_erdos_renyi_density_normalized(y,N,p)\n%GSP_ERDOS_RENYI_DENSITY_NORMALIZED The asymptotic density function of the normalized graph Laplacian\n%eigenalues of an Erdos-Renyi random graph\n% Usage: pdf=gsp_erdos_renyi_density_normalized(y,N,p);\n% \n% Input parameters:\n% y : A vector of values at which the density will be evaluated.\n% N : Number of vertices in the graph.\n% p : Edge probability.\n% Output parameters:\n% pdf : The values of the density function at the points y.\n%\n% 'gsp_erdos_renyi_density_normalized(y,N,p)' computes the asymptotic density\n% function (for large $N$) of the normalized graph Laplacian\n% eigenvalues of an Erdos-Renyi random graph with $N$ vertices and edge\n% probability $p$. This is a semicircular density function.\n%\n\n% AUTHOR : David I Shuman.\n% TESTING: \n% REFERENCE:\n \npdf=sqrt((p*N)/(1-p))*(1/(2*pi))*real((y>1-2*sqrt((1-p)/(p*N))).*(y<1+2*sqrt((1-p)/(p*N))).*sqrt(4-p*N/(1-p)*(1-y).^2));\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/filters/utils/gsp_erdos_renyi_density_normalized.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810466522863, "lm_q2_score": 0.8558511414521922, "lm_q1q2_score": 0.8108171501675318}} {"text": "function [ xtab, weight ] = legendre_compute ( norder )\n\n%*****************************************************************************80\n%\n%% LEGENDRE_COMPUTE computes a Gauss-Legendre quadrature rule.\n%\n% Discussion:\n%\n% The integration interval is [ -1, 1 ].\n%\n% The weight function is w(x) = 1.0.\n%\n% The integral to approximate:\n%\n% Integral ( -1 <= X <= 1 ) F(X) dX\n%\n% The quadrature rule:\n%\n% Sum ( 1 <= I <= NORDER ) WEIGHT(I) * F ( XTAB(I) )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 15 October 2005\n%\n% Author:\n%\n% Original FORTRAN77 version by Philip Davis, Philip Rabinowitz\n% MATLAB version by John Burkardt\n%\n% Reference:\n%\n% Philip Davis, Philip Rabinowitz,\n% Methods of Numerical Integration,\n% Second Edition,\n% Dover, 2007,\n% ISBN: 0486453391,\n% LC: QA299.3.D28.\n%\n% Parameters:\n%\n% Input, integer NORDER, the order of the rule.\n% NORDER must be greater than 0.\n%\n% Output, real XTAB(NORDER), the abscissas of the rule.\n%\n% Output, real WEIGHT(NORDER), the weights of the rule.\n% The weights are positive, symmetric, and should sum to 2.\n%\n if ( norder < 1 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LEGENDRE_COMPUTE - Fatal error!\\n' );\n fprintf ( 1, ' Illegal value of NORDER = %d\\n', norder );\n error ( 'LEGENDRE_COM - Fatal error!' );\n end\n\n e1 = norder * ( norder + 1 );\n\n m = floor ( ( norder + 1 ) / 2 );\n\n for i = 1 : floor ( ( norder + 1 ) / 2 )\n\n mp1mi = m + 1 - i;\n\n t = ( 4 * i - 1 ) * pi / ( 4 * norder + 2 );\n\n x0 = cos(t) * ( 1.0 - ( 1.0 - 1.0 / ( norder ) ) / ( 8 * norder * norder ) );\n\n pkm1 = 1.0;\n pk = x0;\n\n for k = 2 : norder\n pkp1 = 2.0 * x0 * pk - pkm1 - ( x0 * pk - pkm1 ) / k;\n pkm1 = pk;\n pk = pkp1;\n end\n\n d1 = norder * ( pkm1 - x0 * pk );\n\n dpn = d1 / ( 1.0 - x0 * x0 );\n\n d2pn = ( 2.0 * x0 * dpn - e1 * pk ) / ( 1.0 - x0 * x0 );\n\n d3pn = ( 4.0 * x0 * d2pn + ( 2.0 - e1 ) * dpn ) / ( 1.0 - x0 * x0 );\n\n d4pn = ( 6.0 * x0 * d3pn + ( 6.0 - e1 ) * d2pn ) / ( 1.0 - x0 * x0 );\n\n u = pk / dpn;\n v = d2pn / dpn;\n%\n% Initial approximation H:\n%\n h = - u * ( 1.0 + 0.5 * u * ( v + u * ( v * v - d3pn / ( 3.0 * dpn ) ) ) );\n%\n% Refine H using one step of Newton's method:\n%\n p = pk + h * ( dpn + 0.5 * h * ( d2pn + h / 3.0 ...\n * ( d3pn + 0.25 * h * d4pn ) ) );\n\n dp = dpn + h * ( d2pn + 0.5 * h * ( d3pn + h * d4pn / 3.0 ) );\n\n h = h - p / dp;\n\n xtemp = x0 + h;\n\n xtab(mp1mi) = xtemp;\n\n fx = d1 - h * e1 * ( pk + 0.5 * h * ( dpn + h / 3.0 ...\n * ( d2pn + 0.25 * h * ( d3pn + 0.2 * h * d4pn ) ) ) );\n\n weight(mp1mi) = 2.0 * ( 1.0 - xtemp * xtemp ) / fx / fx;\n\n end\n\n if ( mod ( norder, 2 ) == 1 )\n xtab(1) = 0.0;\n end\n%\n% Shift the data up.\n%\n nmove = floor ( ( norder + 1 ) / 2 );\n ncopy = norder - nmove;\n\n for i = 1 : nmove\n iback = norder + 1 - i;\n xtab(iback) = xtab(iback-ncopy);\n weight(iback) = weight(iback-ncopy);\n end\n%\n% Reflect values for the negative abscissas.\n%\n for i = 1 : norder - nmove\n xtab(i) = - xtab(norder+1-i);\n weight(i) = weight(norder+1-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/laguerre_test_int/legendre_compute.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.8962513821399045, "lm_q1q2_score": 0.8107942855258315}} {"text": "function [mel,mr] = frq2mel(frq)\n%FRQ2ERB Convert Hertz to Mel frequency scale MEL=(FRQ)\n%\t[mel,mr] = 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% mr gives the corresponding gradients in Hz/mel.\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%\tReferences:\n%\n%\t [1] S. S. Stevens & J. Volkman \"The relation of pitch to\n%\t\tfrequency\", American J of Psychology, V 53, p329 1940\n%\t [2] C. G. M. Fant, \"Acoustic description & classification\n%\t\tof phonetic units\", Ericsson Tchnics, No 1 1959\n%\t\t(reprinted in \"Speech Sounds & Features\", MIT Press 1973)\n%\t [3] S. B. Davis & P. Mermelstein, \"Comparison of parametric\n%\t\trepresentations for monosyllabic word recognition in\n%\t\tcontinuously spoken sentences\", IEEE ASSP, V 28,\n%\t\tpp 357-366 Aug 1980\n%\t [4] J. R. Deller Jr, J. G. Proakis, J. H. L. Hansen,\n%\t\t\"Discrete-Time Processing of Speech Signals\", p380,\n%\t\tMacmillan 1993\n%\t [5] HTK Reference Manual p73\n%\t\n\n\n\n% Copyright (C) Mike Brookes 1998\n% Version: $Id: frq2mel.m,v 1.7 2010/08/01 08:41:57 dmb Exp $\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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\npersistent k\nif isempty(k)\n k=1127.01048;\nend\naf=abs(frq);\nmel = sign(frq).*log(1+af/700)*k;\nmr=(700+af)/k;\nif ~nargout\n plot(frq,mel,'-x');\n xlabel(['Frequency (' xticksi 'Hz)']);\n ylabel(['Frequency (' yticksi 'Mel)']);\nend\n", "meta": {"author": "decouples", "repo": "Matlab_deep_learning", "sha": "1b823b82686080e32b03e1f1a4648896bd6e3c44", "save_path": "github-repos/MATLAB/decouples-Matlab_deep_learning", "path": "github-repos/MATLAB/decouples-Matlab_deep_learning/Matlab_deep_learning-1b823b82686080e32b03e1f1a4648896bd6e3c44/第 19 章 基于语音识别的信号灯图像模拟控制技术/voicebox/frq2mel.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789547, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.8105263172156281}} {"text": "function value = cos_deg ( angle )\n\n%*****************************************************************************80\n%\n%% COS_DEG returns the cosine of an angle given in degrees.\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 ANGLE, the angle, in degrees.\n%\n% Output, real COS_DEG, the cosine of the angle.\n%\n angle_rad = pi * angle / 180.0;\n\n value = cos ( angle_rad );\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/subpak/cos_deg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.8824278587245935, "lm_q1q2_score": 0.810492562892366}} {"text": "%% Transient Behavior and Location of Characteristic Roots in the Complex Plane\n% Copyright 2011 The MathWorks, Inc.\n%% Initial Value Problem\n%\n% Consider the system described by the following second-order, \n% ordinary differential equation and associated initial conditions:\n%\n% $$\\frac{d^2x}{dt^2} + 2\\zeta\\omega_n\\frac{dx}{dt} + \\omega_n^2x = 0; x(0)=x0,\\frac{dx}{dt}(0)=0 $$\n%\n% We would like to examine the behavior of the free response of the \n% system as the damping ratio changes. This will be done first by solving\n% the initial value problem for various damping ratios and plotting the\n% results. Then, we will explore changes in the damping ratio affect the\n% characteristic roots. (Recall that the characteristic roots dictate the\n% free-response behavior.)\n\n%% Set physical and derived parameters.\n%\n% To enable numerical solution of the differential equation, we will set\n% specific values for the mass and (linear) spring rate. We will then use\n% these to derive the (circular) natural frequency.\n%\nparam.m = 1; % Mass [kg]\nparam.k = 1; % Spring rate [N/m]\nparam.wn = sqrt(param.k/param.m); % (Circular) natural frequency [rad/s]\n\n\n%% Set initial conditions.\n%\n% To solve our 2nd order differential equation, we need two initial\n% conditions: one on position, the other on velocity. Moreover, recall \n% from the accompanying PowerPoint slides that we have represented our\n% 2nd order linear ODE into a system of 1st order ODE's amenable to\n% solution using MATLAB. Having defined position and velocity as our\n% system states, we must define an initial state vector.\n\nx0 = 1; % Position [m]\nx0_dot = 0; % Velocity [m/s]\nz0 = [x0 ; x0_dot]; % Initial condition on state vector\n\n\n%% Set simulation parameters.\n%\n% We will define the duration of our simulation to be approximately 4\n% periods. To accommodate changes in physical parameters, we will\n% parameterize the duration by the natural frequency. We then define the\n% associated time step and vector of simulation time. Note that the time\n% step dt serves to define the times at which output will be provided, not\n% the solver time step.\n\ntend = 4*round((2*pi)/param.wn); % Simulate for approximately 4 periods [s]\ndt = round((2*pi)/param.wn)/1000; % Time step [s]\ntsim = 0:dt:tend; % Vector of simulation times [s]\n\n\n%% Undamped system.\n%\n% We first consider an undamped system, characterized by a damping ratio of\n% zero. Physically, this represents a system with zero dissipation of\n% energy. We will plot the free response to confirm the expected behavior.\n%\n% To solve the system of 1st order ODE's, we will use the baseline ode45\n% solver. The solver requires a vector of state derivatives; in this\n% case, we call upon a function to define them.\n\nparam.zeta = 0; % Damping ratio\n\n\n[t,z] = ode45(@(t,z) odesys( t,z,param ),tsim,z0);\nx(:,1) = z(:,1); % Save solution for future plotting.\n\n\nplot(t,x(:,1),'linewidth',2);grid on;hold all\n\n\n ylim([-1 1])\n xlabel('Time [s]');\n ylabel('Position [m]')\n title('Free Response: Undamped 2nd Order System');\n\n\n%% Consider several damping ratios.\n%\n% Now we will consider four distinct values of the damping ratio\n% corresponding to four distinct types of system behavior: undamped,\n% underdamped, critically damped, and overdamped. These terms refer to the\n% behavior of the system as it returns to its equilibrium state. We will\n% plot and compare the free responses for these cases.\n\nzetavals = [0 1/sqrt(2) 1 1.5]; % Damping ratios to consider.\n\ncase1 = 'Undamped: zeta = 0' ;\ncase2 = 'Underdamped: zeta = 0.707' ;\ncase3 = 'Critically Damped: zeta = 1' ;\ncase4 = 'Overdamped: zeta = 1.5' ;\n\nfor i = 2: length(zetavals)\n \n param.zeta = zetavals(i); % Set current damping ratio.\n [t,z] = ode45(@(t,z) odesys( t,z,param ),tsim,z0); % Compute free response.\n x(:,i) = z(:,1); % Save solution for future plotting.\n\nend;\n\n\nfigure % Plot results\n\n plot(t,x,'linewidth',2);grid on\n xlabel('Time [s]');\n ylabel('Position [m]')\n title('Free Response of 2nd Order System for Various Damping Ratios');\n legend(case1,case2,case3,case4,0)\n \n \n%% Track characteristic roots as damping ratio increases.\n%\n% Recalling that the free response of a system is governed by its\n% characteristic roots, we will examine the changes in these roots as the\n% damping ratio changes over a more finely spaced set of values. Since the\n% roots may have real and imaginary parts, we will plot them in the complex \n% plane. For each value of the damping ratio, we will compute the\n% characteristic roots as the eigenvalues of the associated state matrix.\n \nzeta_range = 0:0.01:1.5; % Damping ratio: undamped to overdamped.\nS = zeros(2,length(zeta_range)); % Initialize characteristic roots array.\n\nfor i = 1:length(zeta_range)\n \n S(:,i) = eig([0 1; -param.wn^2 -2*zeta_range(i)*param.wn]); % Characteristic roots.\n\nend;\n\nfigure % Plot characteristic roots in complex plane.\n\n plot(S,'bx','linewidth',2,'markersize',5); grid on;\n set(gca,'YAxisLocation','right')\n xlabel('Real Axis','Position',[-1.5 -0.1 1])\n ylabel('Imaginary Axis')\n title('Loci of Characteristic Roots in Complex Plane for Various Damping Ratios')\n\n \n%% Show the \"odesys\" function.\n%\n% Here we record the function used to define the state matrix\n% corresponding to our system of ordinary differential equations.\n\ntype odesys.m", "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/31826-teaching-system-dynamics-with-matlab-simulink/TeachingSystemDynamicsWebinarContent/MATLABPublish/publish_spring_mass_damper_free_response.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.8918110454379297, "lm_q1q2_score": 0.8103154809809034}} {"text": "function [ x, w ] = gen_hermite_dr_compute ( n, alpha )\n\n%*****************************************************************************80\n%\n%% GEN_HERMITE_DR_COMPUTE computes a generalized Gauss-Hermite rule.\n%\n% Discussion:\n%\n% The integral to be approximated has the form:\n%\n% Integral ( -oo < x < +oo ) |x|^ALPHA exp(-x^2) f(x) dx\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 13 February 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Philip Davis, Philip Rabinowitz,\n% Methods of Numerical Integration,\n% Second Edition,\n% Dover, 2007,\n% ISBN: 0486453391,\n% LC: QA299.3.D28.\n%\n% Parameters:\n%\n% Input, integer N, the order.\n%\n% Input, real ALPHA, the parameter.\n%\n% Output, real X(N), the abscissas.\n%\n% Output, real W(N), the weights.\n%\n x = zeros ( n, 1 );\n w = zeros ( n, 1 );\n\n if ( n == 1 )\n arg = ( alpha + 1.0 ) / 2.0;\n x(1) = 0.0;\n w(1) = gamma ( arg );\n return\n end\n \n if ( mod ( n, 2 ) == 0 )\n n_laguerre = floor ( n / 2 );\n alpha_laguerre = ( alpha - 1.0 ) / 2.0;\n elseif ( mod ( n, 2 ) == 1 )\n n_laguerre = floor ( n - 1 ) / 2;\n alpha_laguerre = ( alpha + 1.0 ) / 2.0;\n end\n \n [ x_laguerre, w_laguerre ] = gen_laguerre_ss_compute ( n_laguerre, alpha_laguerre );\n \n if ( mod ( n, 2 ) == 0 )\n \n x(1:n_laguerre) = - sqrt ( x_laguerre(n_laguerre:-1:1) );\n x(n_laguerre+1:n_laguerre+n_laguerre) = sqrt ( x_laguerre(1:n_laguerre) );\n\t\n w(1:n_laguerre) = 0.5 * w_laguerre(n_laguerre:-1:1);\n w(n_laguerre+1:n_laguerre+n_laguerre) = 0.5 * w_laguerre(1:n_laguerre);\n\t\n elseif ( mod ( n, 2 ) == 1 )\n\n x(1:n_laguerre) = - sqrt ( x_laguerre(n_laguerre:-1:1) );\n x(n_laguerre+1) = 0.0;\n x(n_laguerre+2:n_laguerre+n_laguerre+1) = sqrt ( x_laguerre(1:n_laguerre) );\n\n w(1:n_laguerre) = 0.5 * w_laguerre(n_laguerre:-1:1) ...\n ./ x_laguerre(n_laguerre:-1:1);\n\n arg = ( alpha + 1.0 ) / 2.0;\n w(n_laguerre+1) = gamma ( arg ) ...\n - sum ( w_laguerre(1:n_laguerre) ./ x_laguerre(1:n_laguerre) );\n\n w(n_laguerre+2:n_laguerre+n_laguerre+1) = 0.5 * w_laguerre(1:n_laguerre) ...\n ./ x_laguerre(1:n_laguerre);\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/quadrule/gen_hermite_dr_compute.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.8103043570929588}} {"text": "function fx = p37_fun ( n, x )\n\n%*****************************************************************************80\n%\n%% P37_FUN evaluates the integrand for problem 37.\n%\n% Discussion:\n%\n% The problem has a parameter ALPHA that can be set by calling\n% P37_PARAM_SET. It had a default value of 5.0.\n%\n% The integrand has a peak of height 4^ALPHA at X = PI/4.\n%\n% Suggested values of ALPHA include 0 through 20.\n%\n% Interval:\n%\n% 0 <= x <= 1\n%\n% Integrand:\n%\n% 4^(-ALPHA) / ( ( x - PI/4 )^2 + 16^(-ALPHA) )\n%\n% Exact Integral:\n%\n% atan ( ( 4 - PI ) * 4^(ALPHA-1) ) + atan ( PI * 4^(ALPHA-1) )\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% Robert Piessens, Elise de Doncker-Kapenga,\n% Christian Ueberhuber, David Kahaner,\n% QUADPACK: A Subroutine Package for Automatic Integration,\n% Springer, 1983, page 83.\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 alpha = p37_param_get ( );\n\n fx = 4.0^( -alpha ) ./ ( ( x - 0.25 * pi ).^2 + 16.0^(-alpha) );\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/p37_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.8757869803008764, "lm_q1q2_score": 0.8103043538167822}} {"text": "function timemetric\ntic; [x,n,bco,bcn,gco,gcn,cs1,cs2]=metr(@elipsod,1); toc\n\nfunction [x,n,bco,bcn,gco,gcn,cs1,cs2]=metr(func,method)\n% [x,n,bco,bcn,gco,gcn,cs1,cs2]=metr(func,method)\n\n% This function computes base vectors, metric tensor\n% components, and Christoffel symbols for a general\n% curvilinear coordinate system\n% func - handle of a function which returns the\n% cartesian radius vector x as a function\n% of the curvilinear coordinate variables,\n% and a vector containing the names of the\n% coordinate variables used to define x. In\n% spherical coordinates, for example, names\n% might be 'r, theta, phi'.\n% method - Use 1 to compute the Christoffel symbols by\n% differentiating the metric tensor components.\n% Use 2 to compute the Christoffel symbols by \n% by differentiating vector x. \n% x - cartesian components of the radius vector\n% expressed in terms of the curvilinear \n% coordinate variables\n% n a vector containing the names of the \n% curvilinear coordinate variables\n% bco, bcn - cartesian components of the covariant and\n% contravariant base vectors. The i'th column\n% of each array contains components of the \n% i'th base vector.\n% gco, gcn - covariant and contravariant components of\n% the metric tensor.\n% cs1, cs2 - Christoffel symbols or the first and second\n% kinds. The symbol for index i,j,k is in\n% row i, column j, and layer k of each array.\n \nif nargin<2, method=1; end\nif nargin==0, func=@sphr; end\n[x,n]=feval(func); x=simple(x(:));\n\n% Differentiate the radius vector to get the\n% contravariant base vectors.\n% bco=[diff(x,n(1)),diff(x,n(2)),diff(x,n(3))]\nbco=jacobian(x,n(:).');\n\n% Use orthogonality to compute the contravariant \n% base vectors.\nbcn=simple(inv(bco.'));\n\n% Obtain the metric tensor components as dot products of\n% the base vectors\ngco=simple(bco.'*bco); gcn=simple(bcn.'*bcn);\n\n% If Christoffel symbols are not required, then exit\nif nargout<6, return, end\n\n% Compute the Christoffel symbols.\ncs1=sym(zeros(3,3,3)); cs2=cs1;\nif method==1 \n % Obtain symbols of the first kind by differentiating\n % the covariant metric tensor components. \n for k=1:3\n for i=1:3, for j=1:i\n cs1(i,j,k)=1/2*(diff(gco(j,k),n(i))+...\n diff(gco(i,k),n(j))-diff(gco(i,j),n(k))); \n if j~=i, cs1(j,i,k)=cs1(i,j,k); end \n end, end\n end\nelse % method==2 \n % Obtain symbols of the first kind using derivatives \n % of vector x. \n h=sym(zeros(3,3,3)); \n for k=1:3, h(:,:,k)=simple(diff(bco(:,:),n(k))); end\n \n for k=1:3\n cs1(:,:,k)=squeeze(h(1,:,:)*bco(1,k)+h(2,:,:)*bco(2,k)+...\n h(3,:,:)*bco(3,k));\n end\n% for k=1:3, for i=1:3, for j=1:3\n% cs1(i,j,k)=h(1,i,j)*bco(1,k)+h(2,i,j)*bco(2,k)+...\n% h(3,i,j)*bco(3,k);\n% end,end,end\n cs1=simple(cs1);\nend\n\n% Obtain Christoffel symbols of the second kind by \n% using the contravariant metric tensor components to\n% raise the third index.\nfor k=1:3\n cs2(:,:,k)=cs1(:,:,1)*gcn(1,k)+cs1(:,:,2)*gcn(2,k)+...\n cs1(:,:,3)*gcn(3,k);\nend\nx=simple(x); bco=simple(bco); bcn=simple(bcn);\ngco=simple(gco); gcn=simple(gcn);\ncs1=simple(cs1); cs2=simple(cs2);\n\nfunction [X,names]=elipsod\n% [X,names]=elipsod defines ellipsoidal\n% coordinates with 0 < lm < b,\n% b < t < c, and c < e Knapsack problem on Wikipedia.\n%\n% Copyright 2009 Petter Strandmark\n% petter.strandmark@gmail.com\nfunction [best amount] = knapsack(weights, values, W)\n if ~all(is_positive_integer(weights)) || ...\n ~is_positive_integer(W)\n error('Weights must be positive integers');\n end\n %We work in one dimension\n [M N] = size(weights);\n weights = weights(:);\n values = values(:);\n if numel(weights) ~= numel(values)\n error('The size of weights must match the size of values');\n end\n if numel(W) > 1\n error('Only one constraint allowed');\n end \n \n % Solve the problem\n \n % Note that A would ideally be indexed from A(0..N,0..W) but MATLAB \n % does not allow this.\n A = zeros(length(weights)+1,W+1);\n % A(j+1,Y+1) means the value of the best knapsack with capacity Y using\n % the first j items.\n for j = 1:length(weights)\n for Y = 1:W\n if weights(j) > Y\n A(j+1,Y+1) = A(j,Y+1);\n else\n A(j+1,Y+1) = ...\n max( A(j,Y+1), values(j) + A(j,Y-weights(j)+1));\n end\n end\n end\n\n best = A(end,end);\n \n %Now backtrack \n amount = zeros(length(weights),1);\n a = best;\n j = length(weights); \n Y = W;\n while a > 0\n while A(j+1,Y+1) == a\n j = j - 1;\n end\n j = j + 1; %This item has to be in the knapsack\n amount(j) = 1;\n Y = Y - weights(j);\n j = j - 1;\n a = A(j+1,Y+1);\n end\n\n \n amount = reshape(amount,M,N);\nend\n\nfunction yn = is_positive_integer(X)\n yn = X>0 & floor(X)==X;\nend", "meta": {"author": "kezhang-cs", "repo": "Video-Summarization-with-LSTM", "sha": "0ee0a0948872544567ecede76868287042470f75", "save_path": "github-repos/MATLAB/kezhang-cs-Video-Summarization-with-LSTM", "path": "github-repos/MATLAB/kezhang-cs-Video-Summarization-with-LSTM/Video-Summarization-with-LSTM-0ee0a0948872544567ecede76868287042470f75/codes/evalSumMe/knapsack/knapsack.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750360641185, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.8102563031284358}} {"text": "function program_03 ( )\n\n%*****************************************************************************80\n%\n%% PROGRAM_03 demonstrates barycentric coordinates.\n%\n% Discussion:\n%\n% The program\n% * reads a triangle T (defined by three points),\n% * computes and prints the area;\n% * computes and prints the angles;\n% * reads a point P\n% * computes the signed areas of the subtriangles;\n% * computes the barycentric coordinates.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 February 2007\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PROGRAM_03 - Barycentric Coordinates\\n' );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Define a triangle T:\\n' );\n\n t_v1 = input ( ' Enter [ T.v1.x, T.v1.y]: ' ); \n t_v2 = input ( ' Enter [ T.v2.x, T.v2.y]: ' ); \n t_v3 = input ( ' Enter [ T.v3.x, T.v3.y]: ' ); \n%\n% Compute the area.\n%\n t_area = 0.5 * ( t_v1(1) * ( t_v2(2) - t_v3(2) ) ...\n + t_v2(1) * ( t_v3(2) - t_v1(2) ) ...\n + t_v3(1) * ( t_v1(2) - t_v2(2) ) );\n \n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Triangle area = %f\\n', t_area );\n%\n% Check various points.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Now we compute barycentric coordinates for points.\\n' );\n fprintf ( 1, '\\n' );\n\n while ( 1 )\n\n p = [];\n fprintf ( 1, '\\n' );\n p = input ( ' Enter a point [ P.x, P.y], or RETURN to quit: ' );\n\n if ( isempty ( p ) )\n break\n end\n%\n% Compute the areas of the three subtriangles.\n%\n tpbc_area = 0.5 * ( p(1) * ( t_v2(2) - t_v3(2) ) ...\n + t_v2(1) * ( t_v3(2) - p(2) ) ...\n + t_v3(1) * ( p(2) - t_v2(2) ) );\n\n tapc_area = 0.5 * ( t_v1(1) * ( p(2) - t_v3(2) ) ...\n + p(1) * ( t_v3(2) - t_v1(2) ) ...\n + t_v3(1) * ( t_v1(2) - p(2) ) );\n\n tabp_area = 0.5 * ( t_v1(1) * ( t_v2(2) - p(2) ) ...\n + t_v2(1) * ( p(2) - t_v1(2) ) ...\n + p(1) * ( t_v1(2) - t_v2(2) ) );\n\n xi1 = tpbc_area / t_area;\n xi2 = tapc_area / t_area;\n xi3 = tabp_area / t_area;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' PBC = %8.4f XI1 = %8.4f\\n', tpbc_area, xi1 );\n fprintf ( 1, ' APC = %8.4f XI2 = %8.4f\\n', tapc_area, xi2 );\n fprintf ( 1, ' APB = %8.4f XI3 = %8.4f\\n', tabp_area, xi3 );\n sum1 = tpbc_area + tapc_area + tabp_area;\n sum2 = xi1 + xi2 + xi3;\n fprintf ( 1, ' Sum = %8.4f Sum = %8.4f\\n', sum1, sum2 );\n\n end\n \n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PROGRAM_03\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\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/cg_lab_triangles/program_03.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551525886193, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.8102216397074526}} {"text": "function F = spm_ncFcdf(x,df,d)\n% Cumulative Distribution Function (CDF) of non-central F-distribution\n% FORMAT f = spm_ncFcdf(x,df,d)\n% x - F-variate (F has range [0,Inf) )\n% df - degrees of freedom, df = [v,w] with v>0 and w>0\n% d - non-centrality parameter\n% F - CDF of non-central F-distribution with [v,w] d.f. at points x\n%\n% Reference:\n% https://en.wikipedia.org/wiki/Noncentral_F-distribution\n%__________________________________________________________________________\n% Copyright (C) 2018 Wellcome Trust Centre for Neuroimaging\n\n% Guillaume Flandin\n% $Id: spm_ncFcdf.m 7354 2018-06-22 10:44:22Z guillaume $\n\n\n%-Format arguments, note & check sizes\n%--------------------------------------------------------------------------\n%-Unpack degrees of freedom v & w from single df parameter (df)\nif numel(df) == 2\n v = df(1);\n w = df(2);\nelseif size(df,2) == 2\n v = df(:,1);\n w = df(:,2);\nelse\n error('Cannot unpack degrees of freedom.');\nend\n\n%-Check argument sizes\nad = [ndims(x);ndims(v);ndims(w);ndims(d)];\nrd = max(ad);\nas = [[size(x),ones(1,rd-ad(1))];...\n [size(v),ones(1,rd-ad(2))];...\n [size(w),ones(1,rd-ad(3))];...\n [size(d),ones(1,rd-ad(4))];];\nrs = max(as);\nxa = prod(as,2)>1;\nif all(xa) && any(any(diff(as(xa,:)),1))\n error('Non-scalar arguments must match in size.');\nend\n\n\n%-Computation\n%--------------------------------------------------------------------------\n%-Initialise result to zeros\nF = zeros(rs);\n\n%-Only defined for v>0, w>0 and d>=0. Return NaN if undefined.\nmd = true(size(F)) & v>0 & w>0 & d>=0;\nif any(~md(:))\n F(~md) = NaN;\n warning('Returning NaN for out of range arguments');\nend\n\n%-Compute where defined\nif ~any(md(:)), return, end\nQ = md;\nif xa(1), Qx=Q; else Qx=1; end\nif xa(2), Qv=Q; else Qv=1; end\nif xa(3), Qw=Q; else Qw=1; end\nif xa(4), Qd=Q; else Qd=1; end\n\na = exp(-d(Qd)/2);\nx = v(Qv) .* x(Qx) ./ (w(Qw) + v(Qv) .* x(Qx));\nF(Q) = a .* betainc(x(Qx), v(Qv)/2, w(Qw)/2);\nfor i=1:1024\n a = a .* d(Qd) / (2 * i);\n % could use recursion with:\n % Ix(a+1,b)=Ix(a,b)-G(a+b)/(G(a+1)*G(b))*x^a*(1-x)^b and G(a+1)=a*G(a)\n e = a .* betainc(x(Qx), v(Qv)/2+i, w(Qw)/2);\n if max(e) < 1e-12, break; end\n F = F + e;\nend\n", "meta": {"author": "spm", "repo": "spm12", "sha": "3085dac00ac804adb190a7e82c6ef11866c8af02", "save_path": "github-repos/MATLAB/spm-spm12", "path": "github-repos/MATLAB/spm-spm12/spm12-3085dac00ac804adb190a7e82c6ef11866c8af02/spm_ncFcdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140232, "lm_q2_score": 0.8670357563664174, "lm_q1q2_score": 0.8101540149148032}} {"text": "% Minimize sidelobe level of a uniform linear array via spectral factorization\n% \"FIR Filter Design via Spectral Factorization and Convex Optimization\" example\n% by S.-P. Wu, S. Boyd, and L. Vandenberghe\n% (figures are generated)\n%\n% Designs a uniform linear antenna array using spectral factorization method where:\n% - it minimizes sidelobe level outside the beamwidth of the pattern\n% - it has a constraint on the maximum ripple around unit gain in the beamwidth\n%\n% minimize max |y(theta)| for theta in the stop-beamwidth\n% s.t. 1/delta <= |y(theta)| <= delta for theta in the pass-beamwidth\n%\n% We first replace the look-angle variable theta with the \"frequency\"\n% variable omega, defined by omega = -2*pi*d/lambda*cos(theta).\n% This transforms the antenna pattern y(theta) into a standard discrete\n% Fourier transform of array weights w. Then we apply another change of\n% variables: we replace w with its auto-correlation coefficients r.\n%\n% Now the problem can be solved via spectral factorization approach:\n%\n% minimize max R(omega) for omega in the stopband\n% s.t. (1/delta)^2 <= R(omega) <= delta^2 for omega in the passband\n% R(omega) >= 0 for all omega\n%\n% where R(omega) is the squared magnitude of the y(theta) array response\n% (and the Fourier transform of the autocorrelation coefficients r).\n% Variables are coefficients r. delta is the allowed passband ripple.\n% This is a convex problem (can be formulated as an LP after sampling).\n%\n% Written for CVX by Almir Mutapcic 02/02/06\n\n%********************************************************************\n% problem specs: a uniform line array with inter-element spacing d\n% antenna element locations are at d*[0:n-1]\n% (the array pattern will be symmetric around origin)\n%********************************************************************\nn = 20; % number of antenna elements\nlambda = 1; % wavelength\nd = 0.45*lambda; % inter-element spacing\n\n% passband direction from 30 to 60 degrees (30 degrees bandwidth)\n% transition band is 15 degrees on both sides of the passband\ntheta_pass = 40;\ntheta_stop = 50;\n\n% passband max allowed ripple\nripple = 0.1; % in dB (+/- around the unit gain)\n\n%********************************************************************\n% construct optimization data\n%********************************************************************\n% number of frequency samples\nm = 30*n;\n\n% convert passband and stopband angles into omega frequencies\nomega_zero = -2*pi*d/lambda;\nomega_pass = -2*pi*d/lambda*cos(theta_pass*pi/180);\nomega_stop = -2*pi*d/lambda*cos(theta_stop*pi/180);\nomega_pi = +2*pi*d/lambda;\n\n% build matrix A that relates R(omega) and r, ie, R = A*r\nomega = linspace(-pi,pi,m)';\nA = exp( -j*omega(:)*[1-n:n-1] );\n\n% passband constraint matrix\nAp = A(omega >= omega_zero & omega <= omega_pass,:);\n\n% stopband constraint matrix\nAs = A(omega >= omega_stop & omega <= omega_pi,:);\n\n%********************************************************************\n% formulate and solve the magnitude design problem\n%********************************************************************\ncvx_begin\n variable r(2*n-1,1) complex\n % minimize stopband attenuation\n minimize( max( real( As*r ) ) )\n subject to\n % passband ripple constraints\n (10^(-ripple/20))^2 <= real( Ap*r ) <= (10^(+ripple/20))^2;\n % nonnegative-real constraint for all frequencies\n % a bit redundant: the passband frequencies are already constrained\n real( A*r ) >= 0;\n % auto-correlation symmetry constraints\n imag(r(n)) == 0;\n r(n-1:-1:1) == conj(r(n+1:end));\ncvx_end\n\n% check if problem was successfully solved\nif ~strfind(cvx_status,'Solved')\n return\nend\n\n% find antenna weights by computing the spectral factorization\nw = spectral_fact(r);\n\n% divided by 2 since this is in PSD domain\nmin_sidelobe_level = 10*log10( cvx_optval );\nfprintf(1,'The minimum sidelobe level is %3.2f dB.\\n\\n',...\n min_sidelobe_level);\n\n%********************************************************************\n% plots\n%********************************************************************\n% build matrix G that relates y(theta) and w, ie, y = G*w\ntheta = [-180:180]';\nG = kron( cos(pi*theta/180), [0:n-1] );\nG = exp(2*pi*i*d/lambda*G);\ny = G*w;\n\n% plot array pattern\nfigure(1), clf\nymin = -40; ymax = 5;\nplot([-180:180], 20*log10(abs(y)), ...\n [theta_stop theta_stop],[ymin ymax],'r--',...\n [-theta_pass -theta_pass],[ymin ymax],'r--',...\n [-theta_stop -theta_stop],[ymin ymax],'r--',...\n [theta_pass theta_pass],[ymin ymax],'r--');\nxlabel('look angle'), ylabel('mag y(theta) in dB');\naxis([-180 180 ymin ymax]);\n\n% polar plot\nfigure(2), clf\nzerodB = 50;\ndBY = 20*log10(abs(y)) + zerodB;\nplot(dBY.*cos(pi*theta/180), dBY.*sin(pi*theta/180), '-');\naxis([-zerodB zerodB -zerodB zerodB]), axis('off'), axis('square')\nhold on\nplot(zerodB*cos(pi*theta/180),zerodB*sin(pi*theta/180),'k:') % 0 dB\nplot( (min_sidelobe_level + zerodB)*cos(pi*theta/180), ...\n (min_sidelobe_level + zerodB)*sin(pi*theta/180),'k:') % min level\ntext(-zerodB,0,'0 dB')\ntext(-(min_sidelobe_level + zerodB),0,sprintf('%0.1f dB',min_sidelobe_level));\nplot([0 60*cos(theta_pass*pi/180)], [0 60*sin(theta_pass*pi/180)], 'k:')\nplot([0 60*cos(-theta_pass*pi/180)],[0 60*sin(-theta_pass*pi/180)],'k:')\nplot([0 60*cos(theta_stop*pi/180)], [0 60*sin(theta_stop*pi/180)], 'k:')\nplot([0 60*cos(-theta_stop*pi/180)],[0 60*sin(-theta_stop*pi/180)],'k:')\nhold off\n", "meta": {"author": "cvxr", "repo": "CVX", "sha": "a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd", "save_path": "github-repos/MATLAB/cvxr-CVX", "path": "github-repos/MATLAB/cvxr-CVX/CVX-a7b46e7840c3ccf3f35df374d2ff3da4eaafc3cd/examples/antenna_array_design/line_array_spec_fact.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966671870766, "lm_q2_score": 0.8558511414521922, "lm_q1q2_score": 0.8101458381069004}} {"text": "function [ cluster, cluster_center, cluster_energy ] = ...\n cluster_energy_compute ( dim_num, point_num, cluster_num, point, ...\n cluster_center )\n\n%*****************************************************************************80\n%\n%% CLUSTER_ENERGY_COMPUTE computes the energy of the clusters.\n%\n% Discussion:\n%\n% The cluster energy is defined as the sum of the distance\n% squared from each point to its cluster center. It is the goal\n% of the H-means and K-means algorithms to find, for a fixed number\n% of clusters, a clustering that minimizes this energy\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license. \n%\n% Modified:\n%\n% 04 October 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the number of spatial dimensions.\n%\n% Input, integer POINT_NUM, the number of data points.\n%\n% Input, integer CLUSTER_NUM, the number of clusters.\n%\n% Input, real POINT(DIM_NUM,POINT_NUM), the data points.\n%\n% Input, integer CLUSTER(POINT_NUM), the cluster to which each\n% data point belongs.\n%\n% Input, real CLUSTER_CENTER(DIM_NUM,CLUSTER_NUM), the centers.\n%\n% Output, real CLUSTER_ENERGY(CLUSTER_NUM), the energy\n% associated with each cluster.\n%\n cluster_energy(1:cluster_num) = 0.0;\n\n for i = 1 : point_num\n\n j = cluster(i);\n\n point_energy = sum ( ...\n ( point(1:dim_num,i) - cluster_center(1:dim_num,j) ).^2 );\n\n cluster_energy(j) = cluster_energy(j) + point_energy;\n\n end\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/kmeans/cluster_energy_compute.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850128595115, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.8100963412820059}} {"text": "function y = pmean(x,p)\n%Calculates generalized mean\n% x = vector subject to generalized mean calculations. Can be also matrix.\n% p = parameter for generalized mean.\n% y = generalized mean value.\ny = (sum(x.^p,1)/size(x,1)).^(1/p);\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/38871-similarity-classifier-with-owa-operators/SimClassOWA/pmean.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9553191284552528, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.8100798272324625}} {"text": "function pdf = inverse_gaussian_pdf ( x, a, b )\n\n%*****************************************************************************80\n%\n%% INVERSE_GAUSSIAN_PDF evaluates the Inverse Gaussian PDF.\n%\n% Discussion:\n%\n% The Inverse Gaussian PDF is also known as the Wald PDF\n% and the Inverse Normal PDF.\n%\n% PDF(X)(A,B)\n% = SQRT ( B / ( 2 * PI * X**3 ) )\n% * EXP ( - B * ( X - A )**2 / ( 2.0D+00 * A**2 * X ) )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the PDF.\n% 0.0 < X\n%\n% Input, real A, B, the parameters of the PDF.\n% 0.0 < A,\n% 0.0 < B.\n%\n% Output, real PDF, the value of the PDF.\n%\n if ( x <= 0.0 )\n pdf = 0.0;\n else\n pdf = sqrt ( b / ( 2.0 * pi * x^3 ) ) * ...\n exp ( - b * ( x - a )^2 / ( 2.0 * a^2 * x ) );\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/prob/inverse_gaussian_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191284552529, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.8100798217268599}} {"text": "% Chapter 11 - Hamiltonian Systems, Lyapunov Functions, and Stability.\n% Programs_11a - Surface and Contour Plots. Finding Vdot.\n% Copyright Birkhauser 2013. Stephen Lynch.\n\n% The double-well potential (Fig. 11.5(b)).\n% Symbolic Math toolbox required.\nezsurfc('-x^2/2+x^4/4+y^2/2',[-1.5,1.5]);\n\n% Calculating Vdot (Exercise 6).\nclear\nsyms x y V\nV=(1-4*x^2-y^2)^2;\nxdot=-y*(1+x)/2+x*(1-4*x^2-y^2);\nydot=2*x*(1+x)+y*(1-4*x^2-y^2);\nVdot=factor(diff(V,x)*xdot+diff(V,y)*ydot)\n\n% Phase portraits may be plotted using the M-files in Chapter 8.\n% End of Programs_11a.\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/2374-dynamical-systems-with-applications-using-matlab/MATLAB files 20013a/Programs_11a.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9553191271831559, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.8100798206481628}} {"text": "function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters)\n%GRADIENTDESCENT Performs gradient descent to learn theta\n% theta = GRADIENTDESCENT(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 \n predictions = X * theta;\n updates = X' * (predictions - y);\n theta = theta - alpha * (1/m) * updates;\n \n %theta = theta - alpha * (1/m) * sum(sqerrors) * X;\n\n %theta - (alpha/m) * (X' * (X * theta - y));\n\n %theta = theta - (alpha/m) * (X' * (X * theta - y));\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": "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/gradientDescent.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825847, "lm_q2_score": 0.880797068590724, "lm_q1q2_score": 0.8100184494924813}} {"text": "% Section 11.8.4: Network rate optimization\n% Boyd & Vandenberghe \"Convex Optimization\" \n% Argyrios Zymnis - 05/03/08\n%\n% We consider a network with n flows and L links. Each flow i,\n% moves along a fixed predetermined path (i.e. a subset of the links)\n% and has an associated rate x_i. Each link j has an associated capacity\n% c_j. The total rate of all flows travelling along a link cannot exceed\n% the link capacity. We can describe these link capacity limits using the\n% flow-link incidence matrix A \\in \\reals^{L \\times n}, where\n% A_{ij} = 1, if flow j passes through link i and 0 otherwise.\n% The link capacity constraints can be expressed as A*x <= c\n% In the network rate problem the variables are the flow rates x. The\n% objective is to choose the flow rates to maximize a separate utility\n% function U, given by\n% U(x) = U_1(x_1)+U_2(x_2)+...+U_n(x_n)\n% The network rate optimization problem is then\n% maximize U(x)\n% subject to A*x <= c\n% Here we use U_i(x_i) = log x_i for all i\n\n% Input data\nrand('state',1)\nL = 20;\nn = 10;\nk = 7; %average links per flow\nA = double(rand(L,n) <= k/L);\nc = 0.9*rand(L,1)+0.1;\n\n% Solve network rate problem\ncvx_begin\n variable x(n);\n maximize(sum(log(x)))\n subject to\n A*x <= c; %#ok\ncvx_end\nprimal_obj = cvx_optval;\n\n% Solve dual problem to obtain link prices\ncvx_begin\n variable lambda(L);\n minimize(c'*lambda-sum(log(A'*lambda))-n)\n subject to\n lambda >= 0; %#ok\ncvx_end\ndual_obj = cvx_optval;\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/cvxbook/Ch11_intpt_methods/log_utility_flow.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240125464115, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.8099683998987186}} {"text": "% Chebychev design of an FIR filter given a desired H(w)\n% \"Filter design\" lecture notes (EE364) by S. Boyd\n% (figures are generated)\n%\n% Designs an FIR filter given a desired frequency response H_des(w).\n% The design is judged by the maximum absolute error (Chebychev norm).\n% This is a convex problem (after sampling it can be formulated as an SOCP).\n%\n% minimize max |H(w) - H_des(w)| for w in [0,pi]\n%\n% where H is the frequency response function and variable is h\n% (the filter impulse response).\n%\n% Written for CVX by Almir Mutapcic 02/02/06\n\n%********************************************************************\n% problem specs\n%********************************************************************\n% number of FIR coefficients (including the zeroth one)\nn = 20;\n\n% rule-of-thumb frequency discretization (Cheney's Approx. Theory book)\nm = 15*n;\nw = linspace(0,pi,m)'; % omega\n\n%********************************************************************\n% construct the desired filter\n%********************************************************************\n% fractional delay\nD = 8.25; % delay value\nHdes = exp(-1j*D*w); % desired frequency response\n\n% Gaussian filter with linear phase (uncomment lines below for this design)\n% var = 0.05;\n% Hdes = 1/(sqrt(2*pi*var))*exp(-(w-pi/2).^2/(2*var));\n% Hdes = Hdes.*exp(-j*n/2*w);\n\n%*********************************************************************\n% solve the minimax (Chebychev) design problem\n%*********************************************************************\n% A is the matrix used to compute the frequency response\n% A(w,:) = [1 exp(-j*w) exp(-j*2*w) ... exp(-j*n*w)]\nA = exp( -1j*kron(w,0:n-1) );\n\n% optimal Chebyshev filter formulation\ncvx_begin\n variable h(n,1)\n minimize( max( abs( A*h - Hdes ) ) )\ncvx_end\n\n% check if problem was successfully solved\ndisp(['Problem is ' cvx_status])\nif ~strfind(cvx_status,'Solved')\n h = [];\nend\n\n%*********************************************************************\n% plotting routines\n%*********************************************************************\n% plot the FIR impulse reponse\nfigure(1)\nstem(0:n-1,h)\nxlabel('n')\nylabel('h(n)')\n\n% plot the frequency response\nH = exp(-1j*kron(w,0:n-1))*h;\nfigure(2)\n% magnitude\nsubplot(2,1,1);\nplot(w,20*log10(abs(H)),w,20*log10(abs(Hdes)),'--')\nxlabel('w')\nylabel('mag H in dB')\naxis([0 pi -30 10])\nlegend('optimized','desired','Location','SouthEast')\n% phase\nsubplot(2,1,2)\nplot(w,angle(H))\naxis([0,pi,-pi,pi])\nxlabel('w'), ylabel('phase H(w)')\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/filter_design/fir_chebychev_design.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240125464115, "lm_q2_score": 0.8633916011860785, "lm_q1q2_score": 0.8099683933035551}} {"text": "function pdf = point_distance_3d_pdf ( x, a, b )\n\n%*****************************************************************************80\n%\n%% POINT_DISTANCE_3D_PDF evaluates the point distance PDF in the 3D.\n%\n% Discussion:\n%\n% It is assumed that a set of points has been generated in 3D\n% according to a Poisson process. The number of points in a region\n% of size VOLUME is a Poisson variate with mean value B * VOLUME.\n%\n% For a point chosen at random, we may now find the nearest\n% Poisson point, the second nearest and so on. We are interested\n% in the PDF that governs the expected behavior of the distances\n% of rank A = 1, 2, 3, ... with Poisson density B.\n%\n% Formula:\n%\n% PDF(X)(A,B) = 3 * ( (4/3) * B * PI )**A * X**( 3 * A - 1 )\n% * EXP ( - (4/3) * B * PI * X * X * X ) / ( A - 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% Daniel Zwillinger, editor,\n% CRC Standard Mathematical Tables and Formulae,\n% 30th Edition,\n% CRC Press, 1996, pages 580.\n%\n% Parameters:\n%\n% Input, real X, the argument of the PDF.\n% 0.0 <= X.\n%\n% Input, integer A, indicates the degree of nearness of the point.\n% A = 1 means the nearest point, A = 2 the second nearest, and so on.\n% 0 < A.\n%\n% Input, real B, the Poisson point density. 0.0 < B.\n%\n% Output, real PDF, the value of the PDF.\n%\n if ( a < 1 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'POINT_DISTANCE_3D_PDF - Fatal error!\\n' );\n fprintf ( 1, ' Input parameter A < 1.\\n' );\n error ( 'POINT_DISTANCE_3D_PDF - Fatal error!' );\n end\n\n if ( b <= 0.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'POINT_DISTANCE_3D_PDF - Fatal error!\\n' );\n fprintf ( 1, ' Input parameter B <= 0.0.\\n' );\n error ( 'POINT_DISTANCE_3D_PDF - Fatal error!' );\n end\n\n if ( x < 0.0 )\n pdf = 0.0;\n else\n pdf = 3.0 * ( ( 4.0 / 3.0 ) * b * pi )^a ...\n * x^( 3 * a - 1 ) * exp ( - ( 4.0 / 3.0 ) * b * pi * x^3 ) ...\n / i4_factorial ( a - 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/prob/point_distance_3d_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381606, "lm_q2_score": 0.877476793890012, "lm_q1q2_score": 0.8099454502437676}} {"text": "function [g,tfr]=pgauss(L,varargin)\n%PGAUSS Sampled, periodized Gaussian\n% Usage: g=pgauss(L);\n% g=pgauss(L,tfr);\n% g=pgauss(L,...);\n% [g,tfr]=pgauss( ... );\n% \n% Input parameters:\n% L : Length of vector.\n% tfr : ratio between time and frequency support.\n%\n% Output parameters:\n% g : The periodized Gaussian.\n%\n% `pgauss(L,tfr)` computes samples of a periodized Gaussian. The function\n% returns a regular sampling of the periodization of the function\n% $exp(-pi*(x.^2/tfr))$.\n%\n% The $l^2$ norm of the returned Gaussian is equal to 1.\n%\n% The parameter *tfr* determines the ratio between the effective support\n% of *g* and the effective support of the DFT of *g*. If $tfr>1$ then *g*\n% has a wider support than the DFT of *g*.\n%\n% `pgauss(L)` does the same setting *tfr=1*.\n%\n% `[g,tfr] = pgauss( ... )` will additionally return the time-to-frequency\n% support ratio. This is useful if you did not specify it (i.e. used the\n% `'width'` or `'bw'` flag).\n%\n% The function is whole-point even. This implies that `fft(pgauss(L,tfr))`\n% is real for any *L* and *tfr*. The DFT of *g* is equal to\n% `pgauss(L,1/tfr)`.\n%\n% In addition to the `'width'` flag, `pgauss` understands the following\n% flags at the end of the list of input parameters:\n%\n% 'fs',fs Use a sampling rate of *fs* Hz as unit for specifying the\n% width, bandwidth, centre frequency and delay of the\n% Gaussian. Default is *fs=[]* which indicates to measure\n% everything in samples.\n%\n% 'width',s Set the width of the Gaussian such that it has an\n% effective support of *s* samples. This means that\n% approx. 96% of the energy or 79% of the area\n% under the graph is contained within *s* samples. \n% This corresponds to -6dB or to width at the\n% half of the height. \n% This is equivalent to calling `pgauss(L,pi*s^2/4L*log(2))`.\n%\n% 'atheight',ah Used only in conjuction with 'width'. Forces the \n% Gaussian to width *s* at the *ah* fraction of the\n% height.\n%\n% 'bw',bw As for the `'width'` argument, but specifies the width\n% in the frequency domain. The bandwidth is measured in \n% normalized frequencies, unless the `'fs'` value is given.\n%\n% 'cf',cf Set the centre frequency of the Gaussian to *fc*. \n%\n% 'wp' Output is whole point even. This is the default.\n%\n% 'hp' Output is half point even, as most Matlab filter\n% routines.\n%\n% 'delay',d Delay the output by *d*. Default is zero delay.\n%\n% In addition to these parameteres, `pgauss` accepts any of the flags\n% from |setnorm|. The output will be normalized as specified.\n%\n% If this function is used to generate a window for a Gabor frame, then\n% the window giving the smallest frame bound ratio is generated by\n% `pgauss(L,a*M/L)`.\n%\n% Examples:\n% ---------\n%\n% This example creates a Gaussian function, and demonstrates that it is\n% its own Discrete Fourier Transform:::\n%\n% g=pgauss(128);\n%\n% % Test of DFT invariance: Should be close to zero.\n% norm(g-dft(g))\n% \n% The next plot shows the Gaussian in the time domain:::\n%\n% plot(fftshift(pgauss(128)));\n% \n% The next plot shows the Gaussian in the frequency domain on a log scale:::\n%\n% magresp(pgauss(128),'dynrange',100);\n% \n% The next plot shows the Gaussian in the time-frequency plane:::\n% \n% sgram(pgauss(128),'tc','nf','lin');\n%\n% See also: dgtlength, psech, firwin, pbspline, setnorm\n%\n% Demos: demo_pgauss\n%\n% References: mazh93\n\n% AUTHOR : Peter L. Søndergaard.\n\n% First reference on this found in mazh93 eq. 63\n\nif nargin<1\n error('Too few input parameters.');\nend;\n\nif (prod(size(L,1))~=1 || ~isnumeric(L))\n error('L must be a scalar');\nend;\n\nif rem(L,1)~=0\n error('L must be an integer.')\nend;\n\n% Define initial value for flags and key/value pairs.\ndefinput.import={'setnorm'};\n\ndefinput.flags.centering={'wp','hp'};\ndefinput.flags.delay={'nodelay','delay'};\ndefinput.flags.width={'tfr','width','bw'};\n\ndefinput.keyvals.tfr=1;\ndefinput.keyvals.delay=0;\ndefinput.keyvals.width=0;\ndefinput.keyvals.fs=[];\ndefinput.keyvals.cf=0;\ndefinput.keyvals.bw=0;\ndefinput.keyvals.atheight=[];\n\n[flags,keyvals,tfr]=ltfatarghelper({'tfr'},definput,varargin);\n\nif (prod(size(tfr,1))~=1 || ~isnumeric(tfr))\n error('tfr must be a scalar.');\nend;\n\nif ~isempty(keyvals.atheight) && ~flags.do_width\n error(['%s: Param. ''atheight'' must be used together with param.',...\n ' ''width''. '],upper(mfilename));\nend\n\nif isempty(keyvals.atheight)\n keyvals.atheight = 0.5;\nend\n\nif keyvals.atheight >= 1 || keyvals.atheight <=0\n error('%s: Param. ''atheight'' must be in the range ]0,1[.',...\n upper(mfilename));\nend\n\n\nfs=keyvals.fs;\n\nif flags.do_wp\n cent=0;\nelse\n cent=0.5;\nend;\n\nif isempty(fs)\n \n if flags.do_width\n tfr=pi/(4*log(1/keyvals.atheight))*keyvals.width^2/L; \n end;\n \n if flags.do_bw\n tfr=L/(keyvals.bw*L/2)^2;\n end;\n \n delay_s=keyvals.delay;\n cf_s =keyvals.cf;\nelse\n \n if flags.do_width\n tfr=(keyvals.width*fs)^2/L;\n end;\n\n if flags.do_bw\n tfr=L/(keyvals.bw/fs*L)^2;\n end;\n \n delay_s=keyvals.delay*fs;\n cf_s =keyvals.cf/fs*L;\nend;\n\ng=comp_pgauss(L,tfr,cent-delay_s,cf_s);\n\ng=setnorm(g,flags.norm);\n\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/fourier/pgauss.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8774767922879693, "lm_q1q2_score": 0.8099454487650193}} {"text": "function [J, grad] = costFunction(theta, X, y)\n%COSTFUNCTION Compute cost and gradient for logistic regression\n% J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the\n% parameter for logistic regression and the gradient of the cost\n% w.r.t. to the parameters.\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\ngrad = zeros(size(theta));\n\nh = sigmoid(X*theta);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n% Note: grad should have the same dimensions as theta\n%\n\nJ = (-y'*log(h)-(1-y)'*log(1-h))/m;\n\ngrad = X'*(h-y)/m;\n\n\n\n\n\n\n% =============================================================\n\nend\n", "meta": {"author": "lawlite19", "repo": "MachineLearningEx", "sha": "44be60fe4d639d18af5ea5011f069eed348e97b8", "save_path": "github-repos/MATLAB/lawlite19-MachineLearningEx", "path": "github-repos/MATLAB/lawlite19-MachineLearningEx/MachineLearningEx-44be60fe4d639d18af5ea5011f069eed348e97b8/machine-learning-ex2/ex2/costFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088084787998, "lm_q2_score": 0.8723473846343393, "lm_q1q2_score": 0.8098949959479642}} {"text": "function q = sphere_stereograph2 ( p, focus, center )\n\n%*****************************************************************************80\n%\n%% SPHERE_STEREOGRAPH2 computes the stereographic image of points on a sphere.\n%\n% Discussion:\n%\n% We start with a sphere of center C.\n%\n% F is a point on the sphere which is the focus of the mapping,\n% and the antipodal point 2*C-F is the point of tangency\n% to the sphere of a plane.\n%\n% For any point P on the sphere, the stereographic projection Q of the\n% point is defined by drawing the line from F through P, and computing\n% Q as the intersection of this line with the plane.\n%\n% The spatial dimension M is arbitrary, but should be at least 2.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 11 November 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% C F Marcus,\n% The stereographic projection in vector notation,\n% Mathematics Magazine,\n% Volume 39, Number 2, March 1966, pages 100-102.\n%\n% Parameters:\n%\n% Input, real P(M,N), a set of points on the unit sphere.\n%\n% Input, real FOCUS(M,1), the coordinates of the focus point.\n%\n% Input, real CENTER(M,1), the coordinates of the center of the sphere.\n%\n% Output, real Q(M,N), the coordinates of the image points,\n%\n [ m, n ] = size ( p );\n\n ff = repmat ( focus, 1, n );\n\n s(1,1:n) = 2.0 * sum ( ( center - focus ).^2 ) ...\n ./ ( ( center - focus )' * ( p - ff ) );\n\n ss = repmat ( s, m, 1 );\n\n q = ss .* p + ( 1.0 - ss ) .* ff;\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_stereograph/sphere_stereograph2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171238, "lm_q2_score": 0.8723473779969194, "lm_q1q2_score": 0.8098949863297675}} {"text": "function jac = p21_jac ( neqn, t, y )\n\n%*****************************************************************************80\n%\n%% P21_JAC evaluates the jacobian for problem p21.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 23 February 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NEQN, the number of equations.\n%\n% Input, real T, Y(NEQN), the arguments of the jacobian.\n%\n% Output, real JAC(NEQN,NEQN), the jacobian matrix.\n%\n jac = zeros ( neqn, neqn );\n\n jac(1,1) = 0.0;\n jac(1,2) = 1.0;\n\n jac(2,1) = - 1.0 + 0.25 / ( t + 1.0 ).^2;\n jac(2,2) = - 1.0 / ( t + 1.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/test_ode/p21_jac.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.8723473779969194, "lm_q1q2_score": 0.8098949828738096}} {"text": "function [ r, center ] = circle_dia2imp_2d ( p1, p2 )\n\n%*****************************************************************************80\n%\n%% CIRCLE_DIA2IMP_2D converts a diameter to an implicit circle in 2D.\n%\n% Discussion:\n%\n% The diameter form of a circle is:\n%\n% P1 and P2 are the endpoints of a diameter.\n%\n% The implicit form of a circle in 2D is:\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% 04 December 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real P1(2,1), P2(2,1), two points that are the\n% endpoints of a diameter of the circle.\n%\n% Output, real R, the radius of the circle.\n%\n% Output, real CENTER(2,1), the center of the circle.\n%\n r = 0.5 * sqrt ( sum ( ( p2(1:2,1) - p1(1:2,1) ).^2 ) );\n\n center(1:2,1) = 0.5 * ( p1(1:2,1) + p2(1:2,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/geometry/circle_dia2imp_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087926320944, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.8098949713402137}} {"text": "% P3.11\ncolordef white; clear; clc;\nM = 250; k = -M:M; w = (pi/M)*k; % [0, pi] axis divided into 501 points.\nw0 = pi/2; figure(1); \nn = -50:50;\n\nh = (0.9).^(abs(n)); \nH = dtft(h,n,w); \nsubplot(3,2,1); plot(w/pi,abs(H),'k');\nxlabel('frequency in pi units'); ylabel('|H|'); title('Magnitude Response');\nsubplot(3,2,2); plot(w/pi,angle(H)/pi,'k'); \nxlabel('frequency in pi units'); ylabel('\\Theta'); title('Phase Response');\n\nh = sinc(0.2*n).*((stepseq(-20,-50,50)-stepseq(20,-50,50)));\nH = dtft(h,n,w);\nsubplot(3,2,3); plot(w/pi,abs(H),'k');\nxlabel('frequency in pi units'); ylabel('|H|'); title('Magnitude Response');\nsubplot(3,2,4); plot(w/pi,angle(H)/pi,'k'); \nxlabel('frequency in pi units'); ylabel('\\Theta'); title('Phase Response');\n\nh = sinc(0.2*n).*((stepseq(0,-50,50)-stepseq(40,-50,50))); \nH = dtft(h,n,w);\nsubplot(3,2,5); plot(w/pi,abs(H),'k');\nxlabel('frequency in pi units'); ylabel('|H|'); title('Magnitude Response');\nsubplot(3,2,6); plot(w/pi,angle(H)/pi,'k'); \nxlabel('frequency in pi units'); ylabel('\\Theta'); title('Phase Response');\n\nfigure(2); \nh = ((0.5).^n+(0.4).^n).*stepseq(0,-50,50); \nH = dtft(h,n,w);\nsubplot(3,2,1); plot(w/pi,abs(H),'k');\nxlabel('frequency in pi units'); ylabel('|H|'); title('Magnitude Response');\nsubplot(3,2,2); plot(w/pi,angle(H)/pi,'k'); \nxlabel('frequency in pi units'); ylabel('\\Theta'); title('Phase Response');\n\nh = (0.5).^(abs(n)).*cos(0.1*pi*n); \nH = dtft(h,n,w);\nsubplot(3,2,3); plot(w/pi,abs(H),'k');\nxlabel('frequency in pi units'); ylabel('|H|'); title('Magnitude Response');\nsubplot(3,2,4); plot(w/pi,angle(H)/pi,'k'); \nxlabel('frequency in pi units'); ylabel('\\Theta'); title('Phase Response');", "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/16353-ingle-proakis-chapter-3-solutions/P311.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768635777511, "lm_q2_score": 0.8577681104440171, "lm_q1q2_score": 0.8098848041960461}} {"text": "function Y = inv_chol(L)\n% Matrix Inversion using Cholesky Decomposition\n%\n% Finds the inverse of the matrix X, given its (lower triangular) Cholesky\n% Decomposition; i.e. X = LL', according to the paper 'Matrix Inversion\n% Using Cholesky Decomposition', Aravindh Krishnamoorthy, Deepak Menon,\n% arXiv:1111.4144.\n%\n\n% Version 0.1, 2013-05-25, Aravindh Krishnamoorthy\n% e-mail: aravindh.k@ieee.org\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Initializations\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nN = size(L, 1) ;\nY = zeros(N, N) ;\n% Work with the upper triangular matrix\nR = L' ;\n% Construct the auxillary diagonal matrix S = 1/rii\nS = inv(diag(diag(R))) ;\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Algorithm\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nfor j=N:-1:1\n for i=j:-1:1\n Y(i,j) = S(i,j) - R(i,i+1:end)*Y(i+1:end,j) ;\n Y(i,j) = Y(i,j)/R(i,i) ;\n % Write out the symmetric element\n Y(j,i) = conj(Y(i,j)) ;\n end\nend\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Test\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% N = 4 ;\n% X = complex(randn(N, N), randn(N, N)) ;\n% X = X'*X ;\n% L = chol(X, 'lower') ;\n% I = inv_chol(L) ;\n% norm(I-inv(X))\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/41957-matrix-inversion-using-cholesky-decomposition/inv_chol.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768651485395, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.809884798677473}} {"text": "function vol=elemvolume(node,elem,option)\n%\n% vol=elemvolume(node,elem,option)\n%\n% calculate the volume for a list of simplexes\n%\n% author: Qianqian Fang (fangq nmr.mgh.harvard.edu)\n% date: 2007/11/21\n%\n% input:\n% node: node coordinates\n% elem: element table of a mesh\n% option: if option='signed', the volume is the raw determinant,\n% else, the results will be the absolute values\n%\n% output:\n% vol: volume values for all elements\n%\n% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)\n%\n\nif(size(elem,2)==size(node,2))\n\tenum=size(elem,1);\n\tvol=zeros(enum,1);\n\tacol=ones(3,1);\n\tfor i=1:enum\n\t\te1=det([node(elem(i,:),2),node(elem(i,:),3),acol]);\n\t\te2=det([node(elem(i,:),3),node(elem(i,:),1),acol]);\n\t\te3=det([node(elem(i,:),1),node(elem(i,:),2),acol]);\n\t\tvol(i)=sqrt(e1*e1+e2*e2+e3*e3)/2;\n\tend\n\treturn;\nend\ndim=size(elem,2);\nenum=size(elem,1);\nvol=zeros(enum,1);\nfor i=1:enum\n detmat=[node(elem(i,:),:)';ones(1,dim)];\n vol(i)=det(detmat);\nend\nif(nargin==3 && strcmp(option,'signed'))\n vol=vol/prod(1:size(node,2));\nelse\n vol=abs(vol)/prod(1:size(node,2));\nend\n", "meta": {"author": "goodshawn12", "repo": "REST", "sha": "e34ce521fcb36e7813357a9720072dd111edf797", "save_path": "github-repos/MATLAB/goodshawn12-REST", "path": "github-repos/MATLAB/goodshawn12-REST/REST-e34ce521fcb36e7813357a9720072dd111edf797/dependencies/iso2mesh/elemvolume.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.8098847967209567}} {"text": "function [ i, j ] = i4_to_triangle ( k )\n\n%*****************************************************************************80\n%\n%% I4_TO_TRIANGLE converts an integer to triangular coordinates.\n%\n% Discussion:\n%\n% Triangular coordinates are handy when storing a naturally triangular\n% array (such as the lower half of a matrix) in a linear array.\n%\n% Thus, for example, we might consider storing\n%\n% (1,1)\n% (2,1) (2,2)\n% (3,1) (3,2) (3,3)\n% (4,1) (4,2) (4,3) (4,4)\n%\n% as the linear array\n%\n% (1,1) (2,1) (2,2) (3,1) (3,2) (3,3) (4,1) (4,2) (4,3) (4,4)\n%\n% Here, the quantities in parenthesis represent the natural row and\n% column indices of a single number when stored in a rectangular array.\n%\n% In this routine, we are given the location K of an item in the\n% linear array, and wish to determine the row I and column J\n% of the item when stored in the triangular array.\n%\n% First Values:\n%\n% K I J\n%\n% 0 0 0\n% 1 1 1\n% 2 2 1\n% 3 2 2\n% 4 3 1\n% 5 3 2\n% 6 3 3\n% 7 4 1\n% 8 4 2\n% 9 4 3\n% 10 4 4\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 26 July 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer K, the linear index of the (I,J) element, which\n% must be nonnegative.\n%\n% Output, integer I, J, the row and column indices.\n%\n if ( k < 0 )\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'I4_TO_TRIANGLE - Fatal error!\\n' );\n fprintf ( 1, ' K < 0.\\n' );\n fprintf ( 1, ' K = %d\\n', k );\n error ( 'I4_TO_TRIANGLE - Fatal error!' );\n\n elseif ( k == 0 )\n\n i = 0;\n j = 0;\n return\n\n end\n\n i = floor ( sqrt ( 2 * k ) );\n\n if ( i * i + i < 2 * k )\n i = i + 1;\n end\n\n j = k - ( i * ( i - 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/polpak/i4_to_triangle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8887588038050466, "lm_q1q2_score": 0.8098189869779036}} {"text": "function c = tone2cent(t1,t2)\n% MUSIC.TONE2CENT Returns the number of cents between two semitones.\n% C = MUSIC.TONE2CENT(T) returns the number of cents between T and middle C\n% (C4). T is a semitone interval defined relative to C4.\n%\n% C = MUSIC.TONE2CENT(T1,T2) returns the number of cents between T1 and T2.\n% T1 and T2 are musical semitones defined relative to C4. T1 and T2 may be\n% vectors of the same size, or one may be scalar.\n%\n% Examples\n% c = music.tone2cent(12); % returns 1200\n% c = music.tone2cent(-3,-1); % returns 200\n% c = music.tone2cent([-3 9],-1); % returns [200 -1000]\n%\n% See also music.tone2freq, music.tone2interval, music.tone2note.\n\n% Author: E. Johnson\n% Copyright 2010 The MathWorks, Inc.\n\n\nif nargin < 2\n t2 = t1;\n t1 = 0;\nend\n\nf1 = music.tone2freq(t1);\nf2 = music.tone2freq(t2);\n\n% Could call MUSIC.FREQ2TONE but it is easy to inline this simple calclation.\nc = 1200 * log2( f2 ./ f1 );", "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/26509-musical-notes/Pitch/+music/tone2cent.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109770159682, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.8097053020352765}} {"text": "function dist = sphere_distance2 ( lat1, lon1, lat2, lon2, r )\n\n%*****************************************************************************80\n%\n%% SPHERE_DISTANCE2 computes great circle distances on a sphere.\n%\n% Discussion:\n%\n% This computation is written in terms of haversines, and can be more\n% accurate when measuring small angular distances. It can be somewhat\n% inaccurate when the two points are antipodal.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 February 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% \"Great-circle distance\",\n% Wikipedia.\n%\n% Parameters:\n%\n% Input, real LAT1, LON1, the latitude and longitude of\n% the first point.\n%\n% Input, real LAT2, LON2, the latitude and longitude of\n% the second point.\n%\n% Input, real R, the radius of the sphere.\n%\n% Output, real DIST, the great circle distance between\n% the points, measured in the same units as R.\n%\n s = ( sin ( ( lat1 - lat2 ) / 2.0 ) ).^2 ...\n + cos ( lat1 ) * cos ( lat2 ) * ( sin ( ( lon1 - lon2 ) / 2.0 ) ).^2;\n\n s = sqrt ( s );\n\n dist = 2.0 * r * asin ( 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/geometry/sphere_distance2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109784205502, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.809705290728019}} {"text": "function p = kspaceLineRecon(p, dy, dt, c, varargin)\n%KSPACELINERECON 2D linear FFT reconstruction.\n%\n% DESCRIPTION:\n% kspaceLineRecon takes an acoustic pressure time-series p_ty\n% recorded over an evenly spaced array of sensor points on a line,\n% and constructs an estimate of the initial acoustic pressure\n% distribution that gave rise to those measurements using an\n% algorithm based on the FFT. The input p_ty must be indexed\n% p_ty(time step, sensor y position), where the sensor spacing is given\n% by dy, the temporal spacing given by dt, and the sound speed in the\n% propagation medium (which is assumed to be acoustically\n% homogeneous) is given by c. The output p_xy is indexed as\n% p_xy(x position, y position).\n%\n% The code uses a k-space algorithm which performs (1) a Fourier\n% transform on the data p_ty along both t and y dimensions (into\n% wavenumber-frequency space, where the wavenumber component is along\n% the detector line), (2) a mapping, based on the dispersion relation\n% for a plane wave in an acoustically homogeneous medium, from\n% wavenumber-frequency space to wavenumber-wavenumber space (where\n% the second component is orthogonal to the detector line), and\n% finally (3) an inverse Fourier transform back from the wavenumber\n% domain to the spatial domain. The result is an estimate of the\n% initial acoustic pressure distribution from which the acoustic\n% waves originated. \n%\n% Steps (1) and (3) can be performed efficiently using the fast\n% Fourier transform (FFT); they are therefore fastest when the number\n% of samples and number of detector points are both powers of 2. The\n% mapping in step (2) requires an interpolation of the data from an\n% evenly spaced grid of points in the wavenumber-frequency domain to\n% an evenly-spaced grid of points in the wavenumber-wavenumber\n% domain. The option 'Interp' may be used to choose the interpolation\n% method.\n%\n% The physics of photoacoustics requires that the acoustic pressure\n% is initially non-negative everywhere. The estimate of the initial\n% pressure distribution generated by this code may have negative\n% regions due to artefacts arising from differences between the\n% assumed model and the real situation, e.g., homogeneous medium vs.\n% real, somewhat heterogeneous, medium; infinite measurement surface\n% vs. finite-sized region-of-detection, etc. A positivity (or\n% non-negativity) condition can be enforced by setting the optional\n% 'PosCond' to true which simply sets any negative parts of the final\n% image to zero. \n%\n% USAGE:\n% p_xy = kspaceLineRecon(p_ty, dy, dt, c)\n% p_xy = kspaceLineRecon(p_ty, dy, dt, c, ...)\n%\n% INPUTS:\n% p_ty - pressure time-series recorded over an evenly spaced\n% array of sensor points on a line (indexed as t, y)\n% dy - spatial step [m]\n% dt - time step [s]\n% c - acoustically-homogeneous sound speed [m/s]\n%\n% OPTIONAL INPUTS:\n% Optional 'string', value pairs that may be used to modify the\n% default computational settings.\n%\n% 'DataOrder' - String input which sets the data order (default =\n% 'ty'). Valid inputs are 'ty' and 'yt'\n% 'Interp' - string input controlling the interpolation method\n% used by interp2 in the reconstruction (default =\n% '*nearest')\n% 'Plot' - Boolean controlling whether a plot of the\n% reconstructed estimate of the initial acoustic\n% pressure distribution is produced (default = false).\n% 'PosCond' - Boolean controlling whether a positivity condition is\n% enforced on the reconstructed estimate of the initial\n% acoustic pressure distribution (default = false).\n%\n% OUTPUTS:\n% p_xy - estimate of the initial acoustic pressure\n% distribution (indexed as x, y)\n%\n% ABOUT:\n% author - Bradley Treeby and Ben Cox\n% date - 11th January 2009\n% last update - 13th August 2014\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% See also interp2, kspacePlaneRecon, makeGrid\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% Error: interp2 error in Matlab R2012b\nmatlab_ver = ver('matlab'); \nif strcmp(matlab_ver.Release, '(R2012b)')\n error('This function will not run in Matlab R2012b because of a bug in Matlab''s function interp2. It does work in prior and subsequent versions of Matlab.')\nend\n\n% start timer\ntic;\n\n% define defaults\nnum_req_inputs = 4;\ndata_order = 'ty';\ninterp_method = '*nearest';\nplot_recon = false;\npositivity_cond = false;\n\n% replace with user defined values if provided\nif nargin < num_req_inputs\n error('Incorrect number of inputs');\nelseif ~isempty(varargin)\n for input_index = 1:2:length(varargin)\n switch varargin{input_index}\n case 'DataOrder'\n data_order = varargin{input_index + 1};\n if ~strcmp(data_order, 'ty') && ~strcmp(data_order, 'yt')\n error('Unknown setting for optional input DataOrder');\n end\n case 'Interp'\n interp_method = varargin{input_index + 1};\n case 'Plot'\n plot_recon = varargin{input_index + 1}; \n case 'PlotRecon'\n plot_recon = varargin{input_index + 1};\n case 'PosCond'\n positivity_cond = varargin{input_index + 1}; \n otherwise\n error('Unknown optional input');\n end\n end\nend\n\n% reorder the data if needed (p_ty)\nif strcmp(data_order, 'yt')\n p = p.';\nend\n\n% mirror the time domain data about t = 0 to allow the cosine transform to\n% be computed using an FFT (p_ty)\np = [flipdim(p, 1); p(2:end, :)];\n\n% extract the size of mirrored input data\n[Nt, Ny] = size(p);\n\n% update command line status\ndisp('Running k-Wave line reconstruction...');\ndisp([' grid size: ' num2str(Ny) ' by ' num2str((Nt+1)/2) ' grid points']);\ndisp([' interpolation mode: ' interp_method]);\n\n% create a computational grid that is evenly spaced in w and ky, where \n% Nx = Nt and dx = dt*c\nkgrid = makeGrid(Nt, dt*c, Ny, dy);\n\n% from the grid for kx, create a computational grid for w using the\n% relation dx = dt*c; this represents the initial sampling of p(w, ky)\nw = c*kgrid.kx;\n\n% remap the computational grid for kx onto w using the dispersion\n% relation w/c = (kx^2 + ky^2)^1/2. This gives an w grid that is\n% evenly spaced in kx. This is used for the interpolation from p(w, ky)\n% to p(kx, ky). Only real w is taken to force kx (and thus x) to be\n% symmetrical about 0 after the interpolation. \nw_new = (c*kgrid.k);\n\n% calculate the scaling factor using the value of kx, where\n% kx = sqrt( (w/c).^2 - kgrid.ky.^2 ) and then manually\n% replacing the DC value with its limit (otherwise NaN results) \nsf = c^2*sqrt( (w/c).^2 - kgrid.ky.^2)./(2*w);\nsf(w == 0 & kgrid.ky == 0) = c/2;\n\n% compute the FFT of the input data p(t, y) to yield p(w, ky) and scale\np = sf.*fftshift(fftn(fftshift(p)));\n\n% remove unused variables\nclear sf;\n\n% exclude the inhomogeneous part of the wave\np(abs(w) < abs(c*kgrid.ky)) = 0;\n\n% compute the interpolation from p(w, ky) to p(kx, ky)and then force to be\n% symmetrical \np = interp2(kgrid.ky, w, p, kgrid.ky, w_new, interp_method);\n\n% remove unused variables\nclear kgrid w;\n\n% set values outside the interpolation range to zero\np(isnan(p)) = 0;\n\n% compute the inverse FFT of p(kx, ky) to yield p(x, y)\np = real(ifftshift(ifftn(ifftshift(p))));\n\n% remove the left part of the mirrored data which corresponds to the\n% negative part of the mirrored time data\np = p( (Nt + 1)/2:Nt, :);\n\n% correct the scaling - the forward FFT is computed with a spacing of dt\n% and the reverse requires a spacing of dy = dt*c, the reconstruction\n% assumes that p0 is symmetrical about y, and only half the plane collects\n% data (first approximation to correcting the limited view problem)\np = 2*2*p./c;\n\n% enfore positivity condition\nif positivity_cond\n disp(' applying positivity condition...');\n p(p < 0) = 0;\nend\n\n% update command line status\ndisp([' computation completed in ' scaleTime(toc)]);\n\n% plot the reconstruction\nif plot_recon\n \n % allocate axis dimensions\n x_axis = [0 (Nt/2)*dt*c]; \n y_axis = [0 Ny*dy];\n \n % select suitable axis scaling factor\n [x_sc, scale, prefix] = scaleSI(max([Ny*dy, (Nt/2)*dt*c])); \n \n % select suitable plot scaling factor\n plot_scale = max(p(:));\n \n % create the figure\n figure;\n imagesc(y_axis*scale, x_axis*scale, p, [-plot_scale, plot_scale]);\n axis image;\n colormap(getColorMap);\n xlabel(['Sensor Position [' prefix 'm]']);\n ylabel(['Depth [' prefix 'm]']);\n colorbar;\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/kspaceLineRecon.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.952574122783325, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.809660550663286}} {"text": "function a = prolate ( alpha, n )\n\n%*****************************************************************************80\n%\n%% PROLATE returns the PROLATE matrix.\n%\n% Formula:\n%\n% If ( I == J )\n% A(I,J) = 2 * ALPHA\n% else\n% K = abs ( I - J ) + 1\n% A(I,J) = sin ( 2 * pi * ALPHA * K ) / ( pi * K )\n%\n% Example:\n%\n% N = 5, ALPHA = 0.25\n%\n% 0.5 0.0 -0.106103 0.0 0.0636620\n% 0.0 0.5 0.0 -0.106103 0.0\n% -0.106103 0.0 0.5 0.0 -0.106103\n% 0.0 -0.106103 0.0 0.5 0.0\n% 0.0636620 0.0 -0.106103 0.0 0.5\n%\n% 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% A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\n%\n% A is centrosymmetric: A(I,J) = A(N+1-I,N+1-J).\n%\n% A is Toeplitz: constant along diagonals.\n%\n% If 0 < ALPHA < 0.5, then\n% A is positive definite,\n% the eigenvalues of A are distinct,\n% the eigenvalues lie in (0,1) and cluster around 0 and 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% 19 October 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% James Varah,\n% The Prolate Matrix,\n% Linear Algebra and Applications,\n% Volume 187, pages 269-278, 1993.\n%\n% Parameters:\n%\n% Input, real ALPHA, the parameter.\n%\n% Input, integer N, the order of A.\n%\n% Output, real A(N,N), the matrix.\n%\n a = zeros ( n, n );\n\n for i = 1 : n\n\n for j = 1 : n\n\n if ( i == j )\n a(i,j) = 2.0 * alpha;\n else\n k = abs ( i - j ) + 1;\n angle = 2.0 * pi * alpha * k;\n a(i,j) = sin ( angle ) / ( pi * k );\n end\n\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/prolate.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.9019206679615432, "lm_q1q2_score": 0.809649937483391}} {"text": "function value = trinomial ( i, j, k )\n\n%*****************************************************************************80\n%\n%% TRINOMIAL computes a trinomial coefficient.\n%\n% Location:\n%\n% http://people.sc.fsu.edu/~jburkardt/m_src/triangle_integrals/trinomial.m\n%\n% Discussion:\n%\n% The trinomial coefficient is a generalization of the binomial\n% coefficient. It may be interpreted as the number of combinations of\n% N objects, where I objects are of type 1, J of type 2, and K of type 3.\n% and N = I + J + K.\n%\n% T(I,J,K) = N! / ( I! J! K! )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 11 April 2015\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer I, J, K, the factors.\n% All should be nonnegative.\n%\n% Output, integer VALLUE, the trinomial coefficient.\n%\n\n%\n% Each factor must be nonnegative.\n%\n if ( i < 0 || j < 0 || k < 0 ) \n fprintf ( 1, '\\n' );\n fprintf ( 1, 'TRINOMIAL - Fatal error%\\n' );\n fprintf ( 1, ' Negative factor encountered.\\n' );\n error ( 'TRINOMIAL - Fatal error%' );\n end\n\n value = 1;\n\n t = 1;\n\n for l = 1 : i\n% value = value * t / l;\n t = t + 1;\n end\n\n for l = 1 : j\n value = value * t / l;\n t = t + 1;\n end\n\n for l = 1 : k\n value = value * t / l;\n t = t + 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/triangle_integrals/trinomial.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8872045907347108, "lm_q1q2_score": 0.8095175461024522}} {"text": "function G = filterGauss( dims, mu, C, show )\n% n-dimensional Gaussian filter.\n%\n% Creates an image of a Gaussian with arbitrary covariance matrix. The\n% dimensionality and size of the filter is determined by dims (eg dims=[10\n% 10] creates a 2D filter of size 10x10). If mu==[], it is calculated to be\n% the center of the n-dim image. C can be a full nxn covariance matrix, or\n% an nx1 vector of variance. In the latter case C is calculated as\n% C=diag(C). If C=[]; then C=(dims/6).^2, ie it is transformed into a\n% vector of variances such that along each dimension the variance is equal\n% to (siz/6)^2.\n%\n% USAGE\n% G = filterGauss( dims, [mu], [C], [show] )\n%\n% INPUTS\n% dims - n element vector of dimensions of final Gaussian\n% mu - [] n element vector specifying the mean\n% C - [] nxn cov matrix, nx1 set of vars, or variance\n% show - [0] figure to use for optional display\n%\n% OUTPUTS\n% G - image of the created Gaussian\n%\n% EXAMPLE\n% g = filterGauss( 21, [], 4, 1); %1D\n% sig=3; G = filterGauss( 4*[sig sig] + 1, [], [sig sig].^2, 2 ); %2D\n% R = rotationMatrix( [1,1,0], pi/4 );\n% C = R'*[10^2 0 0; 0 5^2 0; 0 0 16^2]*R;\n% G3 = filterGauss( [51,51,51], [], C, 3 ); %3D\n%\n% See also NORMPDF2\n%\n% Piotr's Image&Video Toolbox Version 2.0\n% Copyright 2012 Piotr Dollar. [pdollar-at-caltech.edu]\n% Please email me if you find bugs, or have suggestions or questions!\n% Licensed under the Simplified BSD License [see external/bsd.txt]\n\nnd = length( dims );\nif( nargin<2 || isempty(mu)); mu=(dims+1)/2; end\nif( nargin<3 || isempty(C)); C=(dims/6).^2; end\nif( nargin<4 || isempty(show) ); show=0; end\n\nif( length(mu)~=nd ); error('invalid mu'); end\n\nif( nd==1 ) % fast special case\n xs = 1:dims(1);\n G = exp(-(xs-mu).*(xs-mu)/(2*C))';\n\nelse\n % make C have correct dimensions\n if( numel(C)==1 ); C=repmat(C,[1 nd]); end\n if( size(C,1)==1 || size(C,2)==1 ); C=diag(C); end\n if( any(size(C)~=nd)); error( 'invalid C'); end\n\n % get vector of grid locations\n temp = cell(1,nd);\n for d=1:nd; temp{d} = 1:dims(d); end\n [ temp{:}] = ndgrid( temp{:} );\n xs = zeros( nd, prod(dims) );\n for d=1:nd; xs( d, : ) = temp{d}(:)'; end\n\n % evaluate the Gaussian at those points\n G = normpdf2( xs, mu, C );\n if( nd>1 ); G = reshape( G, dims ); end\nend\n\n% suppress very small values and normalize\nG(G it takes 99 seconds to run\n\n%NOTE: for each image, please also read its CORRESPONDING 'clean' or\n%reference image. We will need this later to do some analysis\n%NOTE2: the noise level is different for each image (it is 20, 10, and 5 as\n%indicated in the image file names)\n%NOTE3 : all the functions to denoise the image work both with grayscale\n%images and with RGB images\n\n%Load the image to denoise and the refernce image \nimageNoisy = imread('images/alleyNoisy_sigma20.png');\nimageReference = imread('images/alleyReference.png');\n\n% converting the image in grayscale is much faster roughly 3 times faster\nimageNoisy = rgb2gray(imageNoisy);\nimageReference = rgb2gray(imageReference);\n\n% we can resize the image so the code can run even faster\n%imageNoisy = imresize(imageNoisy, 0.5);\n%imageReference = imresize(imageReference, 0.5);\n\n\n% Implement the non-local means functions and compare the performances\n\n%############################## SIGMA = 20 ######################\n% tic\n% filtered = nonLocalMeansWithoutIntegral(imageNoisy, sigma, h, patchSize, windowSize, false); \n% toc\n% \n% figure('name', 'NL-Means Denoised Image with Naive Approach -- SIGMA = 20 h = 0.55');\n% imshow(filtered);\n\ntic\nfiltered = nonLocalMeans(imageNoisy, sigma, h, patchSize, windowSize, false); \ntoc\n\nfigure('name', 'NL-Means Denoised Image with Integral Images Approach -- SIGMA = 20 h = 1');\nimshow(filtered);\n\nh = 0.15;\n\n% tic\n% filtered = nonLocalMeansWithoutIntegral(imageNoisy, sigma, h, patchSize, windowSize, false); \n% toc\n% \n% figure('name', 'NL-Means Denoised Image with Naive Approach -- SIGMA = 20 h = 0.25');\n% imshow(filtered);\n\ntic\nfiltered = nonLocalMeans(imageNoisy, sigma, h, patchSize, windowSize, false); \ntoc\n\nfigure('name', 'NL-Means Denoised Image with Integral Images Approach -- SIGMA = 20 h = 0.25');\nimshow(filtered);\n\n%############################### SIGMA = 5 ####################\n\nimageNoisy = imread('images/townNoisy_sigma5.png');\nimageReference = imread('images/townReference.png');\n\n% converting the image in grayscale is much faster roughly 3 times faster\nimageNoisy = rgb2gray(imageNoisy);\nimageReference = rgb2gray(imageReference);\n\nsigma = 5; % standard deviation (different for each image!)\nh = 0.55; %decay parameter\n\n% tic\n% filtered = nonLocalMeansWithoutIntegral(imageNoisy, sigma, h, patchSize, windowSize, false); \n% toc\n% \n% figure('name', 'NL-Means Denoised Image with Naive Approach -- SIGMA = 5 h = 0.55');\n% imshow(filtered);\n\ntic\nfiltered = nonLocalMeans(imageNoisy, sigma, h, patchSize, windowSize, false); \ntoc\n\nfigure('name', 'NL-Means Denoised Image with Integral Images Approach -- SIGMA = 5 h = 0.55');\nimshow(filtered);\n\nh = 0.25;\n\n% tic\n% filtered = nonLocalMeansWithoutIntegral(imageNoisy, sigma, h, patchSize, windowSize, false); \n% toc\n% \n% figure('name', 'NL-Means Denoised Image with Naive Approach -- SIGMA = 5 h = 0.25');\n% imshow(filtered);\n\ntic\nfiltered = nonLocalMeans(imageNoisy, sigma, h, patchSize, windowSize, false); \ntoc\n\nfigure('name', 'NL-Means Denoised Image with Integral Images Approach -- SIGMA = 5 h = 0.25');\nimshow(filtered);\n\n\n\n\n%% Let's show your results!\n\n%Show the denoised image\n% figure('name', 'NL-Means Denoised Image');\n% imshow(filtered);\n\n%Show difference image\ndiff_image = abs(imageReference - filtered);\nfigure('name', 'Difference Image');\nimshow(diff_image ./ max(max((diff_image))));\n\n%Print some statistics ((Peak) Signal-To-Noise Ratio)\ndisp('For Noisy Input');\n[peakSNR, SNR] = psnr(imageNoisy, imageReference);\ndisp(['SNR: ', num2str(SNR, 10), '; PSNR: ', num2str(peakSNR, 10)]);\n\ndisp('For Denoised Result');\n[peakSNR, SNR] = psnr(filtered, imageReference);\ndisp(['SNR: ', num2str(SNR, 10), '; PSNR: ', num2str(peakSNR, 10)]);\n\n%Feel free (if you like only :)) to use some other metrics (Root\n%Mean-Square Error (RMSE), Structural Similarity Index (SSI) etc.)", "meta": {"author": "zhangqianqianQQ", "repo": "MachineVisionAlgorithm", "sha": "683338f6c3b1aab9fa2b80026915fe936aebf0ee", "save_path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm", "path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm/MachineVisionAlgorithm-683338f6c3b1aab9fa2b80026915fe936aebf0ee/去噪算法/Non-Local-Means-master/advancedSection.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383029, "lm_q2_score": 0.8791467722591728, "lm_q1q2_score": 0.8095092753110599}} {"text": "function [tfr,t,f] = tfrmh(x,t,N,trace);\n%TFRMH\tMargenau-Hill time-frequency distribution.\n%\t[TFR,T,F]=TFRMH(X,T,N,TRACE) computes the Margenau-Hill\n%\tdistribution of a discrete-time signal X, \n%\tor the cross Margenau-Hill representation between two signals. \n% \n%\tX : signal if auto-MH, or [X1,X2] if cross-MH.\n%\tT : time instant(s) (default : 1:length(X)).\n%\tN : number of frequency bins (default : length(X)).\n%\tTRACE : if nonzero, the progression of the algorithm is shown\n% (default : 0).\n%\tTFR : time-frequency representation. When called without \n% output arguments, TFRMH runs TFRQVIEW.\n%\tF : vector of normalized frequencies.\n%\n%\tExample :\n%\t sig=fmlin(128,0.1,0.4); tfrmh(sig,1:128,128,1);\n% \n%\tSee also all the time-frequency representations listed in\n%\t the file CONTENTS (TFR*)\n\n%\tF. Auger, May-August 1994, July 1995.\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 (nargin == 0),\n error('At least 1 parameter required');\nend;\n[xrow,xcol] = size(x);\nif (nargin == 1),\n t=1:xrow; N=xrow; trace=0;\nelseif (nargin == 2),\n N=xrow; trace=0;\nelseif (nargin == 3),\n trace = 0;\nend;\n\nif (N<0),\n error('N must be greater than zero');\nend;\n[trow,tcol] = size(t);\nif (xcol==0) | (xcol>2),\n error('X must have one or two columns');\nelseif (trow~=1),\n error('T must only have one row'); \nelseif (2^nextpow2(N)~=N),\n fprintf('For a faster computation, N should be a power of two\\n');\nend; \n\ntfr= zeros (N,tcol) ; \nif trace, disp('Margenau-Hill distribution'); end;\nfor icol=1:tcol,\n ti= t(icol); tau=-min([N-ti,xrow-ti]):(ti-1);\n indices= rem(N+tau,N)+1; \n if trace, disprog(icol,tcol,10); end;\n tfr(indices,icol)=x(ti,1)*conj(x(ti-tau,xcol));\nend; \n\ntfr= real(fft(tfr)); \n\nif (nargout==0),\n tfrqview(tfr,x,t,'tfrmh');\nelseif (nargout==3),\n if rem(N,2)==0, \n f=[0:N/2-1 -N/2:-1]'/N;\n else\n f=[0:(N-1)/2 -(N-1)/2:-1]'/N; \n end;\nend;\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/tfrmh.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.8791467659263148, "lm_q1q2_score": 0.809509261835952}} {"text": "function [x, y] = theta2xy(theta1, theta2, l1, l2)\n% Angle to Position Conversion for 2 link SCARA robot\n%\n% [Inputs]\n%\ttheta1 : angle1 [deg]\n% theta2 : angle2 [deg]\n%\tl1 : link1 length [m]\n%\tl2 : link2 length [m]\n% [Outputs] \n%\tx\t\t : x coordinate of the edge of link2 [m]\n% y\t\t\t: y coordinate of the edge of link2 [m]\n\n% deg to rad conversion\ntheta1 = theta1 * pi / 180;\ntheta2 = theta2 * pi / 180;\n\n% position\nx = l1 * cos(theta1) + l2 * cos(theta1 + theta2);\ny = l1 * sin(theta1) + l2 * sin(theta1 + theta2);\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/22126-nxt-scara-two-link-planar-robot-arm-controller-design/nxtscara/models/theta2xy.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104933824754, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.8094847181145937}} {"text": "function z = cheby_t_poly_zero ( n )\n\n%*****************************************************************************80\n%\n%% CHEBY_T_POLY_ZERO returns zeroes of Chebyshev polynomials T(n,x).\n%\n% Discussion:\n%\n% The I-th zero of T(n,x) is cos((2*I-1)*PI/(2*N)), I = 1 to N\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 March 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the polynomial.\n%\n% Output, real Z(N), the zeroes of T(N)(X).\n%\n for i = 1 : n\n angle = ( 2 * i - 1 ) * pi / real ( 2 * n );\n z(i) = cos ( angle );\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/polpak/cheby_t_poly_zero.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8947894717137997, "lm_q1q2_score": 0.8094717697880844}} {"text": "%UPQ Central image moments\n%\n% M = UPQ(IM, P, Q) is the PQ'th central moment of the image IM. That is, \n% the sum of I(x,y).(x-x0)^P.(y-y0)^Q where (x0,y0) is the centroid.\n%\n% Notes::\n% - The central moments are invariant to translation.\n%\n% See also UPQ_POLY, MPQ, NPQ.\n\n\n% Copyright (C) 1993-2011, by Peter I. Corke\n%\n% This file is part of The Machine Vision Toolbox for Matlab (MVTB).\n% \n% MVTB 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% MVTB 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 MVTB. If not, see .\n\nfunction m = upq(im, p, q)\n\n [X,Y] = imeshgrid(im);\n\n\tm00 = mpq(im, 0, 0);\n\txc = mpq(im, 1, 0) / m00;\n\tyc = mpq(im, 0, 1) / m00;\n\n m = sum(sum( im.*(X-xc).^p.*(Y-yc).^q ) );\n", "meta": {"author": "petercorke", "repo": "machinevision-toolbox-matlab", "sha": "2d791168c19c5e56acef74d22eafd227b4b58e42", "save_path": "github-repos/MATLAB/petercorke-machinevision-toolbox-matlab", "path": "github-repos/MATLAB/petercorke-machinevision-toolbox-matlab/machinevision-toolbox-matlab-2d791168c19c5e56acef74d22eafd227b4b58e42/upq.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.945801271704518, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.8094650962365275}} {"text": "function barycentric_interp_1d_test02 ( prob, nd )\n\n%*****************************************************************************80\n%\n%% BARYCENTRIC_INTERP_1D_TEST02 tests LAGCHEBY2_INTERP_1D.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 19 August 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer PROB, the problem index.\n%\n% Input, integer ND, the number of data points to use.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'BARYCENTRIC_INTERP_1D_TEST02:\\n' );\n fprintf ( 1, ' Interpolate data from TEST_INTERP_1D problem #%d.\\n', prob );\n fprintf ( 1, ' Use Chebyshev Type 2 spacing for data points.\\n' );\n fprintf ( 1, ' Number of data points = %d\\n', nd );\n%\n% Define the data.\n%\n a = 0.0;\n b = +1.0;\n xd = r8vec_cheby2space ( nd, a, b );\n yd = p00_f ( prob, nd, xd );\n\n if ( nd < 10 )\n r8vec2_print ( nd, xd, yd, ' Data array:' );\n end\n%\n% #1: Does the interpolant match the function at the interpolation points?\n%\n ni = nd;\n xi = xd;\n yi = lagcheby2_interp_1d ( nd, xd, yd, ni, xi );\n\n int_error = norm ( yi - yd ) / ni;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' L2 interpolation error averaged per interpolant node = %g\\n', int_error );\n%\n% #2: Plot the data.\n%\n ni = 500;\n xi = r8vec_linspace ( ni, a, b );\n yi = lagcheby2_interp_1d ( nd, xd, yd, ni, xi );\n\n clf\n hold on\n plot ( xd, yd, 'b.', 'MarkerSize', 30 );\n plot ( xi, yi, 'r-', 'LineWidth', 3 );\n grid on\n xlabel ( '<---X--->' );\n ylabel ( '<---Y--->' );\n title ( sprintf ( 'Barycentric Lagrange Chebyshev2 Interpolant for %d nodes', nd ) )\n\n filename = sprintf ( 'p%02d_lagcheby2_%02d.png', prob, nd );\n print ( '-dpng', filename );\n fprintf ( 1, ' Created plot file \"%s\".\\n', filename );\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/barycentric_interp_1d/barycentric_interp_1d_test02.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426831, "lm_q2_score": 0.8824278741843884, "lm_q1q2_score": 0.8094534279020847}} {"text": "function cdf = lorentz_cdf ( x )\n\n%*****************************************************************************80\n%\n%% LORENTZ_CDF evaluates the Lorentz CDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 February 1999\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, the argument of the CDF.\n%\n% Output, real CDF, the value of the CDF.\n%\n cdf = 0.5 + atan ( x ) / pi;\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/lorentz_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8670357598021707, "lm_q1q2_score": 0.8093178956749556}} {"text": "function [J, grad] = costFunction(theta, X, y)\n%COSTFUNCTION Compute cost and gradient for logistic regression\n% J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the\n% parameter for logistic regression and the gradient of the cost\n% w.r.t. to the parameters.\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly\nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n% Note: grad should have the same dimensions as theta\n%\n\n\n\nh = sigmoid(X * theta);\n\nJ = (1 / m) * sum( (-y .* log(h)) - ((1 - y) .* log( 1 - h )) );\n\ngrad = (1 / m) * X' * (h - y);\n\n\n\n\n% =============================================================\n\nend\n", "meta": {"author": "fewtime", "repo": "ML", "sha": "fd9679e9d6648d01e36047e97434f38c8d2d6168", "save_path": "github-repos/MATLAB/fewtime-ML", "path": "github-repos/MATLAB/fewtime-ML/ML-fd9679e9d6648d01e36047e97434f38c8d2d6168/coursera-machine-learning/machine-learning-ex2/ex2/costFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392795, "lm_q2_score": 0.8652240930029118, "lm_q1q2_score": 0.8092843340617264}} {"text": "function pn = plane_imp_point_near_3d ( a, b, c, d, p )\n\n%*****************************************************************************80\n%\n%% PLANE_IMP_POINT_NEAR_3D: nearest point on a implicit plane to a point in 3D.\n%\n% Discussion:\n%\n% The implicit form of a plane in 3D is:\n%\n% A * X + B * Y + C * Z + D = 0\n%\n% The normal N to the plane is (A,B,C).\n%\n% The line defined by (XN-P(1))/A = (YN-P(2))/B = (ZN-P(3))/C = T\n% goes through P and is parallel to N.\n%\n% Solving for the point (XN,YN,ZN) we get\n%\n% XN = A*T+P(1)\n% YN = B*T+P(2)\n% ZN = C*T+P(3)\n%\n% Now place these values in the equation for the plane:\n%\n% A*(A*T+P(1)) + B*(B*T+P(2)) + C*(C*T+P(3)) + D = 0\n%\n% and solve for T:\n%\n% T = (-A*P(1)-B*P(2)-C*P(3)-D) / (A * A + B * B + C * C )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 March 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A, B, C, D, the implicit plane parameters.\n%\n% Input, real P(3), the coordinates of the point.\n%\n% Output, real PN(3), the nearest point on the plane.\n%\n dim_num = 3;\n\n if ( plane_imp_is_degenerate_3d ( a, b, c ) )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PLANE_IMP_POINT_NEAR_3D - Fatal error!\\n' );\n fprintf ( 1, ' A = B = C = 0.\\n' );\n error ( 'PLANE_IMP_POINT_NEAR_3D - Fatal error!' );\n end\n\n t = - ( a * p(1) + b * p(2) + c * p(3) + d ) / ( a * a + b * b + c * c );\n\n pn(1) = p(1) + a * t;\n pn(2) = p(2) + b * t;\n pn(3) = p(3) + c * t;\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_imp_point_near_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346504434783, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.8092843211912294}} {"text": "function d = mahalanobis(varargin)\n%MAHALANOBIS Computes the Mahalanobis distance.\n% D = MAHALANOBIS(Y, X) computes the Mahalanobis distance between\n% each vector in Y to the mean (centroid) of the vectors in X, and\n% outputs the result in vector D, whose length is size(Y, 1). The\n% vectors in X and Y are assumed to be organized as rows. The\n% input data can be real of complex. The outputs are real\n% quantities.\n%\n% D = MAHALANOBIS(Y, CX, MX) computes the Mahalanobis distance\n% between each vector in Y and the given mean vector, MX. The\n% results are output in vector D, whose length is size(Y, 1). The\n% vectors in Y are assumed to be organized as the rows of this\n% array. The input data can be real or complex. The outputs are\n% real quantities. In addition to the mean vector MX, the\n% covariance matrix CX of a population of vectors X also must be\n% provided. Use function COVMATRIX (Section 11.5) to compute MX and\n% CX.\n\n% Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins\n% Digital Image Processing Using MATLAB, Prentice-Hall, 2004\n% $Revision: 1.5 $ $Date: 2003/10/26 23:19:44 $\n\n% Reference: Acklam, P. J. [2002]. \"MATLAB Array Manipulation Tips\n% and Tricks.\" Available at\n% home.online.no/~pjacklam/matlab/doc/mtt/index.html \n% or at\n% www.prenhall.com/gonzalezwoodseddins\n\nparam = varargin; % Keep in mind that param is a cell array.\nY = param{1};\nny = size(Y, 1); % Number of vectors in Y.\n\nif length(param) == 2\n X = param{2};\n % Compute the mean vector and covariance matrix of the vectors\n % in X.\n [Cx, mx] = covmatrix(X);\nelseif length(param) == 3 % Cov. matrix and mean vector provided.\n Cx = param{2};\n mx = param{3};\nelse \n error('Wrong number of inputs.')\nend\nmx = mx(:)'; % Make sure that mx is a row vector.\n\n% Subtract the mean vector from each vector in Y.\nYc = Y - mx(ones(ny, 1), :);\t\n\n% Compute the Mahalanobis distances.\nd = real(sum(Yc/Cx.*conj(Yc), 2));\n", "meta": {"author": "61--", "repo": "weiyanmin", "sha": "e15a7789602ec65c7ce1972bd905826ff4851435", "save_path": "github-repos/MATLAB/61---weiyanmin", "path": "github-repos/MATLAB/61---weiyanmin/weiyanmin-e15a7789602ec65c7ce1972bd905826ff4851435/Matlab/mahalanobis.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680097, "lm_q2_score": 0.868826789824086, "lm_q1q2_score": 0.8092795797705112}} {"text": "function partest(varargin)\n%This function calculate the performance, based on Bayes theorem, of a\n%clinical test.\n%\n% Syntax: \tPARTEST(X,ALPHA)\n% \n% Input:\n% X is the following 2x2 matrix.\n% ALPHA - significance level for confidence intervals (default = 0.05).\n%\n%....................Affected(D+)..Healthy(D-)\n% _______________________\n%Positive Test(T+) | True | False |\n% | positives | positives |\n% |___________|___________|\n% | False | True |\n%Negative Test(T-) | negatives | negatives |\n% |___________|___________|\n%\n% Outputs:\n% - Prevalence\n% - Sensibility\n% - Specificity\n% - False positive and negative proportions\n% - False discovery and discovery rates\n% - Youden's Index and Number Needed to Diagnose (NDD)\n% - Positive predictivity\n% - Positive Likelihood Ratio\n% - Negative predictivity\n% - Negative Likelihood Ratio\n% - Predictive Summary Index (PSI) and Number Needed to Screen (NNS)\n% - Test Accuracy\n% - Mis-classification Rate\n% - F-Measure\n% - Test bias\n% - Error odds ratio\n% - Diagnostic odds ratio\n% - Discriminant Power\n%\n% Example: \n%\n%\n% Calling on Matlab the function: partest\n% it will use a default matrix x=[731 270;78 1500] and alpha=0.05\n%\n% Answer is:\n%\n%DIAGNOSTIC TEST PERFORMANCE PARAMETERS\n% ----------------------------------------------------------------------------------------------------\n% Prevalence: 31.4% (29.6% - 33.2%)\n% \n% Sensitivity (probability that test is positive on unhealthy subject): 90.4% (89.1% - 91.5%)\n% False negative proportion: 9.6% (8.5% - 10.9%)\n% False discovery rate: 27.0% (25.3% - 28.7%)\n% \n% Specificity (probability that test is negative on healthy subject): 84.7% (83.3% - 86.1%)\n% False positive proportion: 15.3% (13.9% - 16.7%)\n% False omission rate: 4.9% (4.2% - 5.9%)\n% \n% Youden's Index (a perfect test would have a Youden's index of +1): 0.7510\n% Number Needed to Diagnose (NND): 1.33\n% Around 14 persons need to be tested to return 10 positive tests for the presence of disease\n% \n% Precision or Predictivity of positive test\n% (probability that a subject is unhealthy when test is positive): 73.0% (71.3% - 74.7%)\n% Positive Likelihood Ratio: 5.9 (5.7 - 6.2)\n% Moderate increase in possibility of disease presence\n% \n% Predictivity of negative test\n% (probability that a subject is healthy when test is negative): 95.1% (94.1% - 95.8%)\n% Negative Likelihood Ratio: 0.1138 (0.1094 - 0.1183)\n% Moderate increase in possibility of disease absence\n% \n% Predictive Summary Index: 0.6808\n% Number Needed to Screen (NNS): 1.47\n% Around 15 persons need to be screened to avoid 10 events (i.e. death) for the presence of disease\n% \n% Accuracy or Potency: 86.5% (85.1% - 87.8%)\n% Mis-classification Rate: 13.5% (12.2% - 14.9%)\n% F-measure: 80.8% (79.2% - 82.3%)\n% \n% Test bias: 1.2373 (0.9474 - 1.6160)\n% Test overestimates the phenomenon\n% Error odds ratio: 1.6869 (1.2916 - 2.2032)\n% Diagnostic odds ratio: 52.0655 (39.8649 - 68.0002)\n% Discriminant Power: 2.2\n% A test with a discriminant value of 1 is not effective in discriminating between affected and unaffected individuals.\n% A test with a discriminant value of 3 is effective in discriminating between affected and unaffected individuals.\n% \n%\n% Created by Giuseppe Cardillo\n% giuseppe.cardillo-edta@poste.it\n%\n% To cite this file, this would be an appropriate format:\n% Cardillo G. (2006). Clinical test performance: the performance of a\n% clinical test based on the Bayes theorem. \n% http://www.mathworks.com/matlabcentral/fileexchange/12705\n\n%Input Error handling\nargs=cell(varargin);\nnu=numel(args);\nif nu>2\n error('Warning: Max two input data are required')\nend\ndefault.values = {[731 270;78 1500],0.05};\ndefault.values(1:nu) = args;\n[x alpha] = deal(default.values{:});\n\nif nu>=1\n if isvector(x)\n error('Warning: PARTEST requires a 2x2 input matrix')\n end\n if ~all(isfinite(x(:))) || ~all(isnumeric(x(:))) || ~isequal(x,round(x))\n error('Warning: all matrix values must be numeric integer and finite')\n end\n [r,c] = size(x);\n if (r ~= 2 || c ~= 2)\n error('Warning: PARTEST requires a 2x2 input matrix')\n end\n clear r c\nend\nif nu>1\n if ~isscalar(alpha) || ~isnumeric(alpha) || ~isfinite(alpha) || isempty(alpha)\n error('Warning: it is required a numeric, finite and scalar ALPHA value.');\n end\n if alpha <= 0 || alpha >= 1 %check if alpha is between 0 and 1\n error('Warning: ALPHA must be comprised between 0 and 1.')\n end\nend\nclear args default nu\n\nglobal z N\n\nz=-realsqrt(2)*erfcinv(2-alpha);\ncs=sum(x); %columns sum\nrs=sum(x,2); %rows sums\nN=sum(x(:)); %numbers of elements\nd=diag(x); %true positives and true negatives\n\nclc\ndisp('DIAGNOSTIC TEST PERFORMANCE PARAMETERS')\ndisp(repmat('-',1,100))\n%Prevalence\n%the prevalence of disease is estimated all D+/N \npr=(cs(1)/N); \n%95% confidence interval critical value for Prevalence\nprci=newcombe(pr);\nfprintf('Prevalence: %0.1f%% (%0.1f%% - %0.1f%%)\\n',pr*100,prci(1).*100,prci(2).*100)\ndisp(' ')\n\n%Sensitivity and Specificity\n%The Sensitivity is the probability that the test is positive on sick subjects: P(T+|D+) \n%The Specificity is the probability that the test is negative on healthy subjects: P(T-|D-) \n%In Matlab both parameters are obtained with only one instruction:\nSS=d./cs'; %Sensitivity and Specificity\n%Of course the false proportion is the complement to 1\nfp=1-SS; %false proportions\n%The false discovery rate is the probability that the disease is absent when the test is positive: P(D-|T+) \n%The false omission rate is the probability that the disease is present when the test is negative: P(D+|T-) \nfd=diag(rot90(x))./rs; %false discovery and omission rate\n\n% 95% confidence intervals\nSeci=newcombe(SS(1)); Spci=newcombe(SS(2));\nfnci=newcombe(fp(1)); fpci=newcombe(fp(2));\nfdci=newcombe(fd(1)); foci=newcombe(fd(2));\nfprintf('Sensitivity (probability that test is positive on unhealthy subject): %0.1f%% (%0.1f%% - %0.1f%%)\\n',SS(1)*100,Seci(1).*100,Seci(2).*100)\nfprintf('False negative proportion: %0.1f%% (%0.1f%% - %0.1f%%)\\n',fp(1)*100,fnci(1).*100,fnci(2).*100)\nfprintf('False discovery rate: %0.1f%% (%0.1f%% - %0.1f%%)\\n',fd(1)*100,fdci(1).*100,fdci(2).*100)\ndisp(' ')\nfprintf('Specificity (probability that test is negative on healthy subject): %0.1f%% (%0.1f%% - %0.1f%%)\\n',SS(2)*100,Spci(1).*100,Spci(2).*100)\nfprintf('False positive proportion: %0.1f%% (%0.1f%% - %0.1f%%)\\n',fp(2)*100,fpci(1).*100,fpci(2).*100)\nfprintf('False omission rate: %0.1f%% (%0.1f%% - %0.1f%%)\\n',fd(2)*100,foci(1).*100,foci(2).*100)\ndisp(' ')\n\n%Youden's Index\n%Youden's J statistics (also called Youden's index) is a single statistic that\n%captures the performance of a diagnostic test. The use of such a single index\n%is \"not generally to be recommended\". It is equal to the risk difference for a\n%dichotomous test and it defined as: J = Sensitivity + Specificity - 1. \n%A perfect test has J=1. \nJ=sum(SS)-1; %Youden's index\nfprintf('Youden''s Index (a perfect test would have a Youden''s index of +1): %0.4f\\n', J)\n\n%The number needed to diagnose is defined as the number of patients that\n%need to be tested to give one correct positive test.\nNND=1/J; %Number needed to Diagnose (NND)\nfprintf('Number Needed to Diagnose (NND): %0.2f\\n',NND);\nfprintf('Around %i persons need to be tested to return 10 positive tests for the presence of disease\\n',ceil(NND*10)) \ndisp(' ')\n\n%Positive and Negative predictivity\n%Positive predictivity is the probability that a subject is sick when test is positive: P(D+|T+)\n%Negative predictivity is the probability that a subject is healthy when test is negative: P(D-|T-)\n%Positive predictivity=Precision\n%In Matlab both parameters are obtained with only one instruction:\nPNp=d./rs; %Positive and Negative predictivity\n% 95% confidence interval critical value for Positive and Negative predictivity\nPpci=newcombe(PNp(1));\nNpci=newcombe(PNp(2));\n%Positive and Negative Likelihood Ratio\n%When we decide to order a diagnostic test, we want to know which test (or\n%tests) will best help us rule-in or rule-out disease in our patient. In the\n%language of clinical epidemiology, we take our initial assessment of the\n%likelihood of disease (“pre-test probability”), do a test to help us shift our\n%suspicion one way or the other, and then determine a final assessment of the\n%likelihood of disease (“post-test probability”). \n%Likelihood ratios tell us how much we should shift our suspicion for a\n%particular test result. Because tests can be positive or negative, there are at\n%least two likelihood ratios for each test. The “positive likelihood ratio”\n%(LR+) tells us how much to increase the probability of disease if the test is\n%positive, while the “negative likelihood ratio” (LR-) tells us how much to\n%decrease it if the test is negative.\n%You can also define the LR+ and LR- in terms of sensitivity and specificity:\n%LR+ = sensitivity / (1-specificity)\n%LR- = (1-sensitivity) / specificity\nplr=SS(1)/fp(2); %Positive Likelihood Ratio\nplrci=LRci(plr,x);\nnlr=fp(1)/SS(2); %Negative Likelihood Ratio\nnlrci=LRci(nlr,x);\n\nfprintf('Precision or Predictivity of positive test\\n')\nfprintf('(probability that a subject is unhealthy when test is positive): %0.1f%% (%0.1f%% - %0.1f%%)\\n', PNp(1)*100,Ppci(1).*100,Ppci(2).*100)\nfprintf('Positive Likelihood Ratio: %0.1f (%0.1f - %0.1f)\\n',plr,plrci(1),plrci(2))\ndlr(plr)\ndisp(' ')\nfprintf('Predictivity of negative test\\n')\nfprintf('(probability that a subject is healthy when test is negative): %0.1f%% (%0.1f%% - %0.1f%%)\\n', PNp(2)*100,Npci(1).*100,Npci(2).*100)\nif nlr<1e-4 || nlrci(1)<1e-4\n fprintf('Negative Likelihood Ratio: %0.4e (%0.4e - %0.4e)\\n',nlr,nlrci(1),nlrci(2))\nelse\n fprintf('Negative Likelihood Ratio: %0.4f (%0.4f - %0.4f)\\n',nlr,nlrci(1),nlrci(2))\nend\ndlr(nlr)\ndisp(' ')\n\n%Predictive Summary Index (similar to Youden's Index)\nPSI=sum(PNp)-1;\nNNS=1/PSI; %Number needed to screen\nfprintf('Predictive Summary Index: %0.4f\\n', PSI)\nfprintf('Number Needed to Screen (NNS): %0.2f\\n',NNS);\nfprintf('Around %i persons need to be screened to avoid 10 events (i.e. death) for the presence of disease\\n',ceil(NNS*10)) \ndisp(' ')\n\n%Accuracy and Mis-classification rate\n%Diagnostic accuracy (or Power) is defined as the proportion of all tests\n%that give a correct result. The Mis-classification rate is its complement to 1. \n%In statistics, the F1 score (also F-score or F-measure) is a measure of a\n%test's accuracy. It considers both the Precision (positive predictivity) \n%and the Sensitivity of the test to compute the score: \n%P is the number of correct results divided by the number of all returned results\n%S is the number of correct results divided by the number of results that should \n%have been returned. \n%The F1 score can be interpreted as a weighted average of the Precision and\n%Sensitivity, where an F1 score reaches its best value at 1 and worst score at 0. \nacc=trace(x)/N; %Accuracy\naccci=newcombe(acc);\nmcr=1-acc; %Mis-classification rate\nmcrci=newcombe(mcr);\nFMeasure=harmmean([SS(1) PNp(1)]); %F-measure\nFMci=newcombe(FMeasure);\nfprintf('Accuracy or Potency: %0.1f%% (%0.1f%% - %0.1f%%)\\n',acc*100,accci(1).*100,accci(2).*100)\nfprintf('Mis-classification Rate: %0.1f%% (%0.1f%% - %0.1f%%)\\n',mcr*100,mcrci(1).*100,mcrci(2).*100)\nfprintf('F-measure: %0.1f%% (%0.1f%% - %0.1f%%)\\n',FMeasure*100,FMci(1).*100,FMci(2).*100)\ndisp(' ')\n\norse=realsqrt(sum(1./x(:))); %standard error of log(OR)\ncv=([-1 1].*(z*orse));\n\n%Test Bias (TB)\n%A test which shows provable and systematic differences in the results of people\n%based on group membership. For example, a test might be considered biased if\n%members of one particular gender or race consistently and systematic have\n%statistically different results from the rest of the testing population. \n%It is defined as (T+)/(D+)=(TP+FP)/(TP+FN)\n%A perfect test has a TB=1;\n%If TB<1 the test underestimates the disease because there are more affected than positive test\n%If TB>1 the test overestimates the disease because there are more positive test than affected\nTB=rs(1)/cs(1); %Test Bias\norci=exp(reallog(TB)+cv); %OR confidence interval\nfprintf('Test bias: %0.4f (%0.4f - %0.4f)\\n',TB,orci(1),orci(2))\nif TB>1\n disp('Test overestimates the phenomenon')\nelseif TB<1\n disp('Test underestimates the phenomenon')\nelse\n disp('There is not test bias')\nend\n\n%Error Odds Ratio. \n%Indicates if the probability of being wrongly classified is highest in the\n%diseased or in the non-diseased group. If the error odds is higher than one the\n%probability is highest in the diseased group (and the specificity of the test\n%is better than the sensitivity), if the value is lower than one the probability\n%of an incorrect classification is highest in the non-diseased group (and the\n%sensitivity of the test is better than the specificity). \n%It is defined as (Sensitivity/(1-Sensitivity))/(Specificity/(1-Specificity));\nEOR=(SS(1)/fp(1))/(SS(2)/fp(2)); %Error odds ratio\norci=exp(reallog(EOR)+cv); %OR confidence interval\nfprintf('Error odds ratio: %0.4f (%0.4f - %0.4f)\\n',EOR,orci(1),orci(2))\n\n%Diagnostic Odds Ratio. \n%Diagnostic odds ratio is defined as how much more likely will the test\n%make a correct diagnosis than an incorrect diagnosis in patients with the\n%disease (Scott et al. 2008). \n%Often used as a measure of the discriminative power of the test. Has the value\n%one if the test does not discriminate between diseased and not diseased. Very\n%high values above one means that a test discriminates well. Values lower than\n%one mean that there is something wrong in the application of the test. \n%It is defined as (Sensitivity/(1-Sensitivity))/((1-Specificity)/Specificity);\nDOR=(SS(1)/fp(1))/(fp(2)/SS(2)); %Diagnostic odds ratio\norci=exp(reallog(DOR)+cv); %OR confidence interval\nfprintf('Diagnostic odds ratio: %0.4f (%0.4f - %0.4f)\\n',DOR,orci(1),orci(2))\n\n%Discriminant power\n%The discriminant power for a test, also termed the test effectiveness, is a\n%measure of how well a test distinguishes between affected and unaffected\n%persons. It is the sum of logs of Sensivity and Specificity over own false\n%proportion, scaled by the standard deviation of the logistic normal\n%distribution curve (square root of 3 divided by π). Test effectiveness is\n%interpreted as the standardized distance between the means for both populations. \n%A test with a discriminant value of 1 is not effective in discriminating between affected and unaffected individuals.\n%A test with a discriminant value of 3 is effective in discriminating between affected and unaffected individuals.\ndpwr=(realsqrt(3)/pi)*sum(log(SS./fp)); %Discriminant power\nfprintf('Discriminant Power: %0.1f\\n',dpwr)\ndisp([blanks(5) 'A test with a discriminant value of 1 is not effective in discriminating between affected and unaffected individuals.'])\ndisp([blanks(5) 'A test with a discriminant value of 3 is effective in discriminating between affected and unaffected individuals.'])\n\n\n%Display graphs\nxg=cs./N;\nfigure\nhold on\nH=zeros(1,4);\nH(1)=fill(xg(1)+[0 xg(2) xg(2) 0],SS(2)+[0 0 fp(2) fp(2)],'r');\nH(2)=fill([0 xg(1) xg(1) 0],fp(1)+[0 0 SS(1) SS(1)],'g');\nH(3)=fill([0 xg(1) xg(1) 0],[0 0 fp(1) fp(1)],'y');\nH(4)=fill(xg(1)+[0 xg(2) xg(2) 0],[0 0 SS(2) SS(2)],'b');\nhold off\naxis square\ntitle('PARTEST GRAPH')\nxlabel('Subjects proportion')\nylabel('Parameters proportion')\nlegend(H,'False Positive','True Positive (Sensibility)','False Negative','True Negative (Specificity)','Location','NorthEastOutside')\n\n%The rose plot is a variation of the common pie chart. For both, we have k data\n%points where each point denotes a frequency or a count. Pie charts and rose\n%plots both use the area of segments of a circle to convey amounts. \n%The pie chart uses a common radius and varies the central angle according to\n%the data. That is, the angle is proportional to the frequency. So if the i-th\n%point has count X and the total count is N, the i-th angle is 360*(X/N). \n%For the rose plot, the angle is constant (i.e., divide 360 by the number of\n%groups, k) and it is the square root of the radius that is proportional to the\n%data. \n%According to Wainer (Wainer (1997), Visual Revelations: Graphical Tales of Fate\n%and Deception from Napolean Bonaporte to Ross Perot, Copernicus, Chapter 11.),\n%the use of a common angle is the strength of the rose plot since it allows us\n%to easily compare a sequence of rose plots (i.e., the corresponding segments in\n%different rose plots are always in the same relative position). \n%In particular, this makes rose plots an effective technique for displaying the\n%data in contingency tables. \n%As an interesting historical note, Wainer points out that rose plots were used\n%by Florence Nightingale (she referred to them as coxcombs). \n%color={'r','g','y','b'};\nH=roseplot([fp(2) SS(1) fp(1) SS(2)]);\ntitle('ROSEPLOT PARTEST GRAPH')\nlegend(H,'False Positive','True Positive (Sensibility)','False Negative','True Negative (Specificity)','Location','NorthEastOutside')\nreturn\nend\n\nfunction dlr(lr) %Likelihood dialog\nif lr==1\n disp('Test is not suggestive of the presence/absence of disease')\n return\nend\n\nif lr>10 || lr<0.1\n p1='Large (often conclusive)';\nelseif (lr>5 && lr<=10) || (lr>0.1 && lr<=0.2)\n p1='Moderate';\nelseif (lr>2 && lr<=5) || (lr>0.2 && lr<=0.5)\n p1='Low';\nelseif (lr>1 && lr<=2) || (lr>0.5 && lr<=1)\n p1='Poor';\nend\n\np2=' increase in possibility of disease ';\n\nif lr>1\n p3='presence';\nelseif lr<1\n p3='absence';\nend\ndisp([p1 p2 p3])\nreturn\nend\n\nfunction H=roseplot(x)\ncolor={'r','g','y','b'};\nk=length(x); H=zeros(1,k);\nang=(0:1:k)./k.*2.*pi;\nfigure\naxis square\nhold on\nfor I=1:k\n theta=[ang(I) linspace(ang(I),ang(I+1),500) ang(I+1)];\n rho=[0 repmat(realsqrt(x(I)),1,500) 0];\n [xg,yg]=pol2cart(theta,rho);\n H(I)=patch(xg,yg,color{I});\nend\nhold off\nreturn\nend\n\nfunction ci=newcombe(p)\nglobal z N\na=2*N*p+z^2;\nb=z*realsqrt((z^2-2-1/N+4*p*(N*(1-p)+1)));\nc=(2*(N+z^2));\n%Of course, the critical interval lower bound cannot be less than 0 and the\n%upper bound cant be greater than 1 and so:\nci(1)=max([0 (a-b-1)/c]);\nci(2)=min([1 (a+b+1)/c]);\nreturn\nend\n\nfunction ci=LRci(lr,x)\nglobal z\na=log(lr); b=realsqrt(sum(1./diag(x))-sum(1./sum(x,2)))*z;\nci=exp([a-b a+b]);\nreturn\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/12705-clinical-test-performance/partest.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9566342049451595, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.8092574635129569}} {"text": "function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters)\n%GRADIENTDESCENT Performs gradient descent to learn theta\n% theta = GRADIENTDESCENT(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\n predictions = X * theta;\n updates = X' * (predictions - y);\n theta = theta - alpha * (1/m) * updates;\n %theta = theta - alpha * (1/m) * sum(sqerrors) * X;\n %theta - (alpha/m) * (X' * (X * theta - y));\n %theta = theta - (alpha/m) * (X' * (X * theta - y));\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": "khanhnamle1994", "repo": "machine-learning", "sha": "fa391eb9429187a295c15a14ba24f4416667e5c1", "save_path": "github-repos/MATLAB/khanhnamle1994-machine-learning", "path": "github-repos/MATLAB/khanhnamle1994-machine-learning/machine-learning-fa391eb9429187a295c15a14ba24f4416667e5c1/machine-learning-ex1/ex1/gradientDescent.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.8856314738181875, "lm_q1q2_score": 0.8091806860239792}} {"text": "% Example 7.2: Maximum entropy distribution\n% Section 7.2, Figures 7.2-7.3\n% Boyd & Vandenberghe, \"Convex Optimization\"\n% Originally by Lieven Vandenberghe\n% Adapted for CVX by Michael Grant 4/11/06\n%\n% We consider a probability distribution on 100 equidistant points in the\n% interval [-1,1]. We impose the following prior assumptions:\n%\n% -0.1 <= E(X) <= +0.1\n% +0.5 <= E(X^2) <= +0.6\n% -0.3 <= E(3*X^3-2*X) <= -0.2\n% +0.3 <= Pr(X<0) <= 0.4\n%\n% Along with the constraints sum(p) == 1, p >= 0, these constraints\n% describe a polyhedron of probability distrubtions. In the first figure,\n% the distribution that maximizes entropy is computed. In the second\n% figure, we compute upper and lower bounds for Prob(X<=a_i) for each\n% point -1 <= a_i <= +1 in the distribution, as well as the maximum\n% entropy CDF.\n\n%\n% Represent the polyhedron as follows:\n% A * p <= b\n% sum( p ) == 1\n% p >= 0\n%\n\nn = 100;\na = linspace(-1,1,n);\na2 = a .^ 2;\na3 = 3 * ( a.^ 3 ) - 2 * a;\nap = +( a < 0 );\nA = [ a ; -a ; a2 ; -a2 ; a3 ; -a3 ; ap ; -ap ];\nb = [ 0.1 ; 0.1 ;0.5 ; -0.5 ; -0.2 ; 0.3 ; 0.4 ; -0.3 ];\n\n%\n% Compute the maximum entropy distribution\n%\n\ncvx_expert true\ncvx_begin \n variables pent(n)\n maximize( sum(entr(pent)) )\n sum(pent) == 1;\n A * pent <= b;\ncvx_end\n\n%\n% Compute the bounds on Prob(X<=a_i), i=1,...,n\n%\n\nUbnds = zeros(1,n);\nLbnds = zeros(1,n);\nfor t = 1 : n,\n cvx_begin quiet\n variable p( n )\n minimize sum( p(1:t) )\n p >= 0; \n sum( p ) == 1;\n A * p <= b;\n cvx_end\n Lbnds(t) = cvx_optval;\n cvx_begin quiet\n variable p( n )\n maximize sum( p(1:t) )\n p >= 0; \n sum( p ) == 1;\n A * p <= b;\n cvx_end\n Ubnds(t) = cvx_optval;\n disp( sprintf( '%g <= Prob(x<=%g) <= %g', Lbnds(t), a(t), Ubnds(t) ) );\nend\n\n%\n% Generate the figures\n%\n\nfigure( 1 )\nstairs( a, pent );\nxlabel( 'x' );\nylabel( 'PDF( x )' );\n\nfigure( 2 )\nstairs( a, cumsum( pent ) );\ngrid on;\nhold on\nd = stairs(a, Lbnds,'r-'); set(d,'Color',[0 0.5 0]);\nd = stairs(a, Ubnds,'r-'); set(d,'Color',[0 0.5 0]);\nd = plot([-1,-1], [Lbnds(1), Ubnds(1)],'r-');\nset(d,'Color',[0 0.5 0]);\naxis([-1.1 1.1 -0.1 1.1]);\nxlabel( 'x' );\nylabel( 'CDF( x )' );\nhold off\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/Ch07_statistical_estim/maxent.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029486, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.8091799291326354}} {"text": "function [points,weights] = FibonacciGaussian(N,mu,P)\n%%FIBONACCIGAUSSIAN Creates a grid of points based on a transformation of a\n% Fibonacci grid as given in [1].\n%\n%INPUT:\n% N: The number of points to sample.\n% mu: The D-by-1 vector indicating the Gaussian mean.\n% P: The D-by-D covariance matrix. This must be positive definite.\n%\n%OUTPUT:\n% points: A D-by-N matrix containing sample points for the given Gaussian.\n% weights: A collection of weights representing the Gaussian PDF at each\n% sample point.\n%\n%EXAMPLE 1: Generates a collection of sample points and their respective\n% Gaussian weights in 1D and plots them.\n% mu = 5;\n% P = 2;\n% [points, weights] = FibonacciGaussian(100,mu,P);\n% stem(points(1,:),weights,'k',\"filled\",\"MarkerEdgeColor\",'b')\n%\n%EXAMPLE 2: Generates a collection of sample points and their respective\n% Gaussian weights in 2D and plots them.\n% mu = [5;3];\n% P = [2,-0.7;-0.7,1];\n% [points, weights] = FibonacciGaussian(100,mu,P);\n% scatter(points(1,:),points(2,:),'k',\"filled\",\"MarkerEdgeColor\",'b',\"CData\",weights)\n% hold on\n% drawEllipse(mu,P\\eye(2),[],'r',\"LineWidth\",2)\n% hold off\n%\n%EXAMPLE 3: Generates a collection of sample points and their respective\n% Gaussian weights in 3D and plots them.\n% mu = [5;3;4];\n% P = [2,-0.7,0.1;-0.7,1,-0.3;0.1,-0.3,2];\n% [points, weights] = FibonacciGaussian(100,mu,P);\n% scatter3(points(1,:),points(2,:),points(3,:),'k',\"filled\",\"MarkerEdgeColor\",'b',\"CData\",1e3*weights)\n% hold on\n% drawEllipse(mu,P\\eye(3),[],\"FaceAlpha\",0.1,\"EdgeAlpha\",0.1)\n% hold off\n%\n%REFERENCE:\n%[1] D. Frisch and U. D. Hanebeck, \"Deterministic gaussian sampling with\n% generalized fibonacci grids,\" in 2021 IEEE 24th International\n% Conference on Information Fusion (FUSION), IEEE, 2021, pp. 1-8.\n%\n%December 2022 Codie T. Lewis, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\nD = size(mu,1);\npoints = FibonacciGrid(N,D);\npoints = sqrt(2)*erfinv(2*points-1);\nnu = sqrt(sum(points.^2,2)/N);\nfor idx = 1:D\n points(idx,:) = points(idx,:)/nu(idx);\nend\n[V,E] = eig(P);\npoints = V*sqrt(abs(E))*points+mu;\nweights = GaussianD.PDF(points,mu,P);\nend\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.", "meta": {"author": "USNavalResearchLaboratory", "repo": "TrackerComponentLibrary", "sha": "9f6e329de5be06a371757c4b853200beb6def2d0", "save_path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary", "path": "github-repos/MATLAB/USNavalResearchLaboratory-TrackerComponentLibrary/TrackerComponentLibrary-9f6e329de5be06a371757c4b853200beb6def2d0/Mathematical_Functions/Numerical_Integration/Fibonacci/FibonacciGaussian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475715065793, "lm_q2_score": 0.8577681122619883, "lm_q1q2_score": 0.8091734656181296}} {"text": "function y = mtrapezlogpdf(x,a,u,v,b)\n%MTRAPEZLOGPDF Multivariate trapezoidal probability log pdf.\n% Y = MTRAPEZLOGPDF(X,A,U,V,B) returns the logarithm of the pdf of the \n% multivariate trapezoidal distribution with external bounds A and B and \n% internal points U and V, evaluated at the values in X. The multivariate\n% trapezoidal pdf is the product of univariate trapezoidal pdfs in each\n% dimension. \n%\n% For each dimension i, the univariate trapezoidal pdf is defined as:\n%\n% | __________\n% | /| |\\\n% p(X(i)) | / | | \\ \n% | / | | \\\n% |___/___|________|___\\____\n% A(i) U(i) V(i) B(i)\n% X(i)\n% \n% X can be a matrix, where each row is a separate point and each column\n% is a different dimension. Similarly, A, B, C, and D can also be\n% matrices of the same size as X.\n%\n% The log pdf is typically preferred in numerical computations involving\n% probabilities, as it is more stable.\n%\n% See also MTRAPEZPDF, MTRAPEZRND.\n\n% Luigi Acerbi 2022\n\n[N,D] = size(x);\n\nif D > 1\n if isscalar(a); a = a*ones(1,D); end\n if isscalar(u); u = u*ones(1,D); end\n if isscalar(v); v = v*ones(1,D); end\n if isscalar(b); b = b*ones(1,D); end\nend\n\nif size(a,2) ~= D || size(u,2) ~= D || size(v,2) ~= D || size(b,2) ~= D\n error('mtrapezpdf:SizeError', ...\n 'A, B, C, D should be scalars or have the same number of columns as X.');\nend\n\nif size(a,1) == 1; a = repmat(a,[N,1]); end\nif size(u,1) == 1; u = repmat(u,[N,1]); end\nif size(v,1) == 1; v = repmat(v,[N,1]); end\nif size(b,1) == 1; b = repmat(b,[N,1]); end\n\ny = -inf(size(x));\nlnf = log(0.5) + log(b - a + v - u) + log(u - a);\n\nfor ii = 1:D\n idx = x(:,ii) >= a(:,ii) & x(:,ii) < u(:,ii);\n y(idx,ii) = log(x(idx,ii) - a(idx,ii)) - lnf(idx,ii);\n \n idx = x(:,ii) >= u(:,ii) & x(:,ii) < v(:,ii);\n y(idx,ii) = log(u(idx,ii)-a(idx,ii)) - lnf(idx,ii);\n \n idx = x(:,ii) >= v(:,ii) & x(:,ii) < b(:,ii);\n y(idx,ii) = log(b(idx,ii) - x(idx,ii)) - log(b(idx,ii) - v(idx,ii)) + log(u(idx,ii)-a(idx,ii)) - lnf(idx,ii);\nend\n\ny = sum(y,2);", "meta": {"author": "acerbilab", "repo": "vbmc", "sha": "54ba2cdd6c11d2595b9613557da14573abbb7b92", "save_path": "github-repos/MATLAB/acerbilab-vbmc", "path": "github-repos/MATLAB/acerbilab-vbmc/vbmc-54ba2cdd6c11d2595b9613557da14573abbb7b92/shared/mtrapezlogpdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475683211323, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.8091734594557974}} {"text": "function [r, R, S] = imnoise3(M, N, C, A, B)\n%IMNOISE3 Generates periodic noise.\n% [r, R, S] = IMNOISE3(M, N, C, A, B), generates a spatial\n% sinusoidal noise pattern, r, of size M-by-N, its Fourier\n% transform, R, and spectrum, S. The remaining parameters are:\n%\n% C is a K-by-2 matrix with K pairs of freq. domain coordinates (u,\n% v) that define the locations of impulses in the freq. domain. The\n% locations are with respect to the frequency rectangle center at\n% (floor(M/2) + 1, floor(N/2) + 1). The impulse locations are spe-\n% cified as increments with respect to the center. For ex, if M =\n% N = 512, then the center is at (257, 257). To specify an impulse\n% at (280, 300) we specify the pair (23, 43); i.e., 257 + 23 = 280,\n% and 257 + 43 = 300. Only one pair of coordinates is required for\n% each impulse. The conjugate pairs are generated automatically. \n%\n% A is a 1-by-K vector that contains the amplitude of each of the\n% K impulse pairs. If A is not included in the argument, the\n% default used is A = ONES(1, K). B is then automatically set to\n% its default values (see next paragraph). The value specified\n% for A(j) is associated with the coordinates in C(j, 1:2). \n%\n% B is a K-by-2 matrix containing the Bx and By phase components\n% for each impulse pair. The default values for B are B(1:K, 1:2)\n% = 0.\n \n% Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins\n% Digital Image Processing Using MATLAB, Prentice-Hall, 2004\n% $Revision: 1.5 $ $Date: 2004/11/04 22:32:42 $\n\n% Process input parameters.\n[K, n] = size(C);\nif nargin == 3\n A(1:K) = 1.0;\n B(1:K, 1:2) = 0;\nelseif nargin == 4\n B(1:K, 1:2) = 0;\nend\n\n% Generate R.\nR = zeros(M, N);\nfor j = 1:K\n u1 = M/2 + 1 + C(j, 1); v1 = N/2 + 1 + C(j, 2);\n R(u1, v1) = i * (A(j)/2) * exp(i*2*pi*C(j, 1) * B(j, 1)/M);\n % Complex conjugate.\n u2 = M/2 + 1 - C(j, 1); v2 = N/2 + 1 - C(j, 2);\n R(u2, v2) = -i * (A(j)/2) * exp(i*2*pi*C(j, 2) * B(j, 2)/N);\nend\n\n% Compute spectrum and spatial sinusoidal pattern.\nS = abs(R);\nr = real(ifft2(ifftshift(R)));\n", "meta": {"author": "61--", "repo": "weiyanmin", "sha": "e15a7789602ec65c7ce1972bd905826ff4851435", "save_path": "github-repos/MATLAB/61---weiyanmin", "path": "github-repos/MATLAB/61---weiyanmin/weiyanmin-e15a7789602ec65c7ce1972bd905826ff4851435/Matlab/imnoise3.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122263731811, "lm_q2_score": 0.8918110519076928, "lm_q1q2_score": 0.8091510710105774}} {"text": "% Generate an n-column convolution matirx of\n% An n-column convolution matrix of p is the matrix for the \n% linear transformation L(f) = p*f for polynomial f of degree n-1.\n% If f is the coefficient vector of f, and C is the convolution matrix,\n% then C*f is the coefficient vector of p*f.\n%\n% Syntax: C = ConvolutionMatrix(p,n)\n%\n% Input: p --- (string or vector) the univariate polynomial\n% n --- (integer) the column dimension of the convolution matrix\n%\n% Output: C --- the convolution matrix\n%\n% Example: >> p = '1+3*x^4-6*x^8';\n% >> C = ConvolutionMatrix(p,3)\n% C =\n% -6 0 0\n% 0 -6 0\n% 0 0 -6\n% 0 0 0\n% 3 0 0\n% 0 3 0\n% 0 0 3\n% 0 0 0\n% 1 0 0\n% 0 1 0\n% 0 0 1\n", "meta": {"author": "zarathustr", "repo": "LibQPEP", "sha": "99e5c23e746ace0bac4a86742c31db6fcf7297ba", "save_path": "github-repos/MATLAB/zarathustr-LibQPEP", "path": "github-repos/MATLAB/zarathustr-LibQPEP/LibQPEP-99e5c23e746ace0bac4a86742c31db6fcf7297ba/MATLAB/homotopy/ConvolutionMatrix.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248174286374, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.8090057564804249}} {"text": "function c=dctii(f,L,dim)\n%DCTII Discrete Consine Transform type II\n% Usage: c=dctii(f);\n% c=dctii(f,L);\n% c=dctii(f,[],dim);\n% c=dctii(f,L,dim);\n%\n% `dctii(f)` computes the discrete cosine transform of type II of the\n% input signal *f*. If *f* is multi-dimensional, the transformation is\n% applied along the first non-singleton dimension.\n%\n% `dctii(f,L)` zero-pads or truncates *f* to length *L* before doing the\n% transformation.\n%\n% `dctii(f,[],dim)` or `dctii(f,L,dim)` applies the transformation along\n% dimension *dim*.\n%\n% The transform is real (output is real if input is real) and orthonormal.\n%\n% This is the inverse of |dctiii|.\n%\n% Let *f* be a signal of length *L*, let `c=dctii(f)` and define the\n% vector *w* of length *L* by\n%\n% .. w = [1/sqrt(2) 1 1 1 1 ...]\n%\n% .. math:: w\\left(n\\right)=\\begin{cases}\\frac{1}{\\sqrt{2}} & \\text{if }n=0\\\\1 & \\text{otherwise}\\end{cases}\n%\n% Then \n%\n% .. L-1\n% c(n+1) = sqrt(2/L) * sum w(n+1)*f(m+1)*cos(pi*n*(m+.5)/L) \n% m=0 \n%\n% .. math:: c\\left(n+1\\right)=\\sqrt{\\frac{2}{L}}\\sum_{m=0}^{L-1}w\\left(n\\right)f\\left(m+1\\right)\\cos\\left(\\frac{\\pi}{L} n\\left(m+\\frac{1}{2}\\right)\\right)\n%\n% Examples:\n% ---------\n%\n% The following figures show the first 4 basis functions of the DCTII of\n% length 20:::\n%\n% % The dctiii is the adjoint of dctii.\n% F=dctiii(eye(20));\n%\n% for ii=1:4\n% subplot(4,1,ii);\n% stem(F(:,ii));\n% end;\n%\n% See also: dctiii, dctiv, dstii\n%\n% References: rayi90 wi94\n\n% AUTHOR: Peter L. Søndergaard\n% TESTING: TEST_PUREFREQ\n% REFERENCE: REF_DCTII\n\ncomplainif_argnonotinrange(nargin,1,3,mfilename);\n\nif nargin<3\n dim=[];\nend;\n\nif nargin<2\n L=[];\nend;\n\n[f,L,Ls,W,dim,permutedsize,order]=assert_sigreshape_pre(f,L,dim,'DCTII');\n\nif ~isempty(L)\n f=postpad(f,L);\nend;\n c=comp_dct(f,2);\n% c=zeros(L,W,assert_classname(f));\n% \n% m1=1/sqrt(2)*exp(-(0:L-1)*pi*i/(2*L)).';\n% m1(1)=1;\n% \n% m2=1/sqrt(2)*exp((1:L-1)*pi*i/(2*L)).';\n% \n% s1=fft([f;flipud(f)]);\n% \n% % This could be done by a repmat instead.\n% for w=1:W\n% c(:,w)=s1(1:L,w).*m1+[0;s1(2*L:-1:L+2,w).*m2];\n% end;\n% \n% c=c/sqrt(L)/2;\n\nif isreal(f)\n c=real(c);\nend;\n\nc=assert_sigreshape_post(c,dim,permutedsize,order);\n\n% This is a slow, but convenient way of expressing the algorithm.\n%R=1/sqrt(2)*[diag(exp((0:L-1)*pi*i/(2*L)));...\n%\t zeros(1,L); ...\n%\t [zeros(L-1,1),flipud(diag(exp(-(1:L-1)*pi*i/(2*L))))]];\n\n%R(1,1)=1;\n\n%c=R'*fft([f;flipud(f)])/sqrt(L)/2;\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/fourier/dctii.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.8807970748488297, "lm_q1q2_score": 0.808994706347602}} {"text": "% This file runs univariate linear regression to predict profits of food trucks based on previous\n\n% actual values of profits in $10,000s in various cities with populations in 10,000s respectively. \n\nclear ; close all; clc ;\n\nfprintf('Plotting data\\n');\n\ndata = load('data_.txt');\nx = data(:, 1); Y = data(:, 2);\nn = length(Y); % Number of training examples.\n\nplotdata(x, Y);\n\nfprintf('Program paused, press enter to continue\\n');\n\npause;\n\nx = [ones(n, 1), data(:,1)]; \nTheta = zeros(2, 1);\n\nnoi = 1500; % Number of iterations in gradient descent. \nAlpha = 0.01; % Learning rate.\n\nfprintf('Testing the cost function\\n')\n\nj = computecost(x, Y, Theta);\nfprintf('With Theta = [0 ; 0]\\nCost computed = %f\\n', j);\nfprintf('Expected cost value (approx) 32.07\\n');\n\nj = computecost(x, Y, [-1 ; 2]);\nfprintf('With theta = [-1 ; 2]\\nCost computed = %f\\n', j);\nfprintf('Expected cost value (approx) 54.24\\n');\n\nfprintf('Program paused, press enter to continue\\n');\n\npause;\n\nfprintf('Running gradient descent\\n');\n\nTheta = gradientdescent(x, Y, Theta, Alpha, noi);\n\nfprintf('Theta found by gradient descent\\n');\nfprintf('%f\\n', Theta);\nfprintf('Expected Theta vector (approx)\\n');\nfprintf(' -3.6303\\n 1.1664\\n\\n');\n\nhold on; % To plot hypothesis on data. \n\nplot(x(:, 2), x * Theta, '-');\nlegend('Training data', 'Linear regression');\n\npredict1 = [1, 3.5] * Theta;\nfprintf('For population = 35,000, we predict a profit of %f\\n',...\n predict1*10000);\n\npredict2 = [1, 7] * Theta;\nfprintf('For population = 70,000, we predict a profit of %f\\n',...\n predict2*10000);", "meta": {"author": "TheAlgorithms", "repo": "MATLAB-Octave", "sha": "e150b77ad256de46c1ce3815c3d7945ac4fc28dc", "save_path": "github-repos/MATLAB/TheAlgorithms-MATLAB-Octave", "path": "github-repos/MATLAB/TheAlgorithms-MATLAB-Octave/MATLAB-Octave-e150b77ad256de46c1ce3815c3d7945ac4fc28dc/algorithms/machine_learning/Linear-Regression/runLinearRegression.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.947381048137938, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.8089807589097378}} {"text": "classdef InverseGammaD\n%%INVERSEGAMMAD Functions to handle the inverse gamma distribution.\n%Implemented methods are: mean, var, PDF, CDF, rand, entropy\n%\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nmethods(Static)\n\nfunction val=mean(k, beta)\n%%MEAN Obtain the mean of the inverse gamma distribution for given shape\n% and scale parameters.\n%\n%INPUTS: k The shape parameter of the distribution; k>0.\n% beta The scale parameter of the distribution; beta>0.\n%\n%OUTPUTS: val The mean of the inverse gamma distribution.\n%\n%If k<1, then the distribution has no mean and a NaN is returned.\n%\n%The distribution arises when estimating radar cross sections in Ch.\n%10.3.2 of [1].\n%\n%REFERENCES:\n%[1] W. Koch, Tracking and Sensor Fusion: Methodological Framework and\n% Selected Applications. Berlin, Germany: Springer, 2014.\n%\n%October 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n \n if(k<1)\n val=NaN;\n else\n val=beta/(k-1);\n end\nend\n\nfunction val=var(k,beta)\n%%VAR Obtain the variance of the inverse gamma distribution for given shape\n% and scale parameters.\n%\n%INPUTS: k The shape parameter of the distribution; k>0.\n% beta The scale parameter of the distribution; beta>0.\n%\n%OUTPUTS: val The variance of the inverse gamma distribution.\n%\n%If k<2, then the distribution has no variance and a NaN is returned.\n%\n%The distribution arises when estimating radar cross sections in Ch.\n%10.3.2 of [1].\n%\n%REFERENCES:\n%[1] W. Koch, Tracking and Sensor Fusion: Methodological Framework and\n% Selected Applications. Berlin, Germany: Springer, 2014.\n%\n%October 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n \n if(k<2)\n val=NaN;\n else\n val=beta^2/((k-1)^2*(k-2));\n end\nend \n \nfunction val=PDF(x,k,beta)\n%%PDF Evaluate the probability density function (PDF) of the inverse gamma\n% distribution at the desired points.\n%\n%INPUTS: x The point(s) at which the inverse gamma PDF is to be evaluated.\n% Note that x>=0.\n% k The shape parameter of the distribution; k>0.\n% beta The scale parameter of the distribution; beta>0.\n%\n%OUTPUTS: val The value(s) of the PDF of the inverse gamma distribution\n% with parameters k and beta evaluated at x.\n%\n%The inverse gamma distribution is the distribution of the inverse of a\n%gamma random variable. Thus, with a little bit of algebra, it can be\n%expressed in terms of the gamma PDF.\n%\n%The distribution arises when estimating radar cross sections in Ch.\n%10.3.2 of [1].\n%\n%REFERENCES:\n%[1] W. Koch, Tracking and Sensor Fusion: Methodological Framework and\n% Selected Applications. Berlin, Germany: Springer, 2014.\n%\n%October 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n val=(beta^k/gamma(k)).*x.^(-k-1).*exp(-beta./x);\nend\n \nfunction val=CDF(x,k,beta)\n%%CDF Evaluate the cumulative distribution function (CDF) of the inverse\n% gamma distribution at desired points.\n%\n%INPUTS: x The point(s) at which the inverse gamma CDF is to be evaluated.\n% Note that x>=0.\n% k The shape parameter of the distribution; k>0.\n% beta The scale parameter of the distribution; beta>0.\n%\n%OUTPUTS: prob The value(s) of the CDF of the inverse gamma distribution\n% with parameters k and beta evaluated at x.\n%\n%The inverse gamma distribution is the distribution of the inverse of a\n%gamma random variable. Thus, with a little bit of algebra, it can be\n%expressed in terms of the gamma PDF.\n%\n%The distribution arises when estimating radar cross sections in Ch.\n%10.3.2 of [1].\n%\n%REFERENCES:\n%[1] W. Koch, Tracking and Sensor Fusion: Methodological Framework and\n% Selected Applications. Berlin, Germany: Springer, 2014.\n%\n%October 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n val=1-GammaD.CDF(1./x,k,1/beta);\nend\n\nfunction vals=rand(N,k,beta)\n%%RAND Generate inverse gamma 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% k The shape parameter of the distribution; k>0.\n% beta The scale parameter of the distribution; beta>0.\n%\n%OUTPUTS: vals A matrix whose dimensions are determined by N of the\n% generated inverse gamma random variables.\n%\n%This just takes the inverse of gamma distributed random variables.\n%\n%October 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n vals=1./randGamma(N,k,1/beta);\nend\n\nfunction entropyVal=entropy(k,beta)\n%%ENTROPY Obtain the differential entropy of the inverse gamma\n% distribution given in nats. The differential entropy of a\n% continuous distribution is entropy=-int_x p(x)*log(p(x)) dx where\n% the integral is over all values of x. Units of nats mean that the\n% natural logarithm is used in the definition. Unlike the Shannon\n% entropy for discrete variables, the differential entropy of\n% continuous variables can be both positive and negative.\n%\n%INPUTS: k The shape parameter of the distribution; k>0.\n% beta The scale parameter of the distribution; beta>0.\n%\n%OUTPUTS: entropyVal The value of the differential entropy in nats.\n%\n%Differential entropy is defined in Chapter 8 of [1].\n%\n%REFERENCES:\n%[1] T. M. Cover and J. A. Thomas, Elements of Information Theory, 2nd ed.\n% Hoboken, NJ: Wiley-Interscience, 2006.\n%\n%April 2018 David F. Crouse, Naval Research Laboratory, Washington D.C.\n\n entropyVal=k+log(beta)+gammaln(k)-(1+k)*psi(k);\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/InverseGammaD.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810451666345, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.8089807546114581}} {"text": "function pde = sincosRobindata\n%% SINCOSDATA trigonometric data for Poisson equation\n%\n% f = 8*pi^2*sin(2*pi*x)*cos(2*pi*y);\n% u = sin(2*pi*x)*cos(2*pi*y);\n% Du = (2*pi*cos(2*pi*x)*cos(2*pi*y), -2*pi*sin(2*pi*x)*sin(2*pi*y));\n%\n% Impose Robin boundary condition g_R*u+ du/dn = g_N on [0,1]^2.\n%\n% Copyright (C) Long Chen. See COPYRIGHT.txt for details.\n\npde = struct('f',@f,'exactu',@exactu,'Du',@Du,'g_D',@g_D,'g_R',@g_R,'g_N',@g_N);\n\n% load data (right hand side function)\nfunction rhs = f(p)\n x = p(:,1); y = p(:,2);\n rhs = 8*pi^2*sin(2*pi*x).*cos(2*pi*y);\nend\n% exact solution\nfunction u = exactu(p)\n x = p(:,1); y = p(:,2);\n u = sin(2*pi*x).*cos(2*pi*y);\nend\n% derivative of the exact solution\nfunction uprime = Du(p)\n x = p(:,1); y = p(:,2);\n uprime(:,1) = 2*pi*cos(2*pi*x).*cos(2*pi*y);\n uprime(:,2) = -2*pi*sin(2*pi*x).*sin(2*pi*y);\nend\n% Dirichlet boundary condition\nfunction u = g_D(p)\n u = exactu(p);\nend\n% coefficients of Robin boundary condition g_R*u+ du/dn = g_N \nfunction f = g_R(p)\n f = ones(size(p,1),1);\nend\n% \nfunction f = g_N(p)\n f = zeros(size(p,1),1);\n x = p(:,1); y = p(:,2);\n uprime = Du(p);\n leftbd = (abs(x) 2011\n\n% Check input\nif ~isscalar(n) || ~isfinite(n) || n < 0 || fix(n) < n\n error('ICHOOSE:N','N must be a non-negative integer.')\nelseif ~isscalar(k) || ~isfinite(k) || k < 0 || fix(k) < k\n error('ICHOOSE:K','K must be a non-negative integer.')\nelseif n < k\n ind = zeros(0,k);\n return\nelseif k == 0\n ind = zeros(1,0);\n return\nend\n\n% Initiate indices\nif n < 256\n ind = uint8(k:n)';\nelseif n < 65536\n ind = uint16(k:n)';\nelse\n ind = (k:n)';\nend\n\nm = n-k+1;\nb = 1:m;\n\n% Generate indices\nfor j = 1:k-1\n a = b;\n b = cumsum(b);\n c = b(m) + 1 - b(1:m-1);\n if m > 1\n p = ones(b(m),1);\n p(c) = 1 - a(1:m-1);\n p = cumsum(p);\n ind = ind(p,:);\n end\n p = zeros(b(m),1);\n p(1) = k-j;\n p(c) = 1;\n p = cumsum(p);\n ind = [p,ind]; %#ok\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/30523-ichoose/ichoose.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.8774767970940975, "lm_q1q2_score": 0.8089650169373327}} {"text": "function [LL,lls]=normloglik(x,mu,sigma2)\n% Log-likelihood for the normal distribution\n%\n% USAGE:\n% [LL,LLS]=normloglik(X,MU,SIGMA2)\n%\n% INPUTS:\n% X - Normal random variables, either scalar or column vector\n% MU - Mean of X, either scalar or size(x)\n% SIGMA2 - Variance of X, either scalar or size(x)\n%\n% OUTPUTS:\n% LL - Log-likelihood evaluated at X\n% LLS - Vector of log-likelihoods corresponding to X\n%\n% COMMENTS:\n%\n% REFERENCES:\n% [1] Cassella and Berger (1990) 'Statistical Interence'\n%\n% See also NORMCDF, NORMINV, NORMRND, NORMPDF\n\n% Copyright: Kevin Sheppard\n% kevin.sheppard@economics.ox.ac.uk\n% Revision: 1 Date: 9/1/2005\n\n[T,K]=size(x);\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Input Checking\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nif K~=1\n error('x must be a column vector');\nend\n\nif nargin==1\n sigma2=ones(T,K);\nelseif nargin==2\n %Check mu's conformability\n if length(mu)~=1 && ~all(size(mu)==[T K])\n error('mu must be either a scalar or the same size as X');\n end\n x=x-mu;\n sigma2=ones(T,K);\nelseif nargin==3\n if length(mu)~=1 && ~all(size(mu)==[T K])\n error('mu must be either a scalar or the same size as X');\n end\n if any(sigma2<=0)\n error('sigma2 must contain only positive elements')\n end\n if length(sigma2)==1\n sigma2=sigma2*ones(T,K);\n elseif size(sigma2,1)~=T || size(sigma2,2)~=1\n error('sigma2 must be a scalar or a vector with the same dimensions as x');\n end\n x=x-mu;\nelse\n error('Only 1 to 3 inputs supported');\nend\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Input Checking\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\nif nargout>1\n%Compute the individual log likelihoods if needed\n lls = -0.5*(log(2*pi) + log(sigma2) + x.^2./sigma2);\n % Use these to comput the LL\n LL = sum(lls);\nelse\n %Compute the log likelihood\n LL = -0.5 * (sum(log(sigma2)) + sum((x.^2)./sigma2) + T*log(2*pi));\nend\n", "meta": {"author": "bashtage", "repo": "mfe-toolbox", "sha": "9622b6c546bc6d649fd9bf0a36a7fcd53872e04a", "save_path": "github-repos/MATLAB/bashtage-mfe-toolbox", "path": "github-repos/MATLAB/bashtage-mfe-toolbox/mfe-toolbox-9622b6c546bc6d649fd9bf0a36a7fcd53872e04a/distributions/normloglik.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.8774767842777551, "lm_q1q2_score": 0.8089650032392773}} {"text": "function x=fibosearch(fhandle,a,b,npoints)\n% fibonacci search for minimum of unknown unimodal function in one variable\n% x = fibosearch(fhandle,a,b,npoints)\n% a,b define the search interval with resolution 1/npoints\n%create fibonacci sequence of length nfibo\nnfibo=22;\nfibo=[1,1,zeros(1,nfibo-2)];\nfor k=1:nfibo-2\n fibo(k+2)=fibo(k+1)+fibo(k);\nend\n%find number of required iterations\nfiboindex=3;\nwhile fibo(fiboindex)' );\n ylabel ( '<--- Y --->' );\n title ( sprintf ( 'Lagrange/Chebyshev Polynomial Approximant of degree %d for %d nodes', m, nd ) )\n grid on\n hold off\n\n filename = sprintf ( 'p%02d_lagcheby_%02d_%02d.png', prob, m, nd );\n print ( '-dpng', filename );\n fprintf ( 1, ' Created plot file \"%s\".\\n', filename );\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/lagrange_approx_1d/lagrange_approx_1d_test03.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.8840392893839086, "lm_q1q2_score": 0.8088083839548768}} {"text": "function [ res, jac ] = opt07_rj ( x, flag )\n\n%*****************************************************************************80\n%\n%% OPT07_RJ evaluates RES and JAC for test case #7.\n%\n% Discussion:\n%\n% This example is known as the helical valley function.\n%\n% The optimizing value is\n%\n% X* = (1,0,0)\n%\n% for which\n%\n% RES(X*) = (0,0,0).\n%\n% Modified:\n%\n% 07 January 2008\n%\n% Author:\n%\n% Jeff Borggaard,\n% Gene Cliff,\n% Virginia Tech.\n%\n% Reference:\n%\n% John Dennis, Robert Schnabel,\n% Numerical Methods for Unconstrained Optimization \n% and Nonlinear Equations,\n% SIAM, 1996,\n% ISBN13: 978-0-898713-64-0,\n% LC: QA402.5.D44.\n%\n% Parameters:\n%\n% Input, real X(3), the evaluation point.\n%\n% Input, string FLAG, indicates what must be computed.\n% 'f' means only the value of RES is needed,\n% 'g' means only the value of JAC is needed,\n% 'all' means RES and JAC are needed.\n% It is acceptable to behave as though FLAG was 'all'\n% on every call.\n%\n% Output, real RES(3,1), the function column vector.\n%\n% Output, real JAC(3,3), the Jacobian matrix.\n%\n n = length ( x );\n\n if ( n ~= 3 )\n fprintf ( '\\n' );\n fprintf ( 'OPT07_RJ - Fatal error!\\n' );\n fprintf ( ' The input vector X should have length 3.\\n'), \n fprintf ( ' Instead, it has length = %d.\\n', n );\n keyboard\n end\n \n if ( 0 < x(1) )\n theta = atan ( x(2) / x(1) ) / ( 2 * pi );\n elseif ( x(1) < 0 )\n theta = atan ( x(2) / x(1) ) / ( 2 * pi ) + 0.5;\n elseif ( 0 < x(2) )\n theta = 0.25;\n elseif ( x(2) < 0 )\n theta = - 0.25;\n else\n theta = 0;\n end\n\n res = zeros(3,1);\n\n res(1,1) = 10 * ( x(3) - 10 * theta );\n res(2,1) = 10 * ( sqrt ( x(1)^2 + x(2)^2 ) - 1 );\n res(3,1) = x(3);\n\n if ( x(1)^2 + x(2)^2 == 0 )\n dtdx1 = 0;\n dtdx2 = 0;\n else\n dtdx1 = - x(2) / ( 2 * pi * ( x(1)^2 + x(2)^2 ) );\n dtdx2 = x(1) / ( 2 * pi * ( x(1)^2 + x(2)^2 ) );\n end\n\n jac = zeros(3,3);\n\n jac(1,1) = -100 * dtdx1;\n jac(1,2) = -100 * dtdx2;\n jac(1,3) = 10;\n\n if ( x(1)^2 + x(2)^2 == 0 )\n jac(2,1) = 0;\n jac(2,2) = 0;\n else\n jac(2,1) = 10 * x(1) / sqrt ( x(1)^2 + x(2)^2 );\n jac(2,2) = 10 * x(2) / sqrt ( x(1)^2 + x(2)^2 );\n end\n jac(2,3) = 0;\n\n jac(3,1) = 0;\n jac(3,2) = 0;\n jac(3,3) = 1;\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/entrust/opt07_rj.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742806, "lm_q2_score": 0.8840392725805823, "lm_q1q2_score": 0.8088083829403083}} {"text": "function sp=orthpoly(n,opfamily,alpha,beta)\n% orthpoly: generate an n'th order (symbolic) orthogonal polynomial\n% usage: sp=orthpoly(n,opfamily,alpha,beta);\n% \n% arguments: (input)\n% n - order of polynomial requested\n%\n% opfamily - (OPTIONAL) character string - specifies the\n% type of orthogonal polynomial to be generated.\n% Legal polytypes are: {'legendre', 'hermite',\n% '1cheby', '2cheby', 'laguerre', 'jacoby'}\n%\n% Default == 'legendre'\n% \n% Note: 1cheby refers to first kind\n% chebychev polynomials (Tn(x)),\n% and 2cheby refers to second kind\n% chebychev polynomials (Un(x))\n% \n% The domain of support is [-1,1] for the polynomial\n% families 'legendre', '1cheby', '2cheby', 'jacoby'.\n% It is [0,inf] for 'laguerre', and [-inf,inf] for\n% the 'hermite' family.\n%\n% See Abramowitz & Stegun for in-depth information\n% on all of these polynomial families.\n%\n% alpha,beta - scalar - orthogonal family parameters - \n% See Abramowitz & Stegun for more information.\n%\n% These parameters are ignored for 'legendre',\n% 'hermite', '1cheby' and '2cheby' polys.\n%\n% arguments: (output)\n% p - sympoly object containing the polynomial\n\n% defaults\nif (nargin<2)|isempty(opfamily)\n % default is legendre\n opfamily = 'legendre';\nelse\n if ~ischar(opfamily)\n error 'Opfamily must be a character string'\n end\n valtypes = {'legendre', 'hermite', 'cheby1', '1chebychev' ...\n 'cheby2', '2chebychev', 'laguerre', 'jacobi'};\n \n ptind = strmatch(opfamily,valtypes);\n if isempty(ptind)\n % no match\n error 'Invalid opfamily'\n elseif length(ptind)>1\n % match more than one\n error 'Ambiguous opfamily'\n else\n % there was exactly one match\n opfamily = valtypes{ptind};\n end\nend\n\nif nargin<1\n error 'Polynomial order must be supplied. No default for n.'\nend\n\nif (nargin<3) || isempty(alpha)\n % default is 0\n alpha = 0;\nend\n\nif (nargin<4) || isempty(beta)\n % default is 0\n beta = 0;\nend\n\n% initialize (-1)'th and zero'th order sympolys\n% for the three term recurrence relation.\npnm1=sympoly(0);\npn=sympoly(1);\nx=sympoly('x');\n\nif n==0\n % p0 is easy to get\n sp=pn;\n return\nelseif n<0\n error 'Polynomial order must not be negative'\nend\n\n% iterate to get polynomial\nfor i=0:(n-1)\n switch opfamily\n case 'legendre'\n pnp1=((2*i+1)*x*pn - i*pnm1)./(i+1);\n % normalize so that Tn(1)=1\n pnp1=pnp1./double(subs(pnp1,'x',1));\n \n case 'hermite'\n % neither alpha nor beta is meaningful\n pnp1=2*pn*x - 2*i*pnm1;\n \n case 'laguerre'\n % only alpha is meaningful here\n pnp1=((2*i+alpha+1)*pn - pn*x - (i+alpha)*pnm1)./(i+1);\n \n case {'cheby1' '1chebychev'}\n % first kind chebychev\n % neither alpha nor beta is meaningful\n pnp1=(2*pn*x - pnm1);\n % normalize so that Tn(1)=1\n pnp1=pnp1/double(subs(pnp1,'x',1));\n \n case {'cheby2' '2chebychev'}\n % second kind chebychev\n % neither alpha nor beta is meaningful\n pnp1=(2*pn*x - pnm1);\n \n case 'jacobi'\n % both alpha and beta are needed\n if (alpha~=0) | (beta~=0)\n a1n=2*(i+1)*(i+alpha+beta+1)*(2*i+alpha+beta);\n a2n=(2*i+alpha+beta+1)*(alpha^2-beta^2);\n if (2*i+alpha+beta)<=150\n a3n=gamma(2*i+alpha+beta+3)./gamma(2*i+alpha+beta);\n else\n a3n=exp(gammaln(2*i+alpha+beta+3)-gammaln(2*i+alpha+beta));\n end\n a4n=2*(i+alpha)*(i+beta)*(2*i+alpha+beta+2);\n pnp1=(a2n*pn + a3n*pn*x - a4n*pnm1)/a1n;\n else\n pnp1=((2*i+1)*pn*x - i*pnm1)/(i+1);\n end\n end\n pnm1=pn;\n pn=pnp1;\n\nend\n\n% return the generated sympoly\nsp=pnp1;\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/9577-symbolic-polynomial-manipulation/SymbolicPolynomials/orthpoly.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069105, "lm_q2_score": 0.8740772417253256, "lm_q1q2_score": 0.8087224434503708}} {"text": "%% Generating the leading mode-n vectors\n% The leading mode-n vectors are those vectors that span the subspace of\n% the mode-n fibers. In other words, the left singular vectors of the\n% n-mode matricization of X. \n%% Using nvecs to calculate the leading mode-n vectors\n% The |nvecs| command efficient computes the leading n-mode vectors.\nrand('state',0);\nX = sptenrand([4,3,2],6) %<-- A sparse tensor\n%%\nnvecs(X,1,2) %<-- The 2 leading mode-1 vectors\n%% \nnvecs(X,1,3) % <-- The 3 leading mode-1 vectors\n%%\nnvecs(full(X),1,3) %<-- The same thing for a dense tensor\n%%\nX = ktensor({rand(3,2),rand(3,2),rand(2,2)}) %<-- A random ktensor\n%%\nnvecs(X,2,1) %<-- The 1 leading mode-2 vector\n%%\nnvecs(full(X),2,1) %<-- Same thing for a dense tensor\n%%\nX = ttensor(tenrand([2,2,2,2]),{rand(3,2),rand(3,2),rand(2,2),rand(2,2)}); %<-- A random ttensor\n%%\nnvecs(X,4,2) %<-- The 1 leading mode-2 vector\n%%\nnvecs(full(X),4,2) %<-- Same thing for a dense tensor\n%% Using nvecs for the HOSVD\nX = tenrand([4 3 2]) %<-- Generate data\n%% \nU1 = nvecs(X,1,4); %<-- Mode 1\nU2 = nvecs(X,2,3); %<-- Mode 2\nU3 = nvecs(X,3,2); %<-- Mode 3\nS = ttm(X,{pinv(U1),pinv(U2),pinv(U3)}); %<-- Core\nY = ttensor(S,{U1,U2,U3}) %<-- HOSVD of X\n%%\nnorm(full(Y) - X) %<-- Reproduces the same result.\n\n%% \nU1 = nvecs(X,1,2); %<-- Mode 1\nU2 = nvecs(X,2,2); %<-- Mode 2\nU3 = nvecs(X,3,2); %<-- Mode 3\nS = ttm(X,{pinv(U1),pinv(U2),pinv(U3)}); %<-- Core\nY = ttensor(S,{U1,U2,U3}) %<-- Rank-(2,2,2) HOSVD approximation of X\n%%\n100*(1-norm(full(Y)-X)/norm(X)) %<-- Percentage explained by approximation", "meta": {"author": "andrewssobral", "repo": "mtt", "sha": "0152a77df09f24af4c294f46845931e4e0e63b55", "save_path": "github-repos/MATLAB/andrewssobral-mtt", "path": "github-repos/MATLAB/andrewssobral-mtt/mtt-0152a77df09f24af4c294f46845931e4e0e63b55/libs/tensor_toolbox_2.5/doc/N_nvecs_doc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.8740772269642949, "lm_q1q2_score": 0.8087224406055818}} {"text": "function val=cosInt(x)\n%%COSINT Evaluate the cosine integral of a real non-negative value x. The\n% cosine integral of x is defined to be the negative of the integral\n% from x to infinity of cos(t)/t dt. The derivative of the cosine\n% integral function is cos(x)/x.\n%\n%INPUTS: x A matrix of non-negative real values, at which one wishes to\n% evaluate the cosine integral. x does not have to be finite.\n%\n%OUTPUTS: val A matrix of the real values of the cosine integral evaluated \n% at the points in x.\n%\n%The cosine integral can be related to the exponential integral as\n%discussed in [1]. This function uses Matlab's built-in expint function to\n%evaluate the cosine integral using the expint function.\n%\n%The cosine integral asymptotically approaches zero. If the results from\n%the exponential integral functions are not finite, then it is assumed that\n%the corresponding values of x were too large and the asymptotic result (0)\n%is substituted.\n%\n%x should be non-negative. If negative values of x are (incorrectly)\n%provided, then the value of cosInt(abs(x)) is returned. Strict definitions\n%of the cosine integral are usually such that negative values return\n%complex numbers.\n%\n%REFERENCES:\n%[1] Weisstein, Eric W. \"Cosine Integral.\" From MathWorld--A Wolfram Web\n% Resource. http://mathworld.wolfram.com/CosineIntegral.html\n%\n%June 2014 David F.Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n %The real function is in case of finite precision problems.\n val=-0.5*real(expint(1j*x)+expint(-1j*x));\n val(~isfinite(val))=0;\n \n %Make sure that NaN inputs remain NaN on the output.\n val(isnan(x))=NaN;\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/Specific_Integrals/cosInt.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.8740772269642949, "lm_q1q2_score": 0.8087224388034888}} {"text": "function value = r8vec_diff_norm ( n, a, b )\n\n%*****************************************************************************80\n%\n%% R8VEC_DIFF_NORM returns the L2 norm of the difference of R8VEC's.\n%\n% Discussion:\n%\n% The vector L2 norm is defined as:\n%\n% value = sqrt ( sum ( 1 <= I <= N ) A(I)**2 ).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 April 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of entries in A.\n%\n% Input, real A(N), B(N), the vectors.\n%\n% Output, real VALUE, the L2 norm of A - B.\n%\n value = norm ( a(1:n) - b(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/r8lib/r8vec_diff_norm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.8740772318846386, "lm_q1q2_score": 0.8087224379496589}} {"text": "function [ f, g, H ] = opt02_fgh ( x, flag )\n\n%*****************************************************************************80\n%\n%% OPT02_FGH evaluates F, G and H for test case #2.\n%\n% Discussion:\n%\n% This example is discussed in Dennis and Schnabel, pages 120 and 138.\n%\n% A suggested initial value for X is\n%\n% X init = ( 1, 1 ).\n%\n% The optimizing value is\n%\n% X* = ( 0, 0 )\n%\n% and the optimal function value is\n%\n% F(X*) = 0.\n%\n% Modified:\n%\n% 02 January 2008\n%\n% Author:\n%\n% Jeff Borggaard,\n% Gene Cliff,\n% Virginia Tech.\n%\n% Reference:\n%\n% John Dennis, Robert Schnabel,\n% Numerical Methods for Unconstrained Optimization \n% and Nonlinear Equations,\n% SIAM, 1996,\n% ISBN13: 978-0-898713-64-0,\n% LC: QA402.5.D44.\n%\n% Parameters:\n%\n% Input, real X(2), the evaluation point.\n%\n% Input, string FLAG, indicates what must be computed.\n% 'f' means only the value of F is needed,\n% 'g' means only the value of G is needed,\n% 'all' means F, G and H (if appropriate) are needed.\n% It is acceptable to behave as though FLAG was 'all'\n% on every call.\n%\n% Output, real F, the optimization function.\n%\n% Output, real G(2,1), the gradient column vector.\n%\n% Output, real H(2,2), the Hessian matrix.\n%\n n = length ( x );\n\n if ( n ~= 2 )\n fprintf ( '\\n' );\n fprintf ( 'OPT02_FGH - Fatal error!\\n' );\n fprintf ( ' The input vector X should have length 2.\\n'), \n fprintf ( ' Instead, it has length = %d.\\n', n );\n keyboard\n end\n\n f = x(1)^4 + x(1)^2 + x(2)^2;\n\n g = [ 4*x(1)^3 + 2*x(1); 2*x(2) ];\n\n H = [ 12*x(1) + 2 , 0 ;\n 0 , 2 ];\n\n return\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/entrust/opt02_fgh.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.9099070097026719, "lm_q1q2_score": 0.8086878507716772}} {"text": "function dist = sphere01_distance_xyz ( xyz1, xyz2 )\n\n%*****************************************************************************80\n%\n%% SPHERE01_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% 22 September 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 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 = 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/sphere_triangle_quad/sphere01_distance_xyz.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.8652240860523328, "lm_q1q2_score": 0.8084612005211977}} {"text": "function [ num_int, p ] = circles_imp_int_2d ( r1, center1, r2, center2 )\n\n%*****************************************************************************80\n%\n%% CIRCLES_IMP_INT_2D: finds the intersection of two implicit circles in 2D.\n%\n% Discussion:\n%\n% Two circles can intersect in 0, 1, 2 or infinitely many points.\n%\n% The 0 and 2 intersection cases are numerically robust; the 1 and\n% infinite intersection cases are numerically fragile. The routine\n% uses a tolerance to try to detect the 1 and infinite cases.\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% 24 February 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real R1, the radius of the first circle.\n%\n% Input, real CENTER1(2,1), the center of the first circle.\n%\n% Input, real R2, the radius of the second circle.\n%\n% Input, real CENTER2(2,1), the center of the second circle.\n%\n% Output, integer NUM_INT, the number of intersecting points found.\n% NUM_INT will be 0, 1, 2 or 3. 3 indicates that there are an infinite\n% number of intersection points.\n%\n% Output, real P(2,2), if NUM_INT is 1 or 2,\n% the coordinates of the intersecting points.\n%\n dim_num = 2;\n\n tol = eps;\n\n p(1:dim_num,1:2) = 0.0;;\n%\n% Take care of the case in which the circles have the same center.\n%\n t1 = ( abs ( center1(1,1) - center2(1,1) ) ...\n + abs ( center1(2,1) - center2(2,1) ) ) / 2.0;\n\n t2 = ( abs ( center1(1,1) ) + abs ( center2(1,1) ) ...\n + abs ( center1(2,1) ) + abs ( center2(2,1) ) + 1.0 ) / 5.0;\n\n if ( t1 <= tol * t2 )\n\n t1 = abs ( r1 - r2 );\n t2 = ( abs ( r1 ) + abs ( r2 ) + 1.0 ) / 3.0;\n\n if ( t1 <= tol * t2 )\n num_int = 3;\n else\n num_int = 0;\n end\n\n return\n\n end\n\n distsq = sum ( ( center1(1:2,1) - center2(1:2,1) ).^2 );\n\n root = 2.0 * ( r1 * r1 + r2 * r2 ) * distsq - distsq * distsq ...\n - ( r1 - r2 ) * ( r1 - r2 ) * ( r1 + r2 ) * ( r1 + r2 );\n\n if ( root < -tol )\n num_int = 0;\n return\n end\n\n sc1 = ( distsq - ( r2 * r2 - r1 * r1 ) ) / distsq;\n\n if ( root < tol )\n num_int = 1;\n p(1:dim_num,1) = center1(1:dim_num,1) ...\n + 0.5 * sc1 * ( center2(1:dim_num,1) - center1(1:dim_num,1) );\n return\n end\n\n sc2 = sqrt ( root ) / distsq;\n\n num_int = 2;\n\n p(1,1) = center1(1,1) + 0.5 * sc1 * ( center2(1,1) - center1(1,1) ) ...\n - 0.5 * sc2 * ( center2(2,1) - center1(2,1) );\n p(2,1) = center1(2,1) + 0.5 * sc1 * ( center2(2,1) - center1(2,1) ) ...\n + 0.5 * sc2 * ( center2(1,1) - center1(1,1) );\n\n p(1,2) = center1(1,1) + 0.5 * sc1 * ( center2(1,1) - center1(1,1) ) ...\n + 0.5 * sc2 * ( center2(2,1) - center1(2,1) );\n p(2,2) = center1(2,1) + 0.5 * sc1 * ( center2(2,1) - center1(2,1) ) ...\n - 0.5 * sc2 * ( center2(1,1) - center1(1,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/geometry/circles_imp_int_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506726044381, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.8084522100529656}} {"text": "function value = r8vec_diff_norm_l1 ( n, a, b )\n\n%*****************************************************************************80\n%\n%% R8VEC_DIFF_NORM_L1 returns the L1 norm of the difference of R8VEC's.\n%\n% Discussion:\n%\n% The vector L1 norm is defined as:\n%\n% value = sum ( 1 <= I <= N ) abs ( A(I) ).\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 April 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of entries in A.\n%\n% Input, real A(N), B(N), the vectors.\n%\n% Output, real VALUE, the L1 norm of A - B.\n%\n value = sum ( abs ( a(1:n) - b(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/r8lib/r8vec_diff_norm_l1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.8872045952083047, "lm_q1q2_score": 0.8084028300628253}} {"text": "function b = isPointOnLine3d(point, line, varargin)\n%ISPOINTONLINE3D Test if a 3D point belongs to a 3D line.\n%\n% B = isPointOnLine3d(POINT, LINE)\n% with POINT being [xp yp zp], and LINE being [x0 y0 z0 dx dy dz].\n% Returns 1 if point lies on the line, 0 otherwise.\n%\n% If POINT is an N-by-3 array of points, B is a N-by-1 array of booleans.\n%\n% If LINE is a N-by-6 array of lines, B is a N-by-1 array of booleans.\n%\n% B = isPointOnLine3d(POINT, LINE, TOL)\n% Specifies the tolerance used for testing location on 3D line.\n%\n% See also: \n% lines3d, distancePointLine3d, linePosition3d, isPointOnLine\n%\n\n% ---------\n% author : David Legland \n% e-mail: david.legland@inra.fr\n% INRA - TPV URPOI - BIA IMASTE\n% created the 31/10/2003.\n%\n\n% HISTORY\n% 17/12/2013 create from isPointOnLine\n\n% extract computation tolerance\ntol = 1e-14;\nif ~isempty(varargin)\n tol = varargin{1};\nend\n\n% test if lines are colinear, using norm of the cross product\nb = bsxfun(@rdivide, vectorNorm3d( ...\n crossProduct3d(bsxfun(@minus, line(:,1:3), point), line(:,4:6))), ...\n vectorNorm3d(line(:,4:6))) < tol;\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/z_geom3d/geom3d/isPointOnLine3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8872045817875224, "lm_q1q2_score": 0.8084028114144305}} {"text": "function area = polygonArea(poly, varargin)\n%POLYGONAREA Compute the signed area of a polygon.\n%\n% A = polygonArea(POINTS);\n% Compute area of a polygon defined by POINTS. POINTS is a N-by-2 array\n% of double containing coordinates of vertices.\n% \n% Vertices of the polygon are supposed to be oriented Counter-Clockwise\n% (CCW). In this case, the signed area is positive.\n% If vertices are oriented Clockwise (CW), the signed area is negative.\n%\n% If polygon is self-crossing, the result is undefined.\n%\n% Examples\n% % compute area of a simple shape\n% poly = [10 10;30 10;30 20;10 20];\n% area = polygonArea(poly)\n% area = \n% 200\n%\n% % compute area of CW polygon\n% area2 = polygonArea(poly(end:-1:1, :))\n% area2 = \n% -200\n%\n% % Computes area of a paper hen\n% x = [0 10 20 0 -10 -20 -10 -10 0];\n% y = [0 0 10 10 20 10 10 0 -10];\n% poly = [x' y'];\n% area = polygonArea(poly)\n% area =\n% 400\n%\n% % Area of unit square with 25% hole\n% pccw = [0 0; 1 0; 1 1; 0 1];\n% pcw = pccw([1 4 3 2], :) * .5 + .25;\n% polygonArea ([pccw; nan(1,2); pcw])\n% ans =\n% 0.75\n%\n% References\n% algo adapted from P. Bourke web page\n% http://paulbourke.net/geometry/polygonmesh/\n%\n% See also:\n% polygons2d, polygonCentroid, polygonSecondAreaMoments, triangleArea\n%\n\n% ---------\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 05/05/2004.\n%\n\n% HISTORY\n% 25/04/2005: add support for multiple polygons\n% 12/10/2007: update doc\n\n\n%% Process special cases\n\n% in case of polygon sets, computes the sum of polygon areas\nif iscell(poly)\n area = 0;\n for i = 1:length(poly)\n area = area + polygonArea(poly{i});\n end\n return;\nend\n\n% check there are enough points\nif size(poly, 1) < 2\n area = 0;\n return;\nend\n\n% case of polygons with holes -> computes the sum of areas\nif any(isnan(poly))\n area = sum(polygonArea(splitPolygons(poly)));\n return;\nend\n\n\n%% Process single polygons or single rings\n\n% extract coordinates\nif nargin == 1\n % polygon given as N-by-2 array\n px = poly(:, 1);\n py = poly(:, 2);\n \nelseif nargin == 2\n % poylgon given as two N-by-1 arrays\n px = poly;\n py = varargin{1};\nend\n\n% indices of next vertices\nN = length(px);\niNext = [2:N 1];\n\n% compute area (vectorized version)\narea = sum(px .* py(iNext) - px(iNext) .* py) / 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/private/polygonArea.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.8824278680004707, "lm_q1q2_score": 0.8084006551955524}} {"text": "function [ i_choose, w_choose ] = subset_sum_task ( weights, target, range )\n\n%*****************************************************************************80\n%\n%% SUBSET_SUM_TASK seeks a subset of a set that has a given sum.\n%\n% Discussion:\n%\n% This function tries to compute a target value as the sum of\n% a selected subset of a given set of weights.\n%\n% This function works by brute force, that is, it tries every\n% possible subset to see if it sums to the desired value.\n%\n% Given N weights, every possible selection can be described by \n% one of the N-digit binary numbers from 0 to 2^N-1.\n%\n% This function includes a range, which allows the user to \n% control which subsets are to be checked. Thus, if there are \n% N weights, specifying a range of [ 0, 2^N-1] indicates that\n% all subsets should be checked. On the other hand, this full\n% range could be broken down into smaller subranges, each of\n% which could be checked independently.\n%\n% It is possible that, in the given range, there may be multiple\n% solutions of the problem. This function will only return\n% one such solution, if found.\n%\n% Example:\n%\n% [ c, wv ] = subset_sum_task ( [1 2 4 8 16 32], 22, [0 2^6 - 1] )\n%\n% c = 2 3 5\n% wv = 2 4 16\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 10 May 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer WEIGHTS(N), a set of weights.\n%\n% Input, integer TARGET, the target value.\n%\n% Input, integer RANGE(2), the lower and upper limits to be searched.\n%\n% Output, integer I_CHOOSE(K), the indices of the chosen weights.\n%\n% Output, integer W_CHOOSE(K), the values of the chosen weights.\n%\n\n%\n% Initialize the output to empty matrices.\n%\n i_choose = [];\n w_choose = [];\n%\n% Iterate through all possible combinations in the provided range.\n%\n n = length ( weights );\n\n for i = range(1) : range(2)\n%\n% Find the combination of weights represented by the current attempt.\n%\n choose = find ( bitget ( i, 1:n ) );\n%\n% If the sum of those weights matches the target, return combination.\n%\n if ( sum ( weights(choose) ) == target )\n i_choose = choose;\n w_choose = weights(choose);\n return\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/subset_sum_tasks/subset_sum_task.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723468, "lm_q2_score": 0.8757870029950159, "lm_q1q2_score": 0.8083857107692923}} {"text": "%% 1D Linear Advection Equation\n%\n% du/dt + a du/dx = 0\n%\n% Ref's: \n% Randall J. Leveque;\n% Finite Volume Methods for Hyperbolic Problems\n% Cambridge Press, 2002.\n%\n% Subroutine for solving using Upwind Method.\n% by Manuel Diaz, manuel.ade'at'gmail.com \n% Institute of Applied Mechanics, 2012.08.12\n\nclear all; close all; clc;\n\n%% Parameters\na = 0.5;\na_m = min(0,a);\na_p = max(0,a);\ndx = 0.01;\ncfl = 0.9;\ndt = cfl*dx/abs(a);\nt_end = 0.6;\n\n%% Discretization of Domain\nx = 1:dx:2;\nt = 0:dt:t_end;\n\n%% Initial Condition\nn = length(x);\n%u_0 = zeros(1,n);\nu0(1:ceil(n/2)) = 1;\nu0((ceil(n/2)+1):n) = 2;\n\n%% Main Loop\n% Initilize vector variables\nu_next = zeros(size(u0)); % u^{n+1}\nu_bar1 = zeros(size(u0)); % preallocate for MacCormack\nu_bar2 = zeros(size(u0)); % preallocate for MacCormack\n\n% Load Initial condition\nu = u0;\n\n% Main Loop\nfor k = t\n % plot every time step\n plot(x,u,'.')\n \n for j = 2:n-1 \n % Single Sided Upwind\n %u_next(j) = u(j) - a*dt/dx*(u(j)-u(j-1)); % Upwind\n %u_next(j) = u(j) - a*dt/dx*(u(j+1)-u(j)); % Downwind\n \n % Double Sided Upwind\n u_next(j) = u(j) - a_p*dt/dx*(u(j)-u(j-1)) - a_m*dt/dx*(u(j+1)-u(j));\n \n % Comparing to Lax-Wendroff:\n %u_next(j) = u(j) - a*dt/(2*dx)*(u(j+1)-u(j-1)) ...\n % +(dt^2/2)/(dx^2)*(a^2)*(u(j+1)-2*u(j)+u(j-1)); % LW\n \n % Comparing to MacCormack Method:\n % Predictor steps\n %u_bar1(j) = u(j) - a*dt/dx*(u(j+1)-u(j)); \n % u_bar1(1) = u_bar1(2); % Neumann BC in predictor step\n %u_bar2(j) = u_bar1(j) - a*dt/dx*(u_bar1(j)-u_bar1(j-1)); \n % Corrector step\n %u_next(j) = 1/2*(u(j)+u_bar2(j));\n end\n % BC\n u_next(1) = u_next(2); % Neumann BC\n u_next(n) = u_next(n-1); % Neumann BC\n \n % UPDATE info\n u = u_next(1:n);\n \n % update figure\n pause(0.05); drawnow\nend\n \n%% Plot final Result\nplot(x,u,'.')", "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/CFD/Upwind.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558356, "lm_q2_score": 0.8757870013740061, "lm_q1q2_score": 0.808385694440054}} {"text": "function C = hcp_lattice(I,J,K)\n % HCP_LATTICE generate the center locations of a hexagonal close-packed\n % lattice of unit-radius spheres.\n %\n % Inputs:\n % I #I list of x-coordinate indices\n % J #I list of y-coordinate indices\n % K #I list of z-coordinate indices\n % Outputs:\n % C #I by 3 list of center locations\n %\n % Example:\n % [I,J,K] = meshgrid(0:9,0:9,0:9);\n % C = hcp_lattice(I(:),J(:),K(:));\n % [SV,SF] = lloyd_sphere(300);\n % [V,F] = repmesh(SV,SF,C);\n i = I(:);\n j = J(:);\n k = K(:);\n % https://en.wikipedia.org/wiki/Close-packing_of_equal_spheres#Simple_hcp_lattice\n C = [2*i + mod(j+k,2), sqrt(3)*(j+1/3*mod(k,2)), 2*sqrt(6)/3*k];\nend\n", "meta": {"author": "alecjacobson", "repo": "gptoolbox", "sha": "a0cb37d8edbcfb1e3587f793df8f24c76a2d7305", "save_path": "github-repos/MATLAB/alecjacobson-gptoolbox", "path": "github-repos/MATLAB/alecjacobson-gptoolbox/gptoolbox-a0cb37d8edbcfb1e3587f793df8f24c76a2d7305/mesh/hcp_lattice.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.8083806151054272}} {"text": "function areRPrime=areRelativelyPrime(a)\n%%ARERELATIVELYPRIME Determine whether a set of numbers is relatively\n% prime (are coprime). A collections of numbers are\n% relatively prime if the greatest common divisor between all\n% pairs of the numbers is 1. Relatively prime numbers are\n% also known as coprime numbers.\n%\n%INPUTS: a An nXnumSets set of numSets sets of n-integers where one wishes\n% to determine whether the n numbers in each set are relatively\n% prime.\n%\n%OUTPUTS: areRPrime A numSetsX1 boolean array indicating whether the\n% numbers in each set are coprime.\n%\n%Coprime numbers arise in a number of areas, such as in the Chinese\n%remainder theorem. This function jst goes through all pairs of numbers and\n%uses the gcd function to see whether the greatest common divisor between\n%all pairs is 1.\n%\n%EXAMPLE:\n% a=zeros(3,2);\n% %This set of numbers is coprime even though 4 is not a prime number.\n% a(:,1)=[7;9;4];\n% %This set of numbers is not coprime\n% a(:,2)=[3;2;9];\n% areRPrime=areRelativelyPrime(a)\n%The functions returns [1;0]\n%\n%September 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nN=size(a,1);\nnumSets=size(a,2);\n\nareRPrime=true(numSets,1);\n\nfor curSet=1:numSets\n for n1=1:(N-1)\n for n2=(n1+1):N\n if(gcd(a(n1,curSet),a(n2,curSet))~=1)\n areRPrime(curSet)=false;\n break;\n end\n end\n \n if(areRPrime(curSet)~=true)\n break;\n end\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/areRelativelyPrime.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.8947894625955064, "lm_q1q2_score": 0.8082581401116439}} {"text": "% Find cycles of length 4 in a graph;\n% Note: Valid for an undirected graph only\n%\n% INPUTS: adjacency matrix\n% OUTPUTS: number of 4-cycles, for which no edges repeat in the cycle\n\n% Other routines used: numEdges.m, numConnTriples.m, cycles3.m\n% GB: last updated January 28, 2016\n\nfunction l4 = cycles4(adj)\n\n\tl4 = trace(adj^4) - 2*numEdges(adj) - 4*numConnTriples(adj) - 8*cycles3(adj);\n\n\tl4 = l4/8;", "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/cycles4.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9381240142763574, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.8082296784811892}} {"text": "%% Solving LQR via SDP (LMIs)\n% http://www1.se.cuhk.edu.hk/~zhang/Courses/Seg5660/Lecture%206.pdf\n\n%% Continuous LQR\nclc\nGs = tf(2,[0.5 0.2 0.1]);\n[A,B] = ssdata(ss(Gs));\nQ = diag([10;10]); R = 1;\n\n[K,S] = lqr(A,B,Q,R)\n\n%LQR LMI - Vars are P11 P12 P22\nP = sym('[P11 P12; P12 P22]')\nLp = vpa([R B'*P; P*B Q + A'*P + P*A],5)\n\n% Objective (max)\nf = -[1 0 1]; %just diagonal elements\n\n% Semidefinite Constraint (cheap way to pick off elements)\nC = -double(subs(Lp,P,zeros(2)));\nA1 = double(diff(Lp,P(1)));\nA2 = double(diff(Lp,P(2)));\nA3 = double(diff(Lp,P(end)));\nsdcone = sparse([C(:) A1(:) A2(:) A3(:)]);\n\n% Create OPTI Object\nOpt = opti('f',f,'sdcone',sdcone)\n% Solve the SDP\nx = solve(Opt)\n\n%Reform P and solve K\nP = [x(1) x(2); x(2) x(3)];\nKsdp = R\\(B'*P) %see help lqr\n\n%% Discrete LQR\nclc\nGd = c2d(Gs,0.1);\n[A,B] = ssdata(ss(Gd));\nQ = diag([10;10]); R = 1;\n\n[K,S] = dlqr(A,B,Q,R)\n\n%LQR LMI - Vars are P11 P12 P22\nP = sym('P',[2 2]); \nLp = vpa([B'*P*B+R B'*P*A; A'*P*B Q + A'*P*A - P],5)\n\n% Objective (max)\nf = -[1 0 1]; %just diagonal elements\n\n% Semidefinite Constraint (cheap way to pick off elements)\nC = -double(subs(Lp,P,zeros(2)));\nA1 = double(diff(Lp,P(1)));\nA2 = double(diff(Lp,P(2))) + double(diff(Lp,P(3)));\nA3 = double(diff(Lp,P(end)));\n\nsdcone = sparse([C(:) A1(:) A2(:) A3(:)]);\n\n% Create OPTI Object\nOpt = opti('f',f,'sdcone',sdcone)\n% Solve the SDP\nx = solve(Opt)\n\n%Reform P and solve K\nP = [x(1) x(2); x(2) x(3)];\nKsdp = (B'*P*B + R)\\(B'*P*A) %see help dlqr\n\n%% Continuous Lyapunov\nclc\n[A,B] = ssdata(ss(Gs));\nX = lyap(A,Q)\n\n%LYAP LMI - Vars are P11 P12 P22\nP = sym('P',[2 2]); \nLp = vpa(A*P + P*A' + Q)\n\n% Objective (max)\nf = -[1 1 1]; %just diagonal elements\n\n% Semidefinite Constraint (cheap way to pick off elements)\nC = -double(subs(Lp,P,zeros(2)));\nA1 = double(diff(Lp,P(1)));\nA2 = double(diff(Lp,P(2))) + double(diff(Lp,P(3)));\nA3 = double(diff(Lp,P(end)));\n\nsdcone = sparse([C(:) A1(:) A2(:) A3(:)]);\n\n% Create OPTI Object\nOpt = opti('f',f,'sdcone',sdcone,'solver','dsdp')\n% Solve the SDP\n[x,f,e,i] = solve(Opt)\nP = [x(1) x(2); x(2) x(3)];\n\nA*P + P*A' + Q\nA*X + X*A' + Q\n\n%% Discrete Lyapunov\nclc\n[A,B] = ssdata(ss(Gd));\nX = dlyap(A,Q)\n\n%LYAP LMI - Vars are P11 P12 P22\nP = sym('P',[2 2]); \nLp = vpa(A*P*A' - P + Q)\n\n% Objective (max)\nf = -[1 1 1]; %just diagonal elements\n\n% Semidefinite Constraint (cheap way to pick off elements)\nC = -double(subs(Lp,P,zeros(2)));\nA1 = double(diff(Lp,P(1)));\nA2 = double(diff(Lp,P(2))) + double(diff(Lp,P(3)));\nA3 = double(diff(Lp,P(end)));\n\nsdcone = sparse([C(:) A1(:) A2(:) A3(:)]);\n\n% Create OPTI Object\nOpt = opti('f',f,'sdcone',sdcone,'solver','dsdp')\n% Solve the SDP\n[x,f,e,i] = solve(Opt)\nP = [x(1) x(2); x(2) x(3)];\n\nA*P*A' - P + Q\nA*X*A' - X + Q\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/sdp_lqr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191322715436, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.8081450007268663}} {"text": "function R = sep(varargin);\n% SEP - An Algorithm for Converting Covariance to Spherical Error Probable\n%\n% Version 1.0\n%\n% Copyright 2004, Michael Kleder\n%\n% USAGE:\n%\n% R = sep(sx,sy,sz)\n% R = sep(sx,sy,sz,prob)\n%\n% This function computes Spherical Error Probable radius from inputs consisting of the\n% square roots of the eigenvalues of a covariance matrix (equivalently, from sigma-x,\n% sigma-y, and sigma-z, of a trivariate normal distribution in a coordinate system\n% where there is no cross-correlation between variables.) This means that if you have\n% a covariance matrix and wish to compute the S.E.P., simply obtain the square roots\n% of the eigenvalues and use these as inputs. For example, list them via \"sqrt(eig(C))\"\n% where C is your covariance matrix.\n%\n% The S.E.P. is the radius of a sphere which contains a fraction of probability equal\n% to the input \"prob,\" which is asumed to be 0.5 if omitted.\n%\n% Note: if one of the input sigmas is significantly smaller than both others,\n% calculation time may rise.\n%\n% By uncommenting a labeled line of code, the user can enter a diagnostic mode\n% to verify the accuracy of this algorithm for whatever inputs are specified.\n%\n% The mathematical formulas contained herein were created by the author and\n% are copyrighted. Feel free to use them provided you credit the author:\n% Kleder, Michael. \"An Algorithm for Converting Covariance to Spherical Error Probable\"\n% Mathworks Central File Exchange, 2004.\n\n\n[sx,sy,sz]=deal(varargin{1:3});\ntarget = .5;\nif nargin>3\n target=varargin{4};\nend\nlowend=0;\nhighend=10*max([sx sy sz]);\nR = fminbnd(@enclosederr,lowend,highend,[],sx,sy,sz,target);\n% diagnostic(R,sx,sy,sz) % use this to verify results against RANDN\nreturn\nfunction enclerr = enclosederr(R,sx,sy,sz,target)\nenclerr=dblquad(@dens,0,pi,0,2*pi,[],[],R,sx,sy,sz);\nenclerr=(target-enclerr)^2;\nreturn\nfunction outp = dens(th,phi,R,sx,sy,sz)\nsinth = sin(th);\nsinphi = sin(phi);\ncosth = cos(th);\ncosphi = cos(phi);\nsubexprA = sinth.^2.*cosphi.^2.*sy.^2.*sz.^2+sinth.^2.*...\n sinphi.^2.*sx.^2.*sz.^2+costh.^2.*sx.^2.*sy.^2;\nsubexprB = sx.*sy.*sz;\noutp = -1./8.*sinth.*2.^(.5).*subexprB.*(2.*R.*exp(-.5.*subexprA.*...\n R.^2./subexprB.^2).*subexprA.^(.5)-pi.^(.5).*2.^(.5).*erf(.5.*...\n 2.^(.5)./subexprB.*subexprA.^(.5).*R).*subexprB)./pi.^(1.5)./subexprA.^(1.5);\nreturn\nfunction diagnostic(R,sx,sy,sz)\ndisp('Running test of SEP.')\nfor i=10:-1:1\n fprintf('%g ',i);\n x=randn(1e6,1)*sx;;\n y=randn(1e6,1)*sy;\n z=randn(1e6,1)*sz;\n r=sqrt(sum([x y z].^2,2));\n m(i) = sum(r0\n % First term is .5\n h(1)=.5;\n\n % Set positive frequencies to 1.\n h(2:ceil(L/2))=1;\n\n % Last term (Nyquist frequency) is also .5, if it exists.\n if rem(L,2)==0\n h(L/2+1)=.5;\n end;\nend;\n\n", "meta": {"author": "ltfat", "repo": "ltfat", "sha": "4496a06ad8dddb85cd2e007216b765dc996ef327", "save_path": "github-repos/MATLAB/ltfat-ltfat", "path": "github-repos/MATLAB/ltfat-ltfat/ltfat-4496a06ad8dddb85cd2e007216b765dc996ef327/fourier/pheaviside.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509316, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.8077209024500688}} {"text": "clear all, close all, clc\n\n\n% x = ones(500,1);\n% t = .1*(1:500)';\n% x = cos(t*2*pi);\n% y = fft(x);\n% \n% N = length(x);\n% \n% plot(real(y),'k')\n% hold on\n% plot(real(DFT*x),'r--')\n\n%% slow and steady\nclear all, close all, clc\nN = 256;\nw = exp(-i*2*pi/N);\nfor i=1:N\n for j=1:N\n DFT(i,j) = w^((i-1)*(j-1));\n end\nend\n\nimagesc(real(DFT))\ncolormap jet\naxis off\naxis equal\nbox on\ncolorbar\nset(gcf,'Position',[100 100 1000 900])\nset(gcf,'PaperPositionMode','auto')\n% print('-depsc2', '-loose', '../figures/DFTMatrixreal');\n% print('-dpng', '-loose', '../figures/DFTMatrixreal');\n\n%%\n\nimagesc(imag(DFT))\ncolormap jet\naxis off\naxis equal\nbox on\ncolorbar\nset(gcf,'Position',[100 100 1000 900])\nset(gcf,'PaperPositionMode','auto')\n% print('-depsc2', '-loose', '../figures/DFTMatriximag');\n% print('-dpng', '-loose', '../figures/DFTMatriximag');\n%% really fast\n[I,J] = meshgrid(1:N,1:N);\nDFT = w.^((I-1).*(J-1));\n", "meta": {"author": "dynamicslab", "repo": "databook_matlab", "sha": "d390d39d18489a4804ee87a143ae8db8a1f3010b", "save_path": "github-repos/MATLAB/dynamicslab-databook_matlab", "path": "github-repos/MATLAB/dynamicslab-databook_matlab/databook_matlab-d390d39d18489a4804ee87a143ae8db8a1f3010b/CH02/CH02_SEC02_1_DFT_production.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761565, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.8077209013529713}} {"text": "function [ pc, normal ] = circle_pppr2imp_3d ( p1, p2, p3, r )\n\n%*****************************************************************************80\n%\n%% CIRCLE_PPR2IMP_3D converts a circle from PPR to implicit form in 3D.\n%\n% Discussion:\n%\n% The PPPR form of a circle in 3D is:\n%\n% The circle of radius R passing through points P1 and P2,\n% and lying in the plane of P1, P2 and P3.\n%\n% The implicit form of a circle in 3D is:\n%\n% ( P(1) - PC(1) )**2 + ( P(2) - PC(2) )**2 + ( P(3) - PC(3) )**2 = R**2\n% and the dot product of P - PC with NORMAL is 0.\n%\n% There may be zero, one, or two circles that satisfy the\n% requirements of the PPPR form.\n%\n% If there is no such circle, then PC(1:2,1) and PC(1:2,2)\n% are set to the midpoint of (P1,P2).\n%\n% If there is one circle, PC(1:2,1) and PC(1:2,2) will be equal.\n%\n% If there are two circles, then PC(1:2,1) is the first center,\n% and PC(1:2,2) is the second.\n%\n% This calculation is equivalent to finding the intersections of\n% spheres of radius R at points P1 and P2, which lie in the plane\n% defined by P1, P2 and P3.\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(3,1), P2(3,1), two points on the circle.\n%\n% Input, real P3(3,1), a third point.\n%\n% Input, real R, the radius of the circle.\n%\n% Output, real PC(3,2), the centers of the two circles.\n%\n% Output, real NORMAL(3,1), the normal to the circles.\n%\n dim_num = 3;\n%\n% Compute the distance from P1 to P2.\n%\n dist = sqrt ( sum ( ( p2(1:dim_num,1) - p1(1:dim_num,1) ).^2 ) );\n%\n% If R is smaller than DIST, we don't have a circle.\n%\n if ( 2.0 * r < dist )\n for j = 1 : 2\n pc(1:dim_num,j) = 0.5 * ( p1(1:dim_num,1) + p2(1:dim_num,1) );\n end\n return\n end\n%\n% H is the distance from the midpoint of (P1,P2) to the center.\n%\n h = sqrt ( ( r + 0.5 * dist ) * ( r - 0.5 * dist ) );\n%\n% Define a unit direction V that is normal to P2-P1, and lying\n% in the plane (P1,P2,P3).\n%\n% To do this, subtract from P3-P1 the component in the direction P2-P1.\n%\n v(1:dim_num,1) = p3(1:dim_num,1) - p1(1:dim_num,1);\n dot = v(1:dim_num,1)' * ( p2(1:dim_num,1) - p1(1:dim_num,1) );\n dot = dot / dist;\n\n v(1:dim_num,1) = v(1:dim_num,1) - dot * ( p2(1:dim_num,1) - p1(1:dim_num,1) ) / dist;\n\n v_length = sqrt ( sum ( v(1:dim_num,1).^2 ) );\n\n v(1:dim_num,1) = v(1:dim_num,1) / v_length;\n%\n% We can go with or against the given normal direction.\n%\n pc(1:dim_num,1) = 0.5 * ( p2(1:dim_num,1) + p1(1:dim_num,1) ) + h * v(1:dim_num,1);\n\n pc(1:dim_num,2) = 0.5 * ( p2(1:dim_num,1) + p1(1:dim_num,1) ) - h * v(1:dim_num,1);\n\n normal = plane_exp_normal_3d ( p1, p2, p3 );\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/circle_pppr2imp_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.8076268219486424}} {"text": "function [x,iflaw]=fmpower(N,k,p1,p2)\n%FMPOWER Signal with power-law frequency modulation.\n%\t[X,IFLAW]=FMPOWER(N,K,P1,P2) generates a signal with a\n%\tpower-law frequency modulation.\n%\tX(t) = exp(j*2*pi(F0*t + C/(1-K)*abs(t).^(1-K))) \n%\n%\tN : number of points in time\n%\tK : degree of the power-law (K~=1)\n%\tP1 : if the number of input arguments (NARGIN) is 3, P1 is a \n%\t vector containing the two coefficients [F0 C] for a\n%\t power-law instantaneous frequency (sampling frequency is set to 1).\n%\t If NARGIN=4, P1 (as P2) is a time-frequency point of the \n%\t form [Ti Fi]. Ti is in seconds and Fi is a normalized frequency\n%\t (between 0 and 0.5). The coefficients F0 \n%\t and C are then deduced such that the frequency modulation \n%\t law fits the points P1 and P2.\n%\tP2 : 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]=fmpower(128,0.5,[1 0.5],[100 0.1]);\n%\t subplot(211);plot(real(X));subplot(212);plot(IFLAW);\n%\n%\tSee also GDPOWER, FMCONST, FMLIN, FMHYP, FMPAR, FMODANY, FMSIN.\n\n%\tP. Goncalves - October 1995, O. Lemoine - April 1996.\n%\tCopyright (c) 1995 Rice University, 1996 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 (nargin <= 2),\n error ( 'The number of parameters must be at least 3.' );\nelseif (N <= 0),\n error ('The signal length N must be strictly positive' );\nelseif abs(k-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 p1(2)<0,\n error ('P1(2) must be > 0');\n elseif p2(2)<0,\n error ('P2(2) must be > 0');\n end\n c = (p2(2) - p1(2))/(1/p2(1)^k - 1/p1(1)^k) ;\n f0 = p1(2) - c/p1(1)^k ;\nend \n\nt=1:N;\n\nphi = 2*pi*(f0*t + c/(1-k)*abs(t).^(1-k)) ;\niflaw = (f0 + c*abs(t).^(-k)).' ;\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", "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/fmpower.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.8652240738888188, "lm_q1q2_score": 0.8076268106145508}} {"text": "function vol = tetrahedronVolume(vertices, varargin)\n%TETRAHEDRONVOLUME Signed volume of a tetrahedron\n%\n% VOL = tetrahedronVolume(TETRA)\n% Comptues the siged volume of the tetrahedron TETRA defined by a 4-by-4\n% array representing the polyhedron vertices.\n%\n% Example\n% vi = [0 0 0;1 0 0;0 1 0;0 0 1];\n% tetrahedronVolume(vi)\n% ans = \n% 0.1667\n%\n% [V F] = createTetrahedron;\n% tetrahedronVolume(V)\n% ans = \n% -.3333\n%\n% See also\n% meshes3d, createTetrahedron, meshVolume\n%\n% ------\n% Author: David Legland\n% e-mail: david.legland@grignon.inra.fr\n% Created: 2012-04-05, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2012 INRA - Cepia Software Platform.\n\nif nargin == 2\n tetras = varargin{1};\n nTetras = size(tetras, 1);\n vol = zeros(nTetras, 1);\n for i = 1:nTetras\n tetra = tetras(i,:);\n vol(i) = det(bsxfun(@minus, vertices(tetra(2:4),:), vertices(tetra(1),:))) / 6;\n end\n return;\nend\n\n% control on inputs\nif nargin == 4\n vertices = [vertices ; varargin{1} ; varargin{2} ; varargin{3}];\nend\n\nif size(vertices, 1) < 4\n error('Input vertex array requires at least 4 vertices');\nend\n\n% compute volume of tetrahedron, using first vertex as origin\nvol = det(vertices(2:4,:) - vertices([1 1 1],:)) / 6;\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/tetrahedronVolume.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308091776496, "lm_q2_score": 0.8652240686758841, "lm_q1q2_score": 0.8076268025441088}} {"text": "function [U,S,V] = svdsecon(X,k)\n% Input:\n% X : m x n matrix\n% k : extracts the first k singular values\n%\n% Output:\n% X = U*S*V' approximately (up to k)\n%\n% Description:\n% Does equivalent to svds(X,k) but faster\n% Requires that k < min(m,n) where [m,n] = size(X)\n% This function is useful if k is much smaller than m and n\n% or if X is sparse (see doc eigs)\n%\n% Vipin Vijayan (2014)\n\n%X = bsxfun(@minus,X,mean(X,2));\n[m,n] = size(X);\nassert(k <= m && k <= n, 'k needs to be smaller than size(X,1) and size(X,2)');\n\nif m <= n\n C = double(X*X');\n [U,D] = eigs(C,k);\n clear C;\n if nargout > 2\n V = X'*U;\n s = sqrt(abs(diag(D)));\n V = bsxfun(@(x,c)x./c, V, s');\n S = diag(s);\n end\nelse\n C = double(X'*X); \n [V,D] = eigs(C,k);\n clear C;\n U = X*V; % convert evecs from X'*X to X*X'. the evals are the same.\n %s = sqrt(sum(U.^2,1))';\n s = sqrt(abs(diag(D)));\n U = bsxfun(@(x,c)x./c, U, s');\n S = diag(s);\nend\n", "meta": {"author": "zhoupc", "repo": "CNMF_E", "sha": "ccca6f9db7d1d15b7dd1266eb9b29e417f92e79f", "save_path": "github-repos/MATLAB/zhoupc-CNMF_E", "path": "github-repos/MATLAB/zhoupc-CNMF_E/CNMF_E-ccca6f9db7d1d15b7dd1266eb9b29e417f92e79f/ca_source_extraction/endoscope/svdsecon.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474246069457, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.8075767635805877}} {"text": "function[nui,om2i]=morlfreq(omi)\n%MORLFREQ Compute Morlet wavelet carrier frequency given peak frequency.\n%\n% FNU=MORLFREQ(FMAX), where FMAX is the desired peak frequency of a \n% Morlet wavelet, returns the appropriate carrier wave frequency FNU.\n%\n% The Morlet wavelet carrier wave and peak frequency differ on account\n% of the correction term which ensures zero mean.\n%\n% Note that FMAX and FNU are both *radian* as in cos(omega t) and not\n% cyclic as in in cos(2 pi f t).\n%\n% [FNU,FMIN]=MORLFREQ(FMAX) also returns the (radian) frequency at which\n% the Morlet wavelet obtains a minimum, which occurs for FMIN<0.\n%\n% For details see Appendix A of\n% \n% Lilly and Olhede (2009). Higher-order properties of analytic \n% wavelets. IEEE Trans. Sig. Proc., 57 (1), 146--160.\n%\n% 'morlfreq --t' runs a test.\n% 'morlfreq --f' generates a sample figure.\n%\n% Usage: fnu=morlfreq(fmax);\n% [fnu,fmin]=morlfreq(fmax);\n% __________________________________________________________________\n% This is part of JLAB --- type 'help jlab' for more information\n% (C) 2008--2013 J.M. Lilly --- type 'help jlab_license' for details\n \nif strcmpi(omi, '--t')\n morlfreq_test,return\nend\nif strcmpi(omi, '--f')\n type makefigs_morlfreq\n makefigs_morlfreq;\n return\nend\n \nsizeom=size(omi);\nomi=omi(:);\n\nN=10000;\n\n%This gives a tighter spacing near one than near zero\nnutilde=log(log(linspace(exp(exp(1./1e9)),exp(exp(1-1./1e9)),N)));\n%nutilde=linspace(1./1e9,1-1./1e9,N);\n\nom=(sqrt(-frac((log(1-nutilde)),nutilde)));\nnu=nutilde.*om;\n\nbool=(omi>=maxmax(om));\nindex1=find(bool);\nif ~isempty(index1)\n nui(index1)=omi(index1);\nend\nindex2=find(~bool);\nif ~isempty(index2)\n nui(index2)=interp1(om,nu,omi(index2),'linear');\nend\n\n%I chose this grid via trial and error\nnutilde=1./[linspace(1./10,10,N) logspace(log10(10+0.0000001),log10(1000),N)];\nom2=-(sqrt(frac((log(1+nutilde)),nutilde)));\nnu2=(nutilde).*abs(om2);\n\nom2i=zeros(size(nui));%figure,plot(nui),maxmax(nu2)\nbool=(nui>=maxmax(nu2));\nindex1=find(bool);\nif ~isempty(index1)\n om2i(index1)=nan;\nend\nindex2=find(~bool);%length(index2)\nif ~isempty(index2)\n om2i(index2)=interp1(nu2,om2,nui(index2),'linear');\nend\n%x=om2i-nui-om2i.*exp(-om2i.*nui);\n%figure,plot(x)\n\nnui=reshape(nui,sizeom);\nom2i=reshape(om2i,sizeom);\n\nfunction[]=morlfreq_test\nom=linspace(0,4,1000);\n[nu,fneg]=morlfreq(om);\n\npsi1a=exp(-frac(1,2).*(nu-om).^2).*(-(om-nu))+exp(-frac(1,2).*(nu.^2+om.^2)).*om;\nreporttest('MORLFREQ first derivative vanishes at peak',aresame(psi1a,0*psi1a,1e-4))\n\nomneg=fneg*2*pi;\npsi1b=exp(-frac(1,2).*(nu-omneg).^2).*(-(omneg-nu))+exp(-frac(1,2).*(nu.^2+omneg.^2)).*omneg;\n\nreporttest('MORLFREQ first derivative vanishes at negative peak',aresame(psi1b,0*psi1b,1e-4))\n\n\n", "meta": {"author": "jonathanlilly", "repo": "jLab", "sha": "9f32f63e647209bc1cb81c8713deb954857f1919", "save_path": "github-repos/MATLAB/jonathanlilly-jLab", "path": "github-repos/MATLAB/jonathanlilly-jLab/jLab-9f32f63e647209bc1cb81c8713deb954857f1919/jWavelet/morlfreq.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465044347828, "lm_q2_score": 0.8633916152464016, "lm_q1q2_score": 0.8075703292790227}} {"text": "function a=getNextMPartition(param1,m)\n%%GETNEXTMPARTITION Get the next partition of the integer n into m\n% parts. This is m nonzero items such that the sum is n.\n% The partitions are visited in reverse lexicographic\n% order (colex order). The function can be called with\n% two parameters to get the first n,m partition, or with\n% 1 parameter (that being the previous partition) to\n% get the next partition. The total number of\n% partitions can be found using the function\n% numMPartitions(n,m). As combinations are to\n% permutations, partitions are to compositions: The order\n% of the terms in an m-partitions do not matter, whereas\n% they matter in a composition.\n%\n%INPUTS: param1 If two parameters are passed to the function, then param1\n% is n, the integer to be partitioned. Otherwise, param1 is a,\n% the current partition of the chosen integer n into m parts.\n% This means that a must be length m and its elements must sum\n% to n. The elements must be ordered in decreasing order. The\n% first partition in the series must be a(1)=n-m+1; a(2:m)=1;\n% Note that n>=m>=2 if a is passed, because a size 1 partition\n% only has one value (the initial value).\n% m This parameter is not passed if the next m-partition in the\n% sequence is desired. However, if one wishes to obtain the\n% first value in the sequence, then m is the positive integer\n% number of parts into which the integer n is split, n>=m;\n%\n%OUTPUTS: a The next partition in the series or the empty matrix if the\n% parition given was the last partition in the series. If the\n% function was called getNextMPartition(n,m), then a is the first\n% parition.\n%\n%The algorithm is Algorithm H in Chapter 7.2.1.4 of [1].\n%\n%The function can either be called as\n%a=getNextMPartition(n,m);\n%to get the first parition of the integer n into m parts or as\n%a=getNextMPartition(a);\n%to get the next partition.\n%\n%Often, one might prefer all partitions of m integers that sum to a\n%constant value n INCLUDING zeros. This function can be used to produce\n%such a modified set of partitions by initializing it as\n%a=getNextMPartition(n+m,m);\n%and for every composition generated, including the first, the modified\n%composition starting from zero is given by a-1.\n%\n%REFERENCES:\n%[1] D. E. Knuth, The Art of Computer Programming. Vol. 4, Fascicle 3:\n% Generating all Combinations and Partitions, Upper Saddle River, NJ:\n% Addison-Wesley, 2009.\n%\n%October 2014 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n%Return the first partition in the sequence if two parameters are passed.\nif(nargin>1)\n n=param1;\n a(1)=n-m+1;\n a(2:m)=1;\n return;\nend\n\na=param1;\n\nm=length(a);\n\n%Deal with the special case of a 1D partition. In this instance, there is\n%only 1 possible solution, so if one is calling this function again, it\n%will be past the end of all possible solutions.\nif(m==1)\n a=[];\n return;\nend\n\nwhile(a(2)m)\n a=[];\n return;\nend\ns=a(1)+a(2)-1;\nwhile(a(j)>=a(1)-1)\n s=s+a(j);\n j=j+1;\n %If we have passed the last partition\n %(Termination part of step H5)\n if(j>m)\n a=[];\n return;\n end\nend\n\n%Step H5 in Knuth.\nx=a(j)+1;\na(j)=x;\nj=j-1;\n\n%Step H6 in Knuth\nwhile(j>1)\n a(j)=x;\n s=s-x;\n j=j-1;\n a(1)=s;\nend\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/Combinatorics/getNextMPartition.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092414, "lm_q2_score": 0.8887587993853654, "lm_q1q2_score": 0.8075421445802979}} {"text": "function h=smooth_diff(n)\n% A smoothed differentiation filter (digital differentiator). \n%\n% Such a filter has the following advantages:\n% \n% First, the filter involves both the smoothing operation and differentation operation. \n% It can be regarded as a low-pass differention filter (digital differentiator). \n% It is well known that the common differentiation operation amplifies the high-frequency noises.\n% Therefore, the smoothded differentiation filter would be valuable in experimental (noisy) data processing. \n% \n% Secondly, the filter coefficients are all convenient integers (simple units) except for an integer scaling factor,\n% as may be especially significant in some applications such as those in some single-chip microcomputers\n% or digital signal processors. \n% \n% Usage:\n% h=smooth_diff(n)\n% n: filter length (positive integer larger no less than 2)\n% h: filter coefficients (anti-symmetry)\n%\n% Examples:\n% smooth_demo\n%\n% Author:\n% Jianwen Luo 2004-11-02\n% Department of Biomedical Engineering, Department of Electrical Engineering\n% Tsinghua University, Beijing 100084, P. R. China \n% \n% References:\n% Usui, S.; Amidror, I., \n% Digital Low-Pass Differentiation for Biological Signal-Processing. \n% IEEE Transactions on Biomedical Engineering 1982, 29, (10), 686-693.\n% Luo, J. W.; Bai, J.; He, P.; Ying, K., \n% Axial strain calculation using a low-pass digital differentiator in ultrasound elastography. \n% IEEE Transactions on Ultrasonics Ferroelectrics and Frequency Control 2004, 51, (9), 1119-1127.\n\nif n>=2 && floor(n)==ceil(n)\n if mod(n,2)==1%is odd\n m=fix((n-1)/2);\n h=[-ones(1,m) 0 ones(1,m)]/m/(m+1);\n else%is even\n m=fix(n/2);\n h=[-ones(1,m) ones(1,m)]/m^2;\n end\nelse \n error('The input parameter (n) should be a positive integer larger no less than 2.');\nend", "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/smooth_diff.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107966642556, "lm_q2_score": 0.8615382094310355, "lm_q1q2_score": 0.8074429116175571}} {"text": "function [Stat] = VectStat (M)\n%\n% [Stat] = VectStat (M)\n%\n%Purpose:\n% calculates very basic stats of vectors\n%\n%\n%Input Parameters:\n% M : MxN matrix\n% NAN or Inf values are not considered and the user is warned of their existence\n%\n%Output Parameters:\n%\n% Stat is an Mx1 vector of structures with the following fields\n% Each Stat(i) has the following structures\n% .N : the number of elements in M(i,:)\n% .M : the mean of vector M(i,:)\n% .Md: the median of vector M(i,:)\n% .S : the (unbiased) standard deviation of M(i,:)\n% .V : the variance (S^2) of M(i,:)\n% .mx: The maximum value\n% .mn: The minimum value\n%\n% if the input vector is empty , NaN values are returned in Stat\n%More Info :\n%\n%\n%\n%\n% Author : Ziad Saad\n% Date : Tue Apr 20 17:13:23 CDT 1999\n\n\n%Define the function name for easy referencing\nFuncName = 'VectStat';\n\n%Debug Flag\nDBG = 1;\nStat.N = NaN;\nStat.M = NaN;\nStat.Md = NaN;\nStat.S = NaN;\nStat.V = NaN;\n\n\n\nif (is_row(M) ~= -1),\n\tsZ = 1;\n\tsz2 = length(M);\n\tM = M(:)'; %turn M into a row vector\nelse\n\tsZ = size(M,1);\n\tsz2 = size(M,2);\nend\n\nif (sZ == 0 | sz2 ==0),\n\tErrEval(FuncName,'Wrn_Empty M returning NaN structure for result');\n\treturn;\nend\n\n%initialize, once\n\tStat(sZ).N = 0;Stat(sZ).M = 0;Stat(sZ).Md = 0;Stat(sZ).S = 0;Stat(sZ).V = 0; Stat(sZ).mn = 0; Stat(sZ).mx = 0;\n\nfor (i=1:1:sZ),\n\tigood = find(isfinite(M(i,:)));\n\tN_igood = length(igood);\n\tif (N_igood < sz2),\n\t\tstmp = sprintf ('%s Warning: Inf or Nan ignored in row %g\\n', FuncName, i);\n\tend\n\t\n\tStat(i).N = N_igood;\n\tStat(i).M = mean(M(i,igood));\n\tStat(i).Md = median(M(i,igood));\n\tStat(i).S = std(M(i,igood),0); %unbiased estimator\n\tStat(i).V = Stat(i).S .^ 2;\n\tStat(sZ).mn = min(M(i,igood));\n\tStat(sZ).mx = max(M(i,igood));\nend\n\n\nreturn;\n\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/afni/VectStat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.8872045877523147, "lm_q1q2_score": 0.8072736745199574}} {"text": "function Xsol = nonlinear_eigenspace(L, k, alpha)\n% Example of nonlinear eigenvalue problem: total energy minimization.\n%\n% function Xsol = nonlinear_eigenspace(L, k, alpha)\n%\n% L is a discrete Laplacian operator,\n% alpha is a given constant, and\n% k corresponds to the dimension of the least eigenspace sought. \n%\n% This example demonstrates how to use the Grassmann geometry factory \n% to solve the nonlinear eigenvalue problem as the optimization problem:\n%\n% minimize 0.5*trace(X'*L*X) + (alpha/4)*(rho(X)*L\\(rho(X))) \n% over X such that X'*X = Identity,\n%\n% where L is of size n-by-n,\n% X is an n-by-k matrix, and\n% rho(X) is the diagonal part of X*X'.\n%\n% This example is motivated in the paper\n% \"A Riemannian Newton Algorithm for Nonlinear Eigenvalue Problems\",\n% Zhi Zhao, Zheng-Jian Bai, and Xiao-Qing Jin,\n% SIAM Journal on Matrix Analysis and Applications, 36(2), 752-774, 2015.\n%\n\n\n% This file is part of Manopt and is copyrighted. See the license file.\n%\n% Main author: Bamdev Mishra, June 19, 2015.\n% Contributors:\n%\n% Change log:\n\n\n % If no inputs are provided, generate a discrete Laplacian operator.\n % This is for illustration purposes only.\n % The default example corresponds to Case (c) of Example 6.2 of the\n % above referenced paper.\n \n if ~exist('L', 'var') || isempty(L)\n n = 100;\n L = gallery('tridiag', n, -1, 2, -1);\n end\n \n n = size(L, 1);\n assert(size(L, 2) == n, 'L must be square.');\n \n if ~exist('k', 'var') || isempty(k) || k > n\n k = 10;\n end\n \n if ~exist('alpha', 'var') || isempty(alpha)\n alpha = 1;\n end\n \n \n % Grassmann manifold description\n Gr = grassmannfactory(n, k);\n problem.M = Gr;\n \n % Cost function evaluation\n problem.cost = @cost;\n function val = cost(X)\n rhoX = sum(X.^2, 2); % diag(X*X'); \n val = 0.5*trace(X'*(L*X)) + (alpha/4)*(rhoX'*(L\\rhoX));\n end\n \n % Euclidean gradient evaluation\n % Note: Manopt automatically converts it to the Riemannian counterpart.\n problem.egrad = @egrad;\n function g = egrad(X)\n rhoX = sum(X.^2, 2); % diag(X*X');\n g = L*X + alpha*diag(L\\rhoX)*X;\n end\n \n % Euclidean Hessian evaluation\n % Note: Manopt automatically converts it to the Riemannian counterpart.\n problem.ehess = @ehess;\n function h = ehess(X, U)\n rhoX = sum(X.^2, 2); %diag(X*X');\n rhoXdot = 2*sum(X.*U, 2); \n h = L*U + alpha*diag(L\\rhoXdot)*X + alpha*diag(L\\rhoX)*U;\n end\n \n \n % Check whether gradient and Hessian computations are correct.\n % checkgradient(problem);\n % pause;\n % checkhessian(problem);\n % pause;\n \n \n % Initialization as suggested in above referenced paper.\n X = randn(n, k);\n [U, S, V] = svd(X, 0); %#ok\n X = U*V';\n [U0, S0, V0] = eigs(L + alpha*diag(L\\(sum(X.^2, 2))), k,'sm'); %#ok\n X0 = U0;\n \n % Call manoptsolve to automatically call an appropriate solver.\n % Note: it calls the trust regions solver as we have all the required\n % ingredients, namely, gradient and Hessian, information.\n Xsol = manoptsolve(problem, X0);\n \nend\n", "meta": {"author": "MIT-SPARK", "repo": "GlobalOptimizationTutorial", "sha": "ae1e947a846ca9199d9a3579409d73f4f7fa4ccf", "save_path": "github-repos/MATLAB/MIT-SPARK-GlobalOptimizationTutorial", "path": "github-repos/MATLAB/MIT-SPARK-GlobalOptimizationTutorial/GlobalOptimizationTutorial-ae1e947a846ca9199d9a3579409d73f4f7fa4ccf/SE-Sync/manopt/examples/nonlinear_eigenspace.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248140158416, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.8072455985030061}} {"text": "function [] = checkNumericalGradient()\n% This code can be used to check your numerical gradient implementation \n% in computeNumericalGradient.m\n% It analytically evaluates the gradient of a very simple function called\n% simpleQuadraticFunction (see below) and compares the result with your numerical\n% solution. Your numerical gradient implementation is incorrect if\n% your numerical solution deviates too much from the analytical solution.\n \n% Evaluate the function and gradient at x = [4; 10]; (Here, x is a 2d vector.)\nx = [4; 10];\n[value, grad] = simpleQuadraticFunction(x);\n\n% Use your code to numerically compute the gradient of simpleQuadraticFunction at x.\n% (The notation \"@simpleQuadraticFunction\" denotes a pointer to a function.)\nnumgrad = computeNumericalGradient(@simpleQuadraticFunction, x);\n\n% Visually examine the two gradient computations. The two columns\n% you get should be very similar. \ndisp([numgrad grad]);\nfprintf('The above two columns you get should be very similar.\\n(Left-Your Numerical Gradient, Right-Analytical Gradient)\\n\\n');\n\n% Evaluate the norm of the difference between two solutions. \n% If you have a correct implementation, and assuming you used EPSILON = 0.0001 \n% in computeNumericalGradient.m, then diff below should be 2.1452e-12 \ndiff = norm(numgrad-grad)/norm(numgrad+grad);\ndisp(diff); \nfprintf('Norm of the difference between numerical and analytical gradient (should be < 1e-9)\\n\\n');\nend\n\n\n \nfunction [value,grad] = simpleQuadraticFunction(x)\n% this function accepts a 2D vector as input. \n% Its outputs are:\n% value: h(x1, x2) = x1^2 + 3*x1*x2\n% grad: A 2x1 vector that gives the partial derivatives of h with respect to x1 and x2 \n% Note that when we pass @simpleQuadraticFunction(x) to computeNumericalGradients, we're assuming\n% that computeNumericalGradients will use only the first returned value of this function.\n\nvalue = x(1)^2 + 3*x(1)*x(2);\n\ngrad = zeros(2, 1);\n% 对X1 求偏导\ngrad(1) = 2*x(1) + 3*x(2);\n% 对X2 求偏导\ngrad(2) = 3*x(1);\n\nend\n", "meta": {"author": "llp1992", "repo": "MachineLearning", "sha": "315c00285b758a7aee0c8a80db2d2f6dfbbe9aef", "save_path": "github-repos/MATLAB/llp1992-MachineLearning", "path": "github-repos/MATLAB/llp1992-MachineLearning/MachineLearning-315c00285b758a7aee0c8a80db2d2f6dfbbe9aef/DeepLearning/UFLDL/Vectorization_sparseae_exercise/checkNumericalGradient.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.8976952941600963, "lm_q1q2_score": 0.8071370389603351}} {"text": "function [yi, p, pval] = newtint(x, y, xi, c)\n\n% NEWTINT Interpolation of equally-spaced points.\n% NEWTINT(X,Y,XI,C) interpolates to find YI, the value\n% of the underlying function Y at the point XI, using\n% either Newton's forward interpolation formula or\n% Newton's backward interpolation formula.\n%\n% C specifies the interpolation method:\n% 0 : Newton's forward or backward (default)\n% 1 : Newton's forward\n% 2 : Newton's backward\n% 3 : Stirling's method\n% 4 : Everett's method\n%\n% [YI,P,PVAL] = NEWTINT() also returns P, the coefficients\n% of the calculated interpolating polynomial, and PVAL,\n% which specifies the maximum degree of the interpolating\n% polynomial.\n\n% Joe Henning - Fall 2011\n\nif (nargin < 4)\n c = 0;\nend\n\npval = length(x)*(0+1) - 1;\n\nn = length(x)-1;\nD = zeros(n+1,n+1);\nD(:,1) = y(:);\n\nh = x(2)-x(1);\n\nfor i = 1:n\n for j = 1:i\n D(i+1,j+1) = D(i+1,j)-D(i,j);\n end\nend\n\nif (c == 0)\n if (xi < x(1))\n c = 2;\n elseif (xi > x(ceil((n+1)/2)) && xi <= x(n+1))\n c = 2;\n else\n c = 1;\n end\nend\n\nswitch c\n case 1\n % forward difference interpolation\n p = diag(D);\n q = (xi-x(1))/h;\n yi = p(1);\n for i = 1:length(p)-1\n term = 1;\n for k = 0:(i-1)\n term = term*(q-k);\n end\n term = term/factorial(i);\n yi = yi + term*p(i+1);\n end\n case 2\n % backward difference interpolation\n p = D(n+1,:).';\n q = (xi-x(n+1))/h;\n yi = p(1);\n for i = 1:length(p)-1\n term = 1;\n for k = 0:(i-1)\n term = term*(q+k);\n end\n term = term/factorial(i);\n yi = yi + term*p(i+1);\n end\n case 3\n % Stirling's method\n xk = 0;\n ik = 0;\n for i = 1:n+1\n if (xi > x(i))\n xk = x(i);\n ik = i;\n end\n end\n yi = 0;\n q = (xi-xk)/h;\n if (q > 0.5)\n ik = ik + 1;\n xk = x(ik);\n q = (xi-xk)/h;\n for i = 1:2:n+1\n fi = floor(i/2);\n term = 0;\n %[term D(ik+i-1-floor(i/2),i)]s\n for k = fi-1:fi\n term = term + dnchoosek(q+k,i-1)/2.0;\n end\n p(i,1) = term;\n if (ik+i-1-floor(i/2) <= n+1)\n yi = yi + term*D(ik+i-1-floor(i/2),i);\n end\n end\n for i = 2:2:n+1\n fi = floor(i/2);\n term = dnchoosek(q+fi-1,i-1);\n p(i,1) = term;\n %[term D(ik+i-1-floor(i/2),i) D(ik+i-floor(i/2),i)]\n if (ik+i-floor(i/2) > n+1)\n yi = yi + term*D(ik+i-1-floor(i/2),i)/2.0;\n else\n yi = yi + term*(D(ik+i-1-floor(i/2),i)+D(ik+i-floor(i/2),i))/2.0;\n end\n end\n else\n for i = 1:2:n+1\n fi = floor(i/2);\n term = 0;\n for k = fi-1:fi\n term = term + dnchoosek(q+k,i-1)/2.0;\n end\n p(i,1) = term;\n %[term D(ik+i-1-floor(i/2),i)]\n if (ik+i-1-floor(i/2) <= n+1)\n yi = yi + term*D(ik+i-1-floor(i/2),i);\n end\n end\n for i = 2:2:n+1\n fi = floor(i/2);\n term = dnchoosek(q+fi-1,i-1);\n p(i,1) = term;\n %[term D(ik+i-1-floor(i/2),i) D(ik+i-floor(i/2),i)]\n if (ik+i-floor(i/2) > n+1)\n yi = yi + term*D(ik+i-1-floor(i/2),i)/2.0;\n else\n yi = yi + term*(D(ik+i-1-floor(i/2),i)+D(ik+i-floor(i/2),i))/2.0;\n end\n end\n end\n case 4\n % Everett's method\n xk = 0;\n ik = 0;\n for i = 1:n+1\n if (xi > x(i))\n xk = x(i);\n ik = i;\n end\n end\n p = [];\n q = (xi-xk)/h;\n r = 1-q;\n yi = 0;\n for i = 1:2:n+1\n fi = floor(i/2);\n e = dnchoosek(r+fi,i);\n f = dnchoosek(q+fi,i);\n p = [p; e f];\n %[e D(ik+i-1-floor(i/2),i) f D(ik+i-floor(i/2),i)]\n if ((ik+i-floor(i/2)) > n+1)\n yi = yi + e*D(ik+i-1-floor(i/2),i) + f*0;\n else\n yi = yi + e*D(ik+i-1-floor(i/2),i) + f*D(ik+i-floor(i/2),i);\n end\n end\nend\n\nfunction [d] = dnchoosek(n, k)\n\n% DNCHOOSEK Binomial coefficient or all combinations.\n% DNCHOOSEK(N,K) where N and K are non-negative numbers\n% returns N!/K!(N-K)!.\n\nd = gamma(n+1)/(gamma(k+1)*gamma(n-k+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/36800-interpolation-utilities/newtint.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.872347369700144, "lm_q1q2_score": 0.8071219230340703}} {"text": "function h = ksizeROT(npd,noIQR)\n% \"Rule of Thumb\" estimate (Silverman)\n% Estimate is based on assumptions of Gaussian data and kernel\n% Actually the multivariate version in Scott ('92) \n% Use ksizeROT(X,1) to force use of stddev. instead of min(std,C*iqr)\n% (iqr = interquartile range, C*iqr = robust stddev estimate)\n%\n\n% Copyright (C) 2003 Alexander Ihler; distributable under GPL -- see README.txt\n\n X = getPoints(npd);\n N = size(X,2); dim = size(X,1);\n if (nargin<2) noIQR=0; end;\n\n Rg = .282095; Mg=1; % See ksizeCalcUseful for derivation\n Re = .6; Me = .199994; % this is the canonical kernel adjustment\n Rl = .25; Ml = 1.994473; % for product kernels of these types\n switch(npd.type),\n case 0, prop = 1.0; % Approximate; 1D prop = 1.059224; % Gaussian\n case 1, prop = ((Re/Rg)^dim / (Me/Mg)^2 )^(1/(dim+4)); % 1D prop = 2.344944; % Epanetchnikov\n case 2, prop = ((Rl/Rg)^dim / (Ml/Mg)^2 )^(1/(dim+4)); % 1D prop = 0.784452; % Laplacian\n end;\n \n sig = std(X,0,2); % estimate sigma (standard)\n if (noIQR)\n h = prop*sig*N^(-1/(4+dim));\n else \n iqrSig = .7413*iqr(X')'; % find interquartile range sigma est.\n if (max(iqrSig)==0) iqrSig=sig; end;\n h = prop * min(sig,iqrSig) * N^(-1/(4+dim));\n end;\n\n% if (min(h) == 0) warning('Near-zero covariance => Kernel size set to 0'); end;\n", "meta": {"author": "ShapeNet", "repo": "RenderForCNN", "sha": "c0bee04aad3dc2f0ae5de71daf6d51664ce02e76", "save_path": "github-repos/MATLAB/ShapeNet-RenderForCNN", "path": "github-repos/MATLAB/ShapeNet-RenderForCNN/RenderForCNN-c0bee04aad3dc2f0ae5de71daf6d51664ce02e76/render_pipeline/kde/matlab_kde_package/private/ksizeROT.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299529686201, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.8071219189105338}} {"text": "function d = divisor(n)\n%% divisor : provides a list of integer divisors of a number.\n% divisor(n) : row vector of all distinct divisors of a positive integer N, \n% including 1 and N.\n%\n% Remark:\n% This function uses the default factor() routine in Matlab and hence is \n% limited to input values upto 2^32. However if factor() routine does get\n% updated for larger integers, this function will still work fine.\n% Using factor() provides a significant speed improvement over manually \n% seaching for the each divisor of n.\n%\n% Example:\n% a = divisor(12);\n% returns -> a = [1, 2, 3, 4, 6, 12];\n%\n% See Also:\n% factor, primes\n\n% Author: Yash Kochar ( yashkochar@yahoo.com )\n% Last modified: 21st June 2009\n%-------------------------------------------------------------------------------\n\n%% Input error check :\n% Check whether input is positive integer and scalar.\nif ~isscalar(n)\n error('divisor:NonScalarInput','Input must be a scalar.');\nend\nif (n < 1) || (floor(n) ~= n)\n error('divisor:PositiveIntegerOnly', 'Input must be a positive integer.'); \nend\n\n%% Find prime factors of number :\npf = factor(n); % Prime factors of n\nupf = unique(pf); % Unique\n\n%% Calculate the divisors\nd = upf(1).^(0:1:sum(pf == upf(1)))';\nfor f = upf(2:end)\n d = d*(f.^(0:1:sum(pf == f)));\n d = d(:);\nend\nd = sort(d)'; % To further improve the speed one may remove this sort command\n % Just remember to take the transpose of \"d\" to get a result\n % as a row vector instead of a column vector.", "meta": {"author": "goGPS-Project", "repo": "goGPS_MATLAB", "sha": "30644df61d2459e3347ac5f3e31b71d9f69f4b01", "save_path": "github-repos/MATLAB/goGPS-Project-goGPS_MATLAB", "path": "github-repos/MATLAB/goGPS-Project-goGPS_MATLAB/goGPS_MATLAB-30644df61d2459e3347ac5f3e31b71d9f69f4b01/source/utility/divisor.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897558991952, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.8069794444014262}} {"text": "function x = cc_abscissas ( n )\n\n%*****************************************************************************80\n%\n%% CC_ABSCISSAS computes the Clenshaw Curtis abscissas.\n%\n% Discussion:\n%\n% The interval is [ -1, 1 ].\n%\n% The abscissas are the cosines of equally spaced angles between\n% 180 and 0 degrees, including the endpoints.\n%\n% X(I) = cos ( ( ORDER - I ) * PI / ( ORDER - 1 ) )\n%\n% except for the basic case ORDER = 1, when\n%\n% X(1) = 0.\n%\n% If the value of ORDER is increased in a sensible way, then\n% the new set of abscissas will include the old ones. One such\n% sequence would be ORDER(K) = 2*K+1 for K = 0, 1, 2, ...\n%\n% When doing interpolation with Lagrange polynomials, the Clenshaw Curtis\n% abscissas can be a better choice than regularly spaced abscissas.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 July 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Charles Clenshaw, Alan Curtis,\n% A Method for Numerical Integration on an Automatic Computer,\n% Numerische Mathematik,\n% Volume 2, Number 1, December 1960, pages 197-205.\n%\n% Philip Davis, Philip Rabinowitz,\n% Methods of Numerical Integration,\n% Second Edition,\n% Dover, 2007,\n% ISBN: 0486453391,\n% LC: QA299.3.D28.\n%\n% Joerg Waldvogel,\n% Fast Construction of the Fejer and Clenshaw-Curtis Quadrature Rules,\n% BIT Numerical Mathematics,\n% Volume 43, Number 1, 2003, pages 1-18.\n%\n% Parameters:\n%\n% Input, integer N, the order of the rule.\n%\n% Output, real X(N), the abscissas.\n%\n if ( n == 1 )\n x(1) = 0.0;\n return\n end\n\n for i = 1 : n\n theta(i) = ( n - i ) * pi ...\n / ( n - 1 );\n end\n\n x(1:n) = cos ( theta(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/interp/cc_abscissas.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.8856314647623016, "lm_q1q2_score": 0.8069694212394586}} {"text": "function f = rhs ( node_num, node_xy, time )\n\n%*****************************************************************************80\n%\n%% RHS gives the right-hand side of the differential equation.\n%\n% Discussion:\n%\n% We assume that the equation to be solved is\n%\n% dUdT - Laplacian U + K * U = F\n%\n% with\n%\n% K = 0,\n%\n% and\n%\n% F = (2*pi*pi-1)*sin(pi*x)*sin(pi*y)*exp(-t).\n%\n% The exact solution is:\n%\n% U = sin(pi*x) * sin(pi*y) * exp(-t)\n%\n% Modified:\n%\n% 07 January 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NODE_NUM, the number of points.\n%\n% Input, real NODE_XY(2,NODE_NUM), the coordinates of the points.\n%\n% Input, real TIME, the current time (assumed to be\n% the initial time).\n%\n% Output, real F(NODE_NUM), the value of the right hand side.\n%\n f(1:node_num) = ( 2.0 * pi * pi - 1.0 ) ...\n * sin ( pi * node_xy(1,1:node_num) ) ...\n .* sin ( pi * node_xy(2,1:node_num) ) * exp ( - time );\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_heat_sparse_square/rhs.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825848, "lm_q2_score": 0.8774767922879693, "lm_q1q2_score": 0.8069649821745811}} {"text": "%\n% [K, dK] = gpK_decper(D, p1, p2, p3, p4)\n%\n% Decaying periodic covariance function for GP.\n%\n% p1 is the scale\n% p2 is the decaying length\n% p3 is the frequency of the periodicity\n% p4 is the smoothness of the periodic signal\n%\nfunction [K, dK] = gpK_decper(D, p1, p2, p3, p4)\nK = p1^2*exp(-0.5*(D.^2)/(p2^2)-2*sin(pi*D*p3).^2/(p4^2));\n\nif nargout >= 2\n dK = zeros([size(D),4]);\n dK(:,:,1) = K .* 2 / p1;\n dK(:,:,2) = K .* (-0.5*D.^2) .* (-2*p2^(-3));\n dK(:,:,3) = K .* (-2*sin(pi*D*p3)*2) .* cos(pi*D*p3) .* (pi*D);\n dK(:,:,4) = K .* (-2*sin(pi*D*p3).^2) * (-2)*p4^(-3);\nend\n", "meta": {"author": "jluttine", "repo": "matlab", "sha": "63406c7782b0869948f06e1dbc594460c165d24e", "save_path": "github-repos/MATLAB/jluttine-matlab", "path": "github-repos/MATLAB/jluttine-matlab/matlab-63406c7782b0869948f06e1dbc594460c165d24e/gppca/gpcov_decper.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517117469258, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.8069437917195732}} {"text": "function y = logMvGamma( x, D)\n% Compute logarithm multivariate Gamma function.\n% operates on each entry of input matrix/vector x\n%INPUT\n% x : any scalar/vector/matrix\n% D : integer dimension of the mv Gamma function\n%MATH DETAILS -------------------------------------------------------\n% Gamma_D(x) = pi^(D(D-1)/4) prod_(j=1)^p Gamma(x+(1-j)/2)\n% log Gamma_D(x) = D(D-1)/4 log pi + sum_(j=1)^p log Gamma(x+(1-j)/2)\n% Credit: Michael Chen (sth4nth@gmail.com).\n\ns = size(x);\nds = (1-(1:D)')/2;\n\n% Force input x to be a row vector\nX = reshape(x,1,prod(s));\n\n% X(dd, dim) = input(dim) - ds(dd)\nX = bsxfun(@plus, X, ds );\n\ny = D*(D-1)/4*log(pi) + sum(gammaln(X),1);\n\n% Force output back to size of original input\ny = reshape(y,s);\n", "meta": {"author": "michaelchughes", "repo": "NPBayesHMM", "sha": "22e164b5eb68ea2b1e5ef38807a56fd8aa3660dd", "save_path": "github-repos/MATLAB/michaelchughes-NPBayesHMM", "path": "github-repos/MATLAB/michaelchughes-NPBayesHMM/NPBayesHMM-22e164b5eb68ea2b1e5ef38807a56fd8aa3660dd/code/util/logMvGamma.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9585377272885903, "lm_q2_score": 0.8418256472515684, "lm_q1q2_score": 0.8069216426897649}} {"text": "%% Gaussian mask\n% k: the scaling factor\n% s: standard variance\n% M: mask\n\nfunction M = gaussianMask(k,s)\nM=[];\nif s==0\n M=1;\n return;\nend\nR = ceil(3*s); % cutoff radius of the gaussian kernal \nfor i = -R:R,\n for j = -R:R,\n M(i+R+1,j+R+1) = k * exp(-(i*i+j*j)/2/s/s)/(2*pi*s*s);\n end\nend\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/39553-gmm-hmrf/GMM-HMRF_v1.0/code/color-image/gaussianMask.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9585377249197139, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.8069216349898857}} {"text": "function pwl_interp_2d_scattered_test03 ( prob )\n\n%*****************************************************************************80\n%\n%% PWL_INTERP_2D_SCATTERED_TEST03 tests PWL_INTERP_2D_SCATTERED_VALUE.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 26 October 2012\n%\n% Author:\n%\n% John Burkardt\n%\n ni = 25;\n g = 2;\n nd = g00_size ( g );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PWL_INTERP_2D_SCATTERED_TEST03\\n' );\n fprintf ( 1, ' PWL_INTERP_2D_SCATTERED_VALUE evaluates a\\n' );\n fprintf ( 1, ' piecewise linear interpolant to scattered data.\\n' );\n fprintf ( 1, ' Here, we use grid number %d\\n', g );\n fprintf ( 1, ' with %d scattered points in the unit square\\n', nd );\n fprintf ( 1, ' on problem %d\\n', prob );\n%\n% Get the data points and evaluate the function there.\n%\n [ xd, yd ] = g00_xy ( g, nd );\n\n zd = f00_f0 ( prob, nd, xd, yd );\n\n xyd(1,1:nd) = xd(1:nd);\n xyd(2,1:nd) = yd(1:nd);\n%\n% Set up the Delaunay triangulation.\n%\n [ element_num, triangle, element_neighbor ] = r8tris2 ( nd, xyd );\n%\n% Define the interpolation points.\n%\n k = 0;\n for i = 1 : 5\n for j = 1 : 5\n k = k + 1;\n xyi(1,k) = ( 2 * i - 1 ) / 10.0;\n xyi(2,k) = ( 2 * j - 1 ) / 10.0;\n end\n end\n\n xi(1:ni,1) = xyi(1,1:ni);\n yi(1:ni,1) = xyi(2,1:ni);\n\n ze = f00_f0 ( prob, ni, xi, yi );\n%\n% Evaluate the interpolant.\n%\n zi = pwl_interp_2d_scattered_value ( nd, xyd, zd, element_num, ...\n triangle, element_neighbor, ni, xyi );\n\n rms = 0.0;\n for k = 1 : ni\n rms = rms + ( zi(k) - ze(k) )^2;\n end\n rms = sqrt ( rms / ni );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' RMS error is %g\\n', rms );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' K Xi(K) Yi(K) Zi(K) Z(X,Y)\\n' );\n fprintf ( 1, '\\n' );\n\n for k = 1 : ni\n fprintf ( 1, ' %4d %10f %10f %10f %10f\\n', ...\n k, xyi(1,k), xyi(2,k), zi(k), ze(k) );\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/pwl_interp_2d_scattered/pwl_interp_2d_scattered_test03.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.8933094046341533, "lm_q1q2_score": 0.8069212100001214}} {"text": "function [Feven,Fodd] = filterGabor2d( r, sig, lam, theta, omega, show )\n% Creates an even/odd pair of 2D Gabor filters.\n%\n% Creates a pair of Gabor filters (one odd one even) at the specified\n% orientation. For Thomas' ECCV98 filters, use sig=sqrt(2), lam=4. Note\n% that originally this function computed a quadratic masked with a\n% Gaussian, and not a sin/cos masked with a Gaussian. Requires Matlab's\n% 'Signal Processing Toolbox'.\n%\n% USAGE\n% [Feven,Fodd] = filterGabor2d( r, sig, lam, theta, [omega], [show] )\n%\n% INPUTS\n% r - final mask will be 2r+1 x 2r+1\n% sig - standard deviation of Gaussian mask\n% lam - elongation of Gaussian mask\n% theta - orientation (in degrees)\n% omega - [1] wavlength of underlying sine (sould be >=1)\n% show - [0] figure to use for optional display\n%\n% OUTPUTS\n% Feven - even symmetric filter (-cosine masked with Gaussian)\n% Fodd - odd symmetric filter (-sine masked with Gaussian)\n%\n% EXAMPLE\n% [Feven,Fodd] = filterGabor2d(15,sqrt(2),4,45,1,1);\n% [Feven,Fodd] = filterGabor2d(25,4,2,0,2,3);\n%\n% See also FILTERGABOR1D, FILTERGAUSS\n%\n% Piotr's Image&Video Toolbox Version 2.12\n% Copyright 2012 Piotr Dollar. [pdollar-at-caltech.edu]\n% Please email me if you find bugs, or have suggestions or questions!\n% Licensed under the Simplified BSD License [see external/bsd.txt]\n\nif( nargin<5 || isempty(omega) ); omega=1; end\nif( nargin<6 || isempty(show) ); show=0; end\n\n% create even/odd Gabor filters\n[x,y]=meshgrid(-r:r,-r:r);\nmask = exp(-(y.^2)/(sig^2)-(x.^2)/(lam^2*sig^2));\nFeven = -cos(2*pi*y/4/omega) .* mask;\n%Feven = (4*(y.^2)/(sig^4)-2/(sig^2)).*mask; % original function was y.^2\nFodd = imag(hilbert(Feven));\n\n% orient appropriately\nFeven = imrotate(Feven,theta,'bil','crop');\nFodd = imrotate(Fodd,theta,'bil','crop');\n\n% Set mean to 0 (should already be 0)\nFeven=Feven-mean(Feven(:));\nFodd=Fodd-mean(Fodd(:));\n\n% set L1norm to 0\nFeven=Feven/norm(Feven(:),1);\nFodd=Fodd/norm(Fodd(:),1);\n\n% display\nif( show )\n filterVisualize( Feven, show );\n filterVisualize( Fodd, show+1 );\nend\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/Toolbox/SketchTokens-master/toolbox/filters/filterGabor2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.880797076413356, "lm_q1q2_score": 0.806906677393211}} {"text": "%RPY2TR Roll-pitch-yaw angles to SE(3) homogeneous transform\n%\n% T = RPY2TR(ROLL, PITCH, YAW, OPTIONS) is an SE(3) homogeneous\n% transformation matrix (4x4) with zero translation and rotation equivalent\n% to the specified roll, pitch, yaw angles angles. These correspond to\n% rotations about the Z, Y, X axes respectively. If ROLL, PITCH, YAW are\n% column vectors (Nx1) then they are assumed to represent a trajectory and\n% R is a three-dimensional matrix (4x4xN), where the last index corresponds\n% to rows of ROLL, PITCH, YAW.\n%\n% T = RPY2TR(RPY, OPTIONS) as above but the roll, pitch, yaw angles are\n% taken from the vector (1x3) RPY=[ROLL,PITCH,YAW]. If RPY is a matrix\n% (Nx3) then R is a three-dimensional matrix (4x4xN), where the last index\n% corresponds to rows of RPY which are assumed to be\n% ROLL,PITCH,YAW].\n%\n% Options::\n% 'deg' Compute angles in degrees (radians default)\n% 'xyz' Rotations about X, Y, Z axes (for a robot gripper)\n% 'zyx' Rotations about Z, Y, X axes (for a mobile robot, default)\n% 'yxz' Rotations about Y, X, Z axes (for a camera)\n% 'arm' Rotations about X, Y, Z axes (for a robot arm)\n% 'vehicle' Rotations about Z, Y, X axes (for a mobile robot)\n% 'camera' Rotations about Y, X, Z axes (for a camera)\n%\n% Note::\n% - Toolbox rel 8-9 has the reverse angle sequence as default.\n% - ZYX order is appropriate for vehicles with direction of travel in the X\n% direction. XYZ order is appropriate if direction of travel is in the Z\n% direction.\n% - 'arm', 'vehicle', 'camera' are synonyms for 'xyz', 'zyx' and 'yxz'\n% respectively.\n%\n% See also TR2RPY, RPY2R, EUL2TR.\n\n% Copyright (C) 1993-2019 Peter I. Corke\n%\n% This file is part of The Spatial Math Toolbox for MATLAB (SMTB).\n% \n% Permission is hereby granted, free of charge, to any person obtaining a copy\n% of this software and associated documentation files (the \"Software\"), to deal\n% in the Software without restriction, including without limitation the rights\n% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\n% of the Software, and to permit persons to whom the Software is furnished to do\n% so, subject to the following conditions:\n%\n% The above copyright notice and this permission notice shall be included in all\n% copies or substantial portions of the Software.\n%\n% THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR \n% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n% FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n% COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n% IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n%\n% https://github.com/petercorke/spatial-math\n\nfunction T = rpy2tr(roll, varargin)\n\n R = rpy2r(roll, varargin{:});\n T = r2t(R);\n", "meta": {"author": "petercorke", "repo": "spatialmath-matlab", "sha": "6eeff4a79f14286705560b84f1fe72e0b7e0e7f7", "save_path": "github-repos/MATLAB/petercorke-spatialmath-matlab", "path": "github-repos/MATLAB/petercorke-spatialmath-matlab/spatialmath-matlab-6eeff4a79f14286705560b84f1fe72e0b7e0e7f7/rpy2tr.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.8807970654616711, "lm_q1q2_score": 0.8069066572734165}} {"text": "function [mu, Q] = matrixCoherence(A)\n% Computes the coherence of a matrix `A`, that is\n% the maximum absolute value of the cross correlations\n% between the columns of `A`\n%\n% USAGE:\n%\n% [mu, Q] = matrixCoherence(A)\n%\n% INPUT:\n% A: Matrix\n%\n% OUTPUTS:\n% mu: coherence\n% Q: matrix used by `mu`\n\nn = size(A, 2);\nQ = zeros(n, n);\nfor j = 1:n\n for k = 1:n\n if j ~= k\n Q(j, k) = abs(A(:, j)' * A(:, k)) / (norm(A(:, j)) * norm(A(:, k)));\n end\n end\nend\nmu = max(max(Q));\n", "meta": {"author": "opencobra", "repo": "cobratoolbox", "sha": "e60274d127f65d518535fd0814d20c53dc530f73", "save_path": "github-repos/MATLAB/opencobra-cobratoolbox", "path": "github-repos/MATLAB/opencobra-cobratoolbox/cobratoolbox-e60274d127f65d518535fd0814d20c53dc530f73/src/analysis/topology/matrixCoherence.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533088603709, "lm_q2_score": 0.8652240773641087, "lm_q1q2_score": 0.8067810538438247}} {"text": "function S=hypergeometric0F1(a,z)\n%%HYPERGEOMETRIC0F1 Evaluate the confluent hypergeometric function 0F1 for\n% real or complex parameters. This is the confluent\n% hypergeometric limit function 0F1(;a;z).\n%\n%INPUTS: a A real or complex scalar value.\n% z A real or complex scalar value.\n%\n%OUTPUTS: S The value 0F1(;a;z).\n%\n%This implements the Taylor series expansion of APpendix I of [1]. It was\n%noted that the series generated at least 12 digits of accuracy for\n%abs(z)<=1000. A check was added for values of a that are real and negtive\n%as the solution should be infinite in that case. However, neighboring\n%solutions are finite.\n%\n%REFERENCES:\n%[1] J. Pearson, \"Computation of hypergeometric functions,\" Master's\n% thesis, University of Oxford, Worcester College, 4 Sep. 2009.\n%\n%July 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\n%Check for the special case.\nif(isreal(a)&&a<0)\n S=Inf;\n return;\nend\n\nA=1;\nS=A;\n\nepsVal=Inf;\nk=0;\nwhile(epsVal>eps(S))\n A=A*(1/(a+k))*(z/(k+1));\n S=S+A;\n \n epsVal=abs(A);\n \n k=k+1;\nend\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/hypergeometric0F1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8918110339361275, "lm_q1q2_score": 0.8067773313517632}} {"text": "function OutMatrix = IncompleteBellPoly(Nin,Kin,DataList)\n%INCOMPLETEBELLPOLY An iterative method for computing the incomplete (also known as the second kind of) Bell polynomials.\n%\n% Purpose:\n% Given a list of input values (x_{1},x_{2},...,x_{N}), the script returns a matrix of Bell polynomials B_{n,k} for \n% n=0,...,N and k=0,...,K.\n%\n% Syntax:\n% OutMatrix = IncompleteBellPoly(Nin,Kin,DataList)\n% where \n% B_{n,k} = OutMatrix(n+1,k+1)\n% n=0,...,Nin\n% k=0,...,Kin (Kin<=Nin)\n% DataList = (x_{1},x_{2},...,x_{Nin})\n%\n% Authors:\n% Patrick Kano and Moysey Brio\n% University of Arizona\n%\n% Email:\n% brio@math.arizona.edu\n%\n% Latest Modification Date:\n% April 3, 2007\n%\n% Discussion: \n% Given Taylor expansion coefficients of a function g(t) {g_{0},g_{1},g_{2},...} with g_{0}=0, \n% B_{n,k}(g_{0},g_{1},...,g_{n-k+1}) is the nth Taylor coefficient of the kth derivative of g(t)/(k!) in terms of {g_{0},g_{1},g_{2},...}\n% \\frac{1}{k!} g^{k}(t) = \\sum_{n=0}^{\\infty} B_{n,k} \\frac{t^{n}}{n!}\n%\n% The Bell polynomials can be computed efficiently by a recursion relation \n% B_{n,k} = \\sum_{m=1}^{n-k+1} \\binom{n-1}{m-1} g_{m} B_{n-m,k-1}\n% where\n% B_{0,0} = 1; \n% B_{n,0} = 0; for n=>1\n% B_{0,k} = 0; for k=>1\n%\n% The coefficients can be stored in a lower triangular matrix. The elements of the kth column are the Taylor coefficients\n% of the kth derivative of g(t)/k!.\n%\n% In application, the polynomials arise in multiple contexts in combinatorics. They also can be found in Riordan's\n% formulation of di Bruno's formula for computing an arbitrary order derivative of the composition of two functions\n% \\frac{d^{n}}{dt^{n}} g(f(t)) = \\sum_{k=0}^{n} g^{k}(f(t)) B_{n,k}(f^{1}(t),f^{2}(t),...,f^{n-k+1}(t))\n%\n% Script Check:\n% If DataList=1 for all entries, B_{n,k} = S(n,k) = Stirling number of the second kind for (n,k)\n%\n% Failure Return:\n% OutMatrix is undefined if the code fails. An error statement is issued and the function exits.\n%\n% References:\n% Ferrell S. Wheeler, Bell Polynomials, ACM SIGSAM Bulletin, vol. 21, issue 3, pp.44-53, 1987.\n%\n% Warren P. Johnson, The curious history of Faa di Bruno's formula, The American mathematical monthly, vol. 109, no. 3, pp. 217-234, March 2002.\n%\n% http://en.wikipedia.org/wiki/Bell_polynomials\n% \n% Supported by: Grant # NSF ITR-0325097\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%n - row index\n%k - column index\n\n%Check that sufficient input variables x_{1},x_{2},...,x_{N} have been given.\n%Note: To compute B_{n,k} requires (x_{1},x_{2},...,x_{n-k+1}) input terms. \n%However, we want B_{n=1...N,k=1...N), which includes B_{n=N,k=1}.\n%To determine B_{N,1}, we thus require (x_{1},x_{2},...,x_{N}) input terms.\n \nListLength = length(DataList);\n\nif(ListLength0 && Kin==0)\n OutMatrix = zeros(Nin+1,1);\n OutMatrix(1,1) = 1;\n return;\n\nelse\n %Compute the recursion relationship\n %Note: To keep with Matlab's convention for starting indices at 1 we compute only the non-trivial elements of the matrix.\n \n %Initialize the Triangular Matrix\n Bm = zeros(Nin,Kin);\n\n %Starting values for the recurrence relations \n %Bm(0,0) = 1; \n %Bm(n,0) = 0; for n=>1\n %Bm(0,k) = 0; for k=>1\n %kidx=1\n Bm(1:Nin,1) = DataList(1:Nin);\n\n %Generate each required row of data\n for(nidx=2:Nin) %row, Note: Row 1 has only 1 non-zero element\n \n for(kidx=2:Kin) %column, Note: Column 1 is the given input array\n \n for(midx=1:nidx-kidx+1) %recursion\n Bm(nidx,kidx) = Bm(nidx,kidx) + nchoosek(nidx-1,midx-1)*DataList(midx)*Bm(nidx-midx,kidx-1); \n end\n \n end\n end\n\n %Append [1,0,...] to generate the complete output matrix\n OutMatrix = eye(Nin+1,Kin+1);\n OutMatrix(2:Nin+1,2:Kin+1) = Bm;\nend\n\nend %End of the 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/14483-bell-polynomials-of-the-second-kind/IncompleteBellPoly.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.8633916205190225, "lm_q1q2_score": 0.8067489567460228}} {"text": "function [J, grad] = costFunction(theta, X, y)\n%COSTFUNCTION Compute cost and gradient for logistic regression\n% J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the\n% parameter for logistic regression and the gradient of the cost\n% w.r.t. to the parameters.\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n% Note: grad should have the same dimensions as theta\n%\n\npredictions = sigmoid(X*theta);\n\nleftPart = -y' * log(predictions);\n\nrightPart = (1 - y') * log(1 - predictions);\n\nJ = (1 / m) * (leftPart - rightPart);\n\ngrad = (1 / m) * ((predictions - y)' * X);\n\n\n\n\n\n\n% =============================================================\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-3/exercises/machine-learning-ex2/ex2/costFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067179697694, "lm_q2_score": 0.8558511432905481, "lm_q1q2_score": 0.8066454521334493}} {"text": "function [x,y,z]=ell2xyz(lat,lon,h,a,e2)\n% ELL2XYZ Converts ellipsoidal coordinates to cartesian.\n% Vectorized.\n% Version: 2011-02-19\n% Useage: [x,y,z]=ell2xyz(lat,lon,h,a,e2)\n% [x,y,z]=ell2xyz(lat,lon,h)\n% Input: lat - vector of ellipsoidal latitudes (radians)\n% lon - vector of ellipsoidal E longitudes (radians)\n% h - vector of ellipsoidal heights (m)\n% a - ref. ellipsoid major semi-axis (m); default GRS80\n% e2 - ref. ellipsoid eccentricity squared; default GRS80\n% Output: x \\\n% y > vectors of cartesian coordinates in CT system (m)\n% z /\n\n% Copyright (c) 2011, Michael R. Craymer\n% All rights reserved.\n% Email: mike@craymer.com\n\nif nargin ~= 3 & nargin ~= 5\n warning('Incorrect number of input arguments');\n return\nend\nif nargin == 3\n [a,b,e2]=refell('grs80');\nend\n\nv=a./sqrt(1-e2*sin(lat).*sin(lat));\nx=(v+h).*cos(lat).*cos(lon);\ny=(v+h).*cos(lat).*sin(lon);\nz=(v.*(1-e2)+h).*sin(lat);\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/ell2xyz.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811631528336, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.8065600727985014}} {"text": "function program_02 ( )\n\n%*****************************************************************************80\n%\n%% PROGRAM_02 demonstrates point and triangle orientation.\n%\n% Discussion:\n%\n% The program\n% * reads a triangle T (defined by three points),\n% * determines the orientation of the triangle;\n% * computes and prints the length of the edges;\n% * reads a point P\n% * computes the signed distance from P to each line\n% (not the line segment!)\n% * reports whether the point is INSIDE, ON or OUTSIDE the triangle.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 February 2007\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PROGRAM_02 - Point/Triangle Orientation\\n' );\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Define a triangle T:\\n' );\n\n t_v1 = input ( ' Enter [ T.v1.x, T.v1.y]: ' ); \n t_v2 = input ( ' Enter [ T.v2.x, T.v2.y]: ' ); \n t_v3 = input ( ' Enter [ T.v3.x, T.v3.y]: ' ); \n%\n% Compute the edges.\n%\n t_e1 = t_v2 - t_v1;\n t_e2 = t_v3 - t_v2;\n t_e3 = t_v1 - t_v3;\n%\n% Compute the unit normal vectors to each edge.\n% MATLAB's NORM function returns the square root of the sum\n% of the squares of the entries of a vector.\n%\n t_e1_nv = [ -t_e1(2), t_e1(1) ] / norm ( t_e1 );\n t_e2_nv = [ -t_e2(2), t_e2(1) ] / norm ( t_e2 );\n t_e3_nv = [ -t_e3(2), t_e3(1) ] / norm ( t_e3 );\n%\n% Orientation test.\n% The signed distance of V3 from the line from V1 to V2 must be positive.\n%\n test = t_e1_nv * ( t_v3 - t_v1 )';\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Orientation test value = %f\\n', test );\n\n if ( test < 0.0 )\n fprintf ( 1, ' Error! The triangle is improperly oriented.\\n' );\n return\n elseif ( test == 0.0 )\n fprintf ( 1, ' Error! The triangle is degenerate!\\n' );\n else\n fprintf ( 1, ' The triangle is properly oriented.\\n' );\n end\n%\n% Edge lengths.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Edge1 = v2-v1, length = %f\\n', norm ( t_e1 ) );\n fprintf ( 1, ' Edge2 = v3-v2, length = %f\\n', norm ( t_e2 ) );\n fprintf ( 1, ' Edge3 = v1-v3, length = %f\\n', norm ( t_e3 ) );\n%\n% Check various points.\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Now we see whether a point is in the triangle.\\n' );\n fprintf ( 1, '\\n' );\n\n while ( 1 )\n\n p = [];\n fprintf ( 1, '\\n' );\n p = input ( ' Enter a point [ P.x, P.y], or RETURN to quit: ' );\n\n if ( isempty ( p ) )\n break\n end\n\n% Compute the signed distance from the point to the line that\n% includes each edge.\n%\n p_e1_dist = t_e1_nv * ( p - t_v1 )';\n p_e2_dist = t_e2_nv * ( p - t_v2 )';\n p_e3_dist = t_e3_nv * ( p - t_v3 )';\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' Distance to line through edge 1 = %f\\n', p_e1_dist );\n fprintf ( 1, ' Distance to line through edge 2 = %f\\n', p_e2_dist );\n fprintf ( 1, ' Distance to line through edge 3 = %f\\n', p_e3_dist );\n\n fprintf ( 1, '\\n' );\n if ( p_e1_dist < 0.0 | p_e2_dist < 0.0 | p_e3_dist < 0.0 )\n fprintf ( 1, ' The point is OUTSIDE the triangle\\n' );\n elseif ( p_e1_dist == 0.0 | p_e2_dist == 0.0 | p_e3_dist == 0.0 )\n fprintf ( 1, ' The point is ON the triangle\\n' );\n else\n fprintf ( 1, ' The point is INSIDE the triangle.\\n' );\n end\n\n end\n \n fprintf ( 1, '\\n' );\n fprintf ( 1, 'PROGRAM_02\\n' );\n fprintf ( 1, ' Normal end of execution.\\n' );\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/cg_lab_triangles/program_02.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240211961401, "lm_q2_score": 0.8596637433190939, "lm_q1q2_score": 0.8064712077590348}} {"text": "function [H,mu,SR]=standardGaussKernelBW(param1,method,spherData,N)\n%%STANDARDGAUSSKERNELBW Estimate the (univariate or multivariate) kernel\n% bandwidth when approximating a PDF using a set of samples\n% with a Gaussian kernel. This function provides the bandwidth\n% estimate based on the optimal solution if the underlying\n% density of the samples is normal. If the density is not\n% normal, then this function is just an approximation. The\n% kernel bandwidth estimate can be used with the points xi in\n% the function kernelApprox to approximate the continuous\n% density.\n%\n%INPUTS: param1 If N is an empty matrix or is omitted, then this is:\n% xi A numDimXnumSamples set of samples of the distribution\n% from which a Gaussian kernel estimator should interpolate\n% a PDF. For multidimensional estimation, there must be\n% >=numDim samples. Specifically, the sample covariance\n% matrix must be positive definite.\n% If N is given, then this is:\n% SR A root covariance matrix such that SR*SR' equals the \n% (exact or approximated) covariance matrix of the PDF\n% being approximated.\n% method An optional parameter specifying the method that should be used\n% to estimate the bandwidth. Possible values are\n% 0 Use the method implied by Equation 3.30 and 3.28 in [1],\n% which uses the lesser of the sample standard deviation or a\n% scaled interquartile range. This approach is supposed to work\n% well when the underlying distribution of the samples is not\n% actually normal and might be bimodal. This method cannot be\n% used if N is given.\n% 1 (The default if omitted or an empty matrix is passed) Use the\n% method of Equation 3.28 in [1], based on the sample standard\n% deviation.\n% 2 Use the method of Equation 3.29 in [1], based on the\n% interquartile range of the samples. This method cannot be\n% used if N is given.\n% spherData When the underlying density is truly normal, then the\n% approximation here is only valid if the cross terms of the\n% correlation are zero. To make that the case, if this parameter\n% is true, then the data is \"sphered\" --premultiplied by the\n% inverse of the square root (lower-triangular Cholesky\n% decomposition) of the sample covariance matrix, and then the\n% final result is multipled by the square root of the sample\n% covariance matrix to scale everything back. However, when this\n% function is used for approximations, sphering can sometimes\n% make thing worse. Thus, if this is false, then only the\n% diagonal terms of the sample covariance matrix are used and the\n% data is not squared. The default if this parameter is omitted\n% or an empty matrix is passed is true.\n% N If this parameter is provided, then param1 is assumed to be SR\n% and N is the number of samples that are being smoothed.\n% Otherwise, if this is omitted or an empty matrix is passed,\n% param1 is xi.\n% \n%OUTPUTS: H The kernel bandwidth matrix that can be used in the function\n% kernelApprox. This will be a lower-triangular matrix.\n% mu If xi is given, then this is the sample mean. Otherwise, this\n% is an empty matrix.\n% SR The root covariance matrix from the input or computed from xi.\n%\n%The methods in Chapter 3 of [1] are for a scalar distribution. We are able\n%to apply them to a multivariate distribution by pre-multiplying the\n%multivariate distribution by the inverse of the sample standard deviation\n%of the points. If the samples were from a normal distribution (the\n%approximation used here), then we can replace the scalar bandwidth\n%formula with the solution for numDim-dimensions given in Chapter 2.4.2 of\n%[2]. The pre-multiplication to decorrelate the dimensions is necessary for\n%the use of that formula. Ultimately, we then have then rotate the final\n%result back. The techniques from Chapter 3 of 1 that are used here only\n%differ in how they try to obtain a robust estimate of the standard\n%deviation values.\n%\n%REFERENCES:\n%[1] B. W. Silverman, Density Estimation for Statistics and Data Analysis.\n% Chapman and Hall, 1986.\n%[2] A. D. Bowman and A. Azzalini, Applied Smoothing Techniques for Data\n% Analysis: The Kernel Approach with S-Plus Illustrations. Oxford:\n% Clarendon Press, 2004.\n%\n%December 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<4)\n N=[]; \nend\n\nif(nargin<3||isempty(spherData))\n spherData=true;\nend\n\nif(nargin<2||isempty(method))\n method=1;\nend\nnumDims=size(param1,1);\n\nif(isempty(N))%xi is given\n xi=param1;\n [mu,S]=calcMixtureMoments(xi);\n SR=cholSemiDef(S,'lower',1);%Not fully triangular. but S=SR*SR'\n if(method~=1&&spherData)\n xi=SR\\xi;\n end\n N=size(xi,2);%Number of points\nelse%S and N are given.\n if(method~=1)\n error('If N is given, then method=1 must be used.')\n end\n \n mu=[];\n SR=param1;\nend\n\nif(numDims>1&&spherData)\n sigma1=ones(numDims,1);\nelse\n sigma1=diag(SR);\nend\n\nswitch(method)\n case 0%Use Equation 3.30 and 3.28 in [1].\n sigma2=interquartileRange(xi,2)/(GaussianD.invCDF(0.75)-GaussianD.invCDF(0.25));\n sigma=min([sigma1,sigma2],[],2);\n case 1%Use Equation 3.28 in [1].\n sigma=sigma1;\n case 2%Use the interquartile range (scaled appropriately) instead of\n %the standard deviation in [1]. This is Equation 3.29.\n sigma=interquartileRange(xi,2)/(GaussianD.invCDF(0.75)-GaussianD.invCDF(0.25));\n otherwise\n error('Unknown method specified')\nend\n\nh=(4/(N*(numDims+2)))^(1/(numDims+4))*sigma;\n\n%Undo any rotation/scaling.\nif(numDims>1&&spherData)\n %H is actually aking to the square root of a covariance matrix. h is a\n %list of scalars--the diagonls of the rotated matrix. This builds that\n %diagonal matrix and then scales it.\n H=SR*diag(h);\nelse\n H=diag(h);\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/Kernel_Estimation/standardGaussKernelBW.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8791467564270272, "lm_q1q2_score": 0.8064436618117496}} {"text": "function inside = triangle_contains_point_1 ( t, p )\n\n%*****************************************************************************80\n%\n%% TRIANGLE_CONTAINS_POINT_1 finds if a point is inside a triangle.\n%\n% Discussion:\n%\n% It is conventional to list the triangle vertices in counter clockwise\n% order. However, this routine does not require a particular order\n% for the vertices.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 December 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real T(2,3), the triangle vertices.\n%\n% Input, real P(2,1), the point to be checked.\n%\n% Output, logical INSIDE, is TRUE if the point is inside\n% the triangle or on its boundary.\n%\n xsi = triangle_barycentric ( t, p );\n\n if ( any ( xsi(1:3,1) < 0.0 ) )\n inside = 0;\n else\n inside = 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/polygon_properties/triangle_contains_point_1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.8064375008527788}} {"text": "function value = monomial_int01 ( dim_num, expon )\n\n%*****************************************************************************80\n%\n%% MONOMIAL_INT01 returns the integral of a monomial over the [0,1] hypercube.\n%\n% Discussion:\n%\n% This routine evaluates a monomial of the form\n%\n% product ( 1 <= dim <= dim_num ) x(dim)^expon(dim)\n%\n% where the exponents are nonnegative integers. Note that\n% if the combination 0^0 is encountered, it should be treated\n% as 1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 11 November 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the spatial dimension.\n%\n% Input, integer EXPON(DIM_NUM), the exponents.\n%\n% Output, real VALUE, the value of the integral of the\n% monomial over the [0,1] hypercube.\n%\n value = 1.0 / prod ( expon(1:dim_num) + 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/sparse_grid_cc/monomial_int01.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9441768651485395, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.8062446644372099}} {"text": "function [z,n] = phiflower(p)\n%% PHIFLOWER level set function of a flower\n%\n% Author: Huayi Wei \n\npetal = 5;\nxc = 0;\nyc = 0;\nr0 = 0.5;\nr1 = 0.2;\ntheta = atan2((p(:,2) - yc),(p(:,1) - xc));\nr = r0 + r1*sin(petal*theta);\n\nz = (p(:,2)-yc).^2 + (p(:,1)-xc).^2 - r.^2;\n\nif nargout == 2\n rp = petal*r1*cos(petal*theta);\n n1 = rp.*cos(theta) - r.*sin(theta);\n n2 = rp.*sin(theta) + r.*cos(theta);\n l = sqrt(n1.^2+n2.^2);\n n = [n2./l, -n1./l];\nend\nend", "meta": {"author": "lyc102", "repo": "ifem", "sha": "29f31c812001ca8d93dad08e67208ca60e8716d4", "save_path": "github-repos/MATLAB/lyc102-ifem", "path": "github-repos/MATLAB/lyc102-ifem/ifem-29f31c812001ca8d93dad08e67208ca60e8716d4/mesh/interfacemesh/phiflower.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9553191259110588, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.8061891279824045}} {"text": "clear all; close all; clc\n\nL=30; n=512; x2=linspace(-L/2,L/2,n+1); x=x2(1:n); % spatial discretization\nk=(2*pi/L)*[0:n/2-1 -n/2:-1].'; % wavenumbers for FFT\nV=x.^2.'; % potential\nt=0:0.2:20; % time domain collection points\n\nu=exp(-0.2*(x-1).^2); % initial conditions\nut=fft(u); % FFT initial data\n[t,utsol]=ode45('harm_rhs',t,ut,[],k,V); % integrate PDE\nfor j=1:length(t)\n usol(j,:)=ifft(utsol(j,:)); % transforming back\nend\n\nu2=exp(-0.2*(x-0).^2);\nut=fft(u2);\n[t,utsol]=ode45('harm_rhs',t,ut,[],k,V);\nfor j=1:length(t)\n usol2(j,:)=ifft(utsol(j,:));\nend\n\nfigure(1)\nsubplot(2,2,2)\nsurfl(x,t,abs(usol)+2), shading interp, colormap(gray) %colormap([0 0 0])\nhold on\npcolor(x,t,abs(usol)), shading interp, %colormap(gray)\nview(20,25)\ntv=0*x+20;\nVx=x.^2;\nplot3(x(12:end-12),tv(12:end-12),Vx(12:end-12)/100+2,'k','Linewidth',[2])\nset(gca,'Xlim',[-15 15],'Ylim',[0 20],'Zlim',[0 4],'Xtick',[-15 -10 -5 0 5 10 15],'Ytick',[0 10 20],'Ztick',[2 3 4], ...\n 'Zticklabel',{'0','1','2'},'Fontsize',[15]);\n\nfigure(1)\nsubplot(2,2,1)\nsurfl(x,t,abs(usol2)+2), shading interp, colormap(gray) %colormap([0 0 0])\nhold on\npcolor(x,t,abs(usol2)), shading interp, %colormap(gray)\nview(20,25)\ntv=0*x+20;\nVx=x.^2;\nplot3(x(12:end-12),tv(12:end-12),Vx(12:end-12)/100+2,'k','Linewidth',[2])\nset(gca,'Xlim',[-15 15],'Ylim',[0 20],'Zlim',[0 4],'Xtick',[-15 -10 -5 0 5 10 15],'Ytick',[0 10 20],'Ztick',[2 3 4], ...\n 'Zticklabel',{'0','1','2'},'Fontsize',[15]);\n\n\n%surfl(x,t,abs(usol)), colormap(gray)\n\nfor j=1:length(t)\n usol3(j,:)=usol(j,n:-1:1);\nend\n\nusym=[usol; usol3];\n\n[U,S,V]=svd(usol.');\n[U2,S2,V2]=svd(usol2.');\n[U3,S3,V3]=svd(usym.');\n\n\nfigure(1)\nsubplot(4,2,6)\nplot(100*diag(S)/sum(diag(S)),'ko','Linewidth',[2]), grid on\nset(gca,'Xlim',[0 20],'Ylim',[0 80],'Ytick',[0 40 80],'Fontsize',[15])\nxlabel('')\n\nsubplot(4,2,5)\nplot(100*diag(S2)/sum(diag(S2)),'ko','Linewidth',[2]), grid on\nset(gca,'Xlim',[0 20],'Ylim',[0 80],'Ytick',[0 40 80],'Fontsize',[15])\nxlabel('')\n\n\nfigure(2)\nsubplot(3,1,3)\nsn=[-1 1 1 1 -1];\nfor j=1:5\n nrm=sqrt(trapz(x,U(:,j).^2));\n Up(:,j)=real(U(:,j))*sn(j)/nrm;\nend\nplot(x,real(Up(:,1:5)),'Linewidth',[2])\nset(gca,'Xlim',[-5 5],'Xtick',[-5 -2.5 0 2.5 5],'Ylim',[-1 1],'Ytick',[-1 -0.5 0 0.5 1],'Fontsize',[15])\nlegend('mode 1','mode 2','mode 3','mode 4','mode 5')\n\nsubplot(3,1,2)\nsn=[-1 -1 1 -1 -1];\nfor j=1:5\n nrm=sqrt(trapz(x,U2(:,j).^2));\n Up2(:,j)=real(U2(:,j))*sn(j)/nrm;\nend\nplot(x,real(Up2(:,1:5)),'Linewidth',[2])\nset(gca,'Xlim',[-5 5],'Xtick',[-5 -2.5 0 2.5 5],'Ylim',[-1 1],'Ytick',[-1 -0.5 0 0.5 1],'Fontsize',[15])\n% subplot(4,1,4)\n% sn=[-1 1 1 1 -1];\n% for j=1:5\n% Up3(:,j)=real(U3(:,j))*sn(j)/norm(U3(:,j));\n% end\n% plot(x,real(Up3(:,1:5)),'Linewidth',[2])\n% set(gca,'Xlim',[-5 5],'Xtick',[-5 -2.5 0 2.5 5],'Ylim',[-0.2 0.2],'Ytick',[-0.2 -0.1 0 0.1 0.2],'Fontsize',[15])\n\n\n\n\nh=[1+0*x; 2*x; 4*x.^2-2; 8*x.^3-12*x; 16*x.^4-48*x.^2+12];\nfor j=0:4\n phi(:,j+1)=(1/(sqrt(factorial(j)*(2^j)*sqrt(pi))).*exp(-x.^2/2).*h(j+1,:)).';\n nrm=sqrt(trapz(x,phi(:,j+1).^2));\n phi2(:,j+1)=phi(:,j+1)/nrm;\nend\nsubplot(3,1,1), plot(x,phi2,'Linewidth',[2]),\nset(gca,'Xlim',[-5 5],'Xtick',[-5 -2.5 0 2.5 5],'Ylim',[-1 1],'Ytick',[-1 -0.5 0 0.5 1],'Fontsize',[15])\n\n", "meta": {"author": "dynamicslab", "repo": "databook_matlab", "sha": "d390d39d18489a4804ee87a143ae8db8a1f3010b", "save_path": "github-repos/MATLAB/dynamicslab-databook_matlab", "path": "github-repos/MATLAB/dynamicslab-databook_matlab/databook_matlab-d390d39d18489a4804ee87a143ae8db8a1f3010b/CH11/CH11_SEC02_1_HarmonicOscillator.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.8723473763375643, "lm_q1q2_score": 0.8061726956673995}} {"text": "function [x,M]=semidefQuadProgEqConst(B,a,A,b)\n%%SEMIDEFQUADPROGEQCONST Solve a quadratic programming problem involving a\n% semidefinite matrix (or a positive defintie matrix) where there are\n% only equality constraints, no inequality constraints. Specifically,\n% this algorithm solves the optimization problem: \n% minimize_x x'*B*x+2*a'*x\n% subject to A*x=b\n% If B is positive semidefinite, then if a solution exists, an\n% infinite number actually exist. This function returns one solution\n% and a matrix that can be used to find the other solutions.\n%\n%INPUTS: B An nXn real positive definite or positive semidefinite,\n% symmetric matrix.\n% a An nX1 real vector.\n% A A numConstXn real matrix. This can be an omitted or empty matrix\n% can be passed if there are no constraints. numConst<=n. There\n% shouldn't be any redundant constraints.\n% b A numConstX1 real vector.\n%\n%OUTPUTS: x The nX1 solution.\n% M An nXn matrix. All other solutions are of the form\n% xOther=x+M*y, where y is a an nX1 real vector.\n%\n%This function implements the equations of Chapter IV of [1]. Note that\n%based on the constraints, it is possible for no solution to exist. This\n%function is run assuming that a solution exists; it does not check for\n%soluion non-existence.\n%\n%EXAMPLE:\n%This is example 4.1 in [1]. x will be [9;18;35]/20.\n% B=[1, 2,-1;\n% 2, 4,-2;\n% -1,-2,1];\n% a=[2;4;1];\n% A=[1,2,1];\n% b=4;\n% [x,M]=semidefQuadProgEqConst(B,a,A,b)\n%One sees that the third row and column of M is all zeros. Also,\n%M(:,2)=-M(:,1)/2, so the matrix is singular. Thus, the second column of M\n%can be used as a basis. So, to get any new point, we can use x+M(:,2)*v\n%(for a scalar v) or we could use x+5*M(:,2)*v, which is the same as the\n%solution given in [1].\n%\n%REFERENCES:\n%[1] D. L. Nelson, \"Quadratic programming techniques using matrix\n% pseudoinverses,\" Ph.D. dissertation, Texas Tech University, Lubbock,\n% TX, Dec. 1969.\n%\n%October 2022 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<3||isempty(A))\n %If there are no constraints, call the unconstrained algorithm.\n [x,M]=semidefQuadProgUnconst(B,a);\n return;\nend\n\nn=length(a);\nI=eye(n,n);\npinvA=pinv(A);\ndiffA=(I-pinvA*A);\nC=diffA*B*diffA;\npinvC=pinv(C);\n\n%A combination of Equation 4.3 and 4.5.\nx=pinvA*b+diffA*pinv(C)*diffA*(a-B*pinvA*b);\nM=diffA*(I-pinvC*C);\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/Continuous_Optimization/Quadratic_Programming/semidefQuadProgEqConst.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.8872045981907006, "lm_q1q2_score": 0.8061299717663426}} {"text": "% Section 8.5.3: Analytic center of a set of linear inequalities\n% Boyd & Vandenberghe \"Convex Optimization\" \n% Joëlle Skaf - 04/29/08 \n%\n% The analytic center of a set of linear inequalities and equalities:\n% a_i^Tx <= b_i i=1,...,m,\n% Fx = g,\n% is the solution of the unconstrained minimization problem \n% minimize -sum_{i=1}^m log(b_i-a_i^Tx).\n\n% Input data \nrandn('state', 0);\nrand('state', 0);\nn = 10;\nm = 50; \np = 5;\ntmp = randn(n,1);\nA = randn(m,n); \nb = A*tmp + 10*rand(m,1); \nF = randn(p,n); \ng = F*tmp; \n\n% Analytic center \ncvx_begin\n variable x(n)\n minimize -sum(log(b-A*x))\n F*x == g; %#ok\ncvx_end\n\ndisp(['The analytic center of the set of linear inequalities and ' ... \n 'equalities is: ']);\ndisp(x);\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/cvxbook/Ch08_geometric_probs/analytic_center.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551546097941, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.8061205953896806}} {"text": "% By Sherif A. Tawfik, Faculty of Engineering, Cairo University\nfunction y=findzero(fun,x0,x1,varargin)\n% fun is the function that we need to compute its root.\n% x0 and x1 are two arguments to the function such that the root that we\n% seek lie between them and the function has different sign at these two\n% points\n% varargin are the other arguments of the function\n\n% the value of the function at the first point\nf0=feval(fun,x0,varargin{:}); \n\n%the value of the function at the second point\nf1=feval(fun,x1,varargin{:});\n\n% check that the sign of the function at x0 and x1 is different. Otherwise\n% report an error\nif sign(f0)==sign(f1)\n error('the function at the two endpoints must be of opposite signs');\nend\n\n%find a closer point to the root using the method of chords. In the method\n%of chords we simply connect the two points (x0, f(x0)) and (x1, f(x1))\n%using a straight line and compute the intersection point with this line\n%and the horizontal axis. This new point is closer to the desired root\nx=x0 - f0 * ((x1-x0)/(f1-f0));\n\n%evaluate the function at this new point\nf=feval(fun,x,varargin{:});\n\n% enter this root as long as the difference between the two points that\n% sandwitch the desired root is larger than a certain threshold\nwhile abs(f)>2^-52\n % we keep one of the two old points that has a different sign than the\n % new point and we overwrite the other old point with the new point\n if sign(f)==sign(f0)\n x0=x;\n f0=f;\n else\n x1=x;\n f1=f;\n end\n x=x0 - f0 * ((x1-x0)/(f1-f0));\n f=feval(fun,x,varargin{:});\nend\n% at the end of the loop we reach the root with the desired precision and\n% it is given by x\ny=x;", "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/8094-remez-algorithm/remez/findzero.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.8774767986961403, "lm_q1q2_score": 0.8059451061509793}} {"text": "function mat_gram = GetKernelMat(data1,data2,kernel_type,kernel_param)\n% Ccomputes the Gram matrix of a specified kernel function.\n%Input: data1, data2-Input data matix \n% kernel_type: 'linear' | 'poly' | 'rbf'|'intersect'|'sigmoid'\n% 2016-10-16 by jlfeng\n\nn1=size(data1,1);\nn2=size(data2,1);\n\nswitch kernel_type\n case 'linear'\n mat_gram=data2*data1';\n case 'poly'\n mat_gram=(data2*data1'+1).^kernel_param; \n case 'polyhomog'\n mat_gram=(data2*data1').^kernel_param;\n case 'rbf'\n mat_gram = exp(-(repmat(sum(data1.*data1,2)',n2,1) + ...\n repmat(sum(data2.*data2,2),1,n1) - 2*data2*data1') ...\n /(2*kernel_param^2)); \n case 'intersect'\n mat_gram=zeros(n2,n1);\n for kk=1:n1\n temp=min(data2,repmat(data1(kk,:),[n2 1]));\n mat_gram(:,kk)=sum(temp,2);\n end\n case 'sigmod'\n mat_gram=tanh(data2*data1'*kernel_param(1)+kernel_param(2));\n otherwise\n error('Unknown kernel function.');\nend\n\n", "meta": {"author": "zhangqianqianQQ", "repo": "MachineVisionAlgorithm", "sha": "683338f6c3b1aab9fa2b80026915fe936aebf0ee", "save_path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm", "path": "github-repos/MATLAB/zhangqianqianQQ-MachineVisionAlgorithm/MachineVisionAlgorithm-683338f6c3b1aab9fa2b80026915fe936aebf0ee/分类算法/HSI-Classification-master/utils/GetKernelMat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620619801095, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.805944810101998}} {"text": "function [c,E,exitVal]=minimaxPolyFit(f,xSpan,n,RelTol,maxIter)\n%MINIMAXPOLYFIT Find an interpolating polynomial of order n to minimize\n% the maximum error approximating a scalar function f in the\n% range [xSpan(1);xSpan(2)]. The Remez algorithm is used.\n% \n%INPUTS: f A handle to the function that is to be approximated. The use\n% y=f(x) take a scalar x and returns a value y.\n% xSpan The range of inputs of x over which a minimax interpolating\n% polynomial is desired. The format is [xMin;xMax]. If this is\n% omitted or an empty matrix is passed, the values [-1;1] are\n% used.\n% n The degree of the polynomial approximation desired. If this is\n% omitted or an empty matrix is passed, the default value of n=5\n% is used. If too small a value is used and the function\n% oscillates a lot, the output polynomial will not be a true\n% minimax polynomial, because the algorithm assumes that there is\n% one maxima between regions chosen for selecting points. Also,\n% if f is an mth order polynomial, but is symmetric, then n\n% should be m+1 due to assumptions in the algorithm (the\n% resulting output will have the extra coefficient zero).\n% RelTol The relative tolerance of the maximum error used for\n% determining convergence. Iterations adjust the maximum error\n% observed with respect to points at which the function is\n% evaluated. When the maximum error stops changing across\n% iterations, convergence is assumed. The relative maximum error\n% is abs(E-EPrev)/abs(E); where E is the error and EPRev is the\n% error from the previous iteration. If this parameter is omitted\n% or an empty matrix is passed, a value of 1e-12 is used.\n% maxIter The maximum number of iterations for convergence. If omitted, a\n% value of 50 is used.\n%\n%OUTPUTS: c An interpolating polynomial such that polyval(c,xRel) gives the\n% interpolated value of f where xRel is the fractional distance\n% between xSpan(1) and xSpan(2). The value xRel ranges from 0 to\n% 1. The development of the interpolation across 0 and 1 is often\n% numerically better than explicitly making the polynomial for\n% values from xSpan(1) to xSpan(2).\n% E The maximum error of the interpolating polynomial.\n% exitVal A value indicating how the algorithm terminated. Possible\n% values are:\n% 0: The tolerance goal was met.\n% 1: the maximum number of iterations was met.\n%\n%The algorithm used to fit a polynomial to an arbitrary nonlinear function\n%is Remez algorithm. This is described ine Remez algorithm is well known\n%and is described in Chapter 6 of [1].\n%\n%To initalize the Remez algorithm, one must choose a set of points in the\n%region to be interpolated. One might be tempted to unifromely space the\n%points, but as noted in [2] and Chaper 8.3 of [3], that can be a very bad\n%idea. Rather, the use of Chebychev nodes is better and has much better\n%asymptotic properties as the number of nodes increases. \n%\n%Given a set of points in xSpan, the algorithm find an interpolating\n%polynomial that mades the magnitude of the error at all of the points the\n%same and the sign of the error alternate. This is because there is a\n%theorem that such an alternating equierror solution is a minimax solution.\n%However, only a minimax solution for the initial set of points is given.\n%Thus, the algorithm tries to move the points to maximize the error.\n%\n%Since the sign of the error between any two points flips, there is at\n%least one zero between the points. This algorithm assumes that there is\n%exactly one zero between the points, which should be reasonable if n is\n%chosen to be large enough. In such an instance, the true error maxima of\n%the function are between the zeros (and the outer bounds) of the function.\n%Thus, the points can be moved there. Basically by maximizing the error at\n%the chosen points, and getting an interpolating polynomial with equal\n%error at the points, one finds the minimax approximation.\n%\n%As an example, consider interpolating the exponential function between 0\n%and 2 with a sixth-order polynomial:\n% f=@(x)exp(x);\n% xSpan=[0;2];\n% n=6;\n% [c,E]=minimaxPolyFit(f,xSpan,n)\n% %The maximum error E should be about 8.7e-6.\n% %The resulting interpolating polynomial can be plotted as a fraction of\n% %the distance between the points in xSpan. We will plot the error.\n% numPoints=500;\n% x=linspace(xSpan(1),xSpan(2),numPoints);\n% xFrac=(x-xSpan(1))/(xSpan(2)-xSpan(1));\n% error=polyval(c,xFrac)-exp(x);\n% plot(x,error)\n%\n%REFERENCES:\n%[1] V. K. Dzyadyk and I. A. Shevchuk, Theory of Uniform Approximation\n% of Functions by Polynomials, 1st ed. Berlin: Walter de Gruyter, 2008.\n%[2] R. B. Platte, L. N. Trefethen, and A. B. Kuijlaars, \"Impossibility of\n% fast stable approximation of analytic functions from equispaced\n% samples,\" SIAM Review, vol. 53, no. 2, pp. 308-318, 2011.\n%[3] R. L. Burden and J. D. Faires, Numerical Analysis, 9th ed. Australia:\n% Brooks/ Cole, 2011.\n%\n%July 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<5||isempty(maxIter))\n maxIter=50; \nend\n\nif(nargin<4||isempty(RelTol))\n RelTol=1e-12; \nend\n\nif(nargin<3||isempty(n))\n n=5;\nend\n\nif(nargin<2||isempty(xSpan))\n xSpan=[-1;1];\nend\n\n%Step 1: Choose an initial set of nodes for interpolation. \n%n+2 nodes are needed for an order-n polynomial approximation. The initial\n%guess is set to the roots of the Chebyshev polynomial of the first kind.\n%Such a choice is standard in most implementations of the Remez algorithm,\n%because the Chebyshev polynomials distribute more nodes to the outside of\n%the interval then to the center, reducing Runge's phenomenon. \nk=(n+2):-1:1;\n%The Chebyshev nodes for the (-1,1) span.\nxNodes=cos((2*k(:)-1)/(2*(n+2))*pi);\n%We are reducing the span of the nodes from -1/2 to 1/2 so that the\n%interpolating polynomial on the output of the function takes an input from\n%0 to 1.\nxNodes=xNodes/2;\n\ncurIter=1;\nEPrev=Inf;%This is used to determine convergence of the error estimate E.\nwhile(1)\n %Step 2: Solve for the maximum error E and the coefficients of the\n % interpolating polynomial P given the current set of nodes.\n % This involves solving a linear system of equations.\n\n %Allocate space for the matrix.\n hMat=zeros(n+2,n+2);\n\n xDelta=(xNodes+1/2);\n hMat(:,1)=1;%The zeroth-order terms.\n for curCol=2:(n+1)\n hMat(:,curCol)=hMat(:,curCol-1).*xDelta;%This is xDelta.^(curCol-1)\n end\n\n %The last column corresponds to the E error term. This last column is\n %why the matrix is not a Vandermonde matrix.\n hMat(:,n+2)=(-1).^(0:(n+1));\n\n %Map the (-1,1) Chebyshev nodes into the range given by xSpan.\n xFNodes=(xSpan(2)-xSpan(1))*(xNodes+1/2)+xSpan(1);\n \n %Solve the system for the polynomial coefficients c and the error E\n coeffs=hMat\\f(xFNodes);\n\n %The flipud is to make the ordering the same as that used by the\n %polyval function.\n c=flipud(coeffs(1:(n+1)));\n E=coeffs(n+2);\n \n relTolVal=abs(E-EPrev)/abs(E);\n \n %Check for convergence. Convergence is determined is the E value stops\n %changing significantly.\n %The check for the relative tolerance value being a nan deals with the\n %case where E=0 and E-EPrev=0.\n if(isnan(relTolVal)||relTolVal.\n%\n\ncheck3Color(img);\n\nimgOut = img;\n\nif(inverse == 0)%ICh color space\n imgOut(:,:,2) = sqrt(img(:,:,2).^2 + img(:,:,3).^2);\n imgOut(:,:,3) = atan2(img(:,:,2), img(:,:,3));\nelse\n imgOut(:,:,2) = sin(img(:,:,3)) .* img(:,:,2);\n imgOut(:,:,3) = cos(img(:,:,3)) .* img(:,:,2);\nend\n \nend\n", "meta": {"author": "banterle", "repo": "HDR_Toolbox", "sha": "a2b45dc48b7169192fb633097a83879e71a0c0f2", "save_path": "github-repos/MATLAB/banterle-HDR_Toolbox", "path": "github-repos/MATLAB/banterle-HDR_Toolbox/HDR_Toolbox-a2b45dc48b7169192fb633097a83879e71a0c0f2/source_code/ColorSpace/ConvertIPTtoICh.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778073288127, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.8058610097541399}} {"text": "function cdf = birthday_cdf ( n )\n\n%*****************************************************************************80\n%\n%% BIRTHDAY_CDF returns the Birthday Concurrence CDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 26 August 2006\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of people whose birthdays have been\n% disclosed.\n%\n% Output, real CDF, the probability that at least\n% two of the N people have matching birthays.\n%\n if ( n < 1 )\n cdf = 0.0;\n return\n elseif ( 365 < n )\n cdf = 1.0;\n return\n end\n%\n% Compute the probability that N people have distinct birthdays.\n%\n cdf = 1.0;\n for i = 1 : n\n cdf = cdf * ( 365 + 1 - i ) / 365.0;\n end\n%\n% Compute the probability that it is NOT the case that N people\n% have distinct birthdays. This is the cumulative probability\n% that person 2 matches person 1, or person 3 matches 1 or 2, \n% etc.\n%\n cdf = 1.0 - cdf;\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/birthday_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.929440403812707, "lm_q2_score": 0.8670357735451834, "lm_q1q2_score": 0.805858079483898}} {"text": "function p = predict(Theta1, Theta2, X)\n%PREDICT Predict the label of an input given a trained neural network\n% p = PREDICT(Theta1, Theta2, X) outputs the predicted label of X given the\n% trained weights of a neural network (Theta1, Theta2)\n\n% Useful values\nm = size(X, 1);\nnum_labels = size(Theta2, 1);\n\n% You need to return the following variables correctly \np = zeros(size(X, 1), 1);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Complete the following code to make predictions using\n% your learned neural network. You should set p to a \n% vector containing labels between 1 to num_labels.\n%\n% Hint: The max function might come in useful. In particular, the max\n% function can also return the index of the max element, for more\n% information see 'help max'. If your examples are in rows, then, you\n% can use max(A, [], 2) to obtain the max for each row.\n%\n\n\na1 = [ones(m,1) X];\nz2 = a1 *Theta1';\na2 = [ones(size(z2),1) sigmoid(z2)];\nz3 = a2*Theta2';\na3 = sigmoid(z3);\n\n[predict_max, index_max] = max(a3, [], 2);\n\np = index_max;\n\n\n\n\n% =========================================================================\n\n\nend\n", "meta": {"author": "schneems", "repo": "Octave", "sha": "411e8794574abb3fb042e178bf95861dfcee3b04", "save_path": "github-repos/MATLAB/schneems-Octave", "path": "github-repos/MATLAB/schneems-Octave/Octave-411e8794574abb3fb042e178bf95861dfcee3b04/mlclass-ex3/mlclass-ex3/predict.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404038127071, "lm_q2_score": 0.8670357460591569, "lm_q1q2_score": 0.8058580539372745}} {"text": "function theta = polygonNormalAngle(points, ind)\n%POLYGONNORMALANGLE Compute the normal angle at a vertex of the polygon\n%\n% THETA = polygonNormalAngle(POLYGON, IND);\n% where POLYGON is a set of points, and IND is index of a point in\n% polygon. The function compute the angle of the normal cone localized at\n% this vertex.\n% If IND is a vector of indices, normal angle is computed for each vertex\n% specified by IND.\n%\n% Example\n% % creates a simple polygon\n% poly = [0 0;0 1;-1 1;0 -1;1 0];\n% % compute normal angle at each vertex\n% theta = polygonNormalAngle(poly, 1:size(poly, 1));\n% % sum of all normal angle of a non-intersecting polygon equals 2xpi\n% % (can be -2xpi if polygon is oriented clockwise)\n% sum(theta)\n%\n% See also:\n% polygons2d, polygonOuterNormal, normalizeAngle\n%\n\n% ------\n% Author: David Legland\n% e-mail: david.legland@inra.fr\n% Created: 2005-11-30\n% Copyright 2005 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas).\n\n\n% number of points\nnp = size(points, 1);\n\n% number of angles to compute\nnv = length(ind);\n\ntheta = zeros(nv, 1);\n\nfor i = 1:nv\n % current vertex\n curr = points(ind(i), :);\n \n % previous and next vertices\n prev = points(mod(ind(i)-2, np)+1, :);\n next = points(mod(ind(i), np)+1, :);\n \n theta(i) = angle3Points(prev, curr, next) - pi;\nend\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/polygons2d/polygonNormalAngle.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900945711678, "lm_q2_score": 0.880797081106935, "lm_q1q2_score": 0.8058420824848204}} {"text": "function y = logn_lpdf(x,mu,sigma)\n%LOGNPDF Lognormal log-probability density function (lpdf).\n%\n% Y = LOGN_LPDF(X,MU,SIGMA) Returns the log of the lognormal pdf at\n% the values in X. The mean and standard deviation of log(Y) are\n% MU and SIGMA.\n%\n% The size of Y is the common size of the input arguments. A scalar input \n% functions as a constant matrix of the same size as the other inputs. \n%\n% Default values for MU and SIGMA are 0 and 1 respectively.\n\n% Copyright (c) 2000 Aki Vehtari\n\n% This software is distributed under the GNU General Public \n% License (version 3 or later); please refer to the file \n% License.txt, included with the software, for details.\n\ny = -0.5 * ((log(x) - mu)./sigma).^2 - log(x .* sqrt(2*pi) .* sigma);\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/dmlt/external/gpstuff/dist/logn_lpdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465098415278, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.8058367522985309}} {"text": "% Copyright (C) 2016, by Arturo Gil Aparicio\n%\n% This file is part of ARTE (A Robotics Toolbox for Education).\n% \n% ARTE 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% ARTE 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 ARTE. If not, see .\nfunction jacobian_symbolic_w\nL3 = 0.38;\n\nsyms q1 q2\n\nA01 = dh_sym(q1, L3, 0, pi/2);\nA12 = dh_sym(q2, 0, 0, -pi/2);\nA02 = A01*A12;\n\nz0 = [0 0 1]';\nz1 = A01(1:3,3);\nz2 = A02(1:3,3);\n\nJw = [z0 z1 z2];\n\nsingularities = det(Jw)\nsingularities = simplify(singularities)\nq=solve(singularities == 0)\n\n\n\nfunction A = dh_sym(theta, d, a, alpha)\nsyms q1 q2\nca = cos(alpha);\nsa = sin(alpha);\nif abs(ca) < 1e-6\n ca = 0;\nend\nif abs(sa) < 1e-6\n sa = 0;\nend\n\n\nA=[cos(theta) -ca*sin(theta) sa*sin(theta) a*cos(theta);\n sin(theta) ca*cos(theta) -sa*cos(theta) a*sin(theta);\n 0 sa ca d;\n 0 0 0 1];\n", "meta": {"author": "4rtur1t0", "repo": "ARTE", "sha": "6e836f3156bb36af63b70bd93375c8ff4ee643c4", "save_path": "github-repos/MATLAB/4rtur1t0-ARTE", "path": "github-repos/MATLAB/4rtur1t0-ARTE/ARTE-6e836f3156bb36af63b70bd93375c8ff4ee643c4/exercises/book/jacobian_symbolic_spherical_w.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370313, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.8058367508557553}} {"text": "function [ valLoss ] = HuberLoss( vX, paramDelta )\n% ----------------------------------------------------------------------------------------------- %\n% [ valLoss ] = HuberLoss( vX, paramDelta )\n% Applies the Huber Loss to the input vector.\n% Input:\n% - vY - Input Vector.\n% Structure: Vector (Column).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - ballRadius - Ball Radius.\n% Sets the Radius of the L1 Ball. For Unit L1 Ball\n% set to 1.\n% Structure: Scalar.\n% Type: 'Single' / 'Double'.\n% Range: (0, inf).\n% Output:\n% - vX - Output Vector.\n% The projection of the Input Vector onto the L1\n% Ball.\n% Structure: Vector (Column).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% References\n% 1. Huber Loss (Wikipedia) - https://en.wikipedia.org/wiki/Huber_loss.\n% Remarks:\n% 1. a\n% TODO:\n% 1. U.\n% Release Notes:\n% - 1.0.000 21/03/2020 Royi Avital\n% * First release version.\n% ----------------------------------------------------------------------------------------------- %\n\nFALSE = 0;\nTRUE = 1;\n\nOFF = 0;\nON = 1;\n\nnumElements = length(vX);\n\nvalLoss = 0;\n\nfor ii = 1:numElements\n if(abs(vX(ii)) <= paramDelta)\n valLoss = valLoss + (0.5 * vX(ii) * vX(ii));\n else\n valLoss = valLoss + (paramDelta * (abs(vX(ii)) - (0.5 * paramDelta)));\n end\n \nend\n\n\nend\n\n", "meta": {"author": "RoyiAvital", "repo": "StackExchangeCodes", "sha": "d2a934616995fa8a9f4df1ca29029402435b9e6f", "save_path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes", "path": "github-repos/MATLAB/RoyiAvital-StackExchangeCodes/StackExchangeCodes-d2a934616995fa8a9f4df1ca29029402435b9e6f/Mathematics/Q2791227/HuberLoss.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012640659995, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.805778042359019}} {"text": "function v=mai(x,lag)\n%Syntax: v=mai(x,lag)\n%____________________\n%\n% Calculates the mutual average information of a time series x for\n% some time lag.\n%\n% v is the the value of the mutual average information.\n% x is the time series.\n% lag is the time lag.\n%\n% Alexandros Leontitsis\n% Institute of Mathematics and Statistics\n% University of Kent at Canterbury\n% Canterbury\n% Kent, CT2 7NF\n% U.K.\n% University e-mail: al10@ukc.ac.uk\n% Lifetime e-mail: leoaleq@yahoo.com\n% Homepage: http://www.geocities.com/CapeCanaveral/Lab/1421\n%\n% May 25, 2001.\n\nif nargin<1 | isempty(x)==1\n error('You should provide a time series.');\nelse\n % x must be a vector\n if min(size(x))>1\n error('Invalid time series.');\n end\n x=x(:);\n % n is the time series length\n n=length(x);\nend\n\nif nargin<2 | isempty(lag)==1\n lag=0:min(n/2-1,20);\nelse\n % lag must be a vector\n if min(size(lag))>1\n error('The time lag must be a scalar or a vector.');\n end\n % lag must contain integers\n lag=round(lag);\n % lag values must be between 0 and n/2-1\n lag=lag(find(lag>=0 & lag0\n ppp=ppp/(n-lag(i));\n px1=length(px1)/(n-lag(i));\n px2=length(px2)/(n-lag(i));\n v(i)=v(i)+ppp*log2(ppp/px1/px2);\n end\n end\n end\n end\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/880-mutual-average-information/mai.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167044, "lm_q2_score": 0.868826784729373, "lm_q1q2_score": 0.8057180634560821}} {"text": "function mu = trapezmf(z,a,b,c,d)\n%TRAPEZMF Trapezoidal membership function.\n% MU = TRAPEZMF(Z,A,B,C,D) computes a fuzzy membership function with a\n% trapezoidal shape. Z is the input variable and can be a vector of\n% any length. A, B, C, and D are scalar parameters that define the\n% trapezoidal shape. The parameters must be ordered so that A <= B, B\n% <= C, and C <= D.\n%\n% MU = 0 Z < A\n% MU = (Z - A) ./ (B - A) A <= Z < B\n% MU = 1 B <= Z < C\n% MU = 1 - (Z - C) ./ (D - C) C <= Z < D\n% MU = 0 D <= Z\n%\n% Copyright 2002-2020 Gatesmark\n%\n% This function, and other functions in the DIPUM Toolbox, are based \n% on the theoretical and practical foundations established in the \n% book Digital Image Processing Using MATLAB, 3rd ed., Gatesmark \n% Press, 2020.\n%\n% Book website: http://www.imageprocessingplace.com\n% License: https://github.com/dipum/dipum-toolbox/blob/master/LICENSE.txt\n\nmu = zeros(size(z));\n\nup_ramp_region = (a <= z) & (z < b);\ntop_region = (b <= z) & (z < c);\ndown_ramp_region = (c <= z) & (z < d);\n\nmu(up_ramp_region) = 1 - (b - z(up_ramp_region))./(b - a);\nmu(top_region) = 1;\nmu(down_ramp_region) = 1 - (z(down_ramp_region) - c)./(d - c);\n\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/fuzzyFunctions/trapezmf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.8688267660487572, "lm_q1q2_score": 0.8057180565973977}} {"text": "function [rho pval] = circ_corrcl(alpha, x)\n%\n% [rho pval ts] = circ_corrcc(alpha, x)\n% Correlation coefficient between one circular and one linear random\n% variable.\n%\n% Input:\n% alpha sample of angles in radians\n% x sample of linear random variable\n%\n% Output:\n% rho correlation coefficient\n% pval p-value\n%\n% References:\n% Biostatistical Analysis, J. H. Zar, p. 651\n%\n% PHB 6/7/2008\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\n\nif size(alpha,2) > size(alpha,1)\n\talpha = alpha';\nend\n\nif size(x,2) > size(x,1)\n\tx = x';\nend\n\nif length(alpha)~=length(x)\n error('Input dimensions do not match.')\nend\n\nn = length(alpha);\n\n% compute correlation coefficent for sin and cos independently\nrxs = corr(x,sin(alpha));\nrxc = corr(x,cos(alpha));\nrcs = corr(sin(alpha),cos(alpha));\n\n% compute angular-linear correlation (equ. 27.47)\nrho = sqrt((rxc^2 + rxs^2 - 2*rxc*rxs*rcs)/(1-rcs^2));\n\n% compute pvalue\npval = 1 - chi2cdf(n*rho^2,2);\n\n", "meta": {"author": "kavli-ntnu", "repo": "MINI2P_toolbox", "sha": "83311a49baea69ecf027e19390e608fd4eaeae8d", "save_path": "github-repos/MATLAB/kavli-ntnu-MINI2P_toolbox", "path": "github-repos/MATLAB/kavli-ntnu-MINI2P_toolbox/MINI2P_toolbox-83311a49baea69ecf027e19390e608fd4eaeae8d/Analysis/+CircStat2012a/circ_corrcl.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107861416414, "lm_q2_score": 0.8596637577007393, "lm_q1q2_score": 0.8056861461721875}} {"text": "function u=EOBurg(u,t,dx,dir,bndcond)\n%%\n% Solves Burgers' equation u_t + 0.5*u^2_x = 0 by the Engquist-Osher method.\n%\n\n%%\n% Initial setup\nif nargin<5,\n bndcond='Neumann';\nend;\nif nargin<4,\n dir=1;\nend;\nif (dir>2),\n error(strcat('You can easily extend this to',num2str(dir)','D yourself ...'));\nend;\n% Some things ensuring that you solve along the columns of u. Must\n% transpose if u is a row vector or if dir = 2.\ntranspose=0;\nS=size(u);\nN=S(1);\nif ((N==1)||(dir==2)),\n u=u';\n transpose=1;\nend;\nmaxspeed=max(max(abs(u)));\nCFL=0.95;\ndt=CFL*dx/maxspeed; \nnstep=ceil(t/dt);\ndt=t/nstep;\nlambda=dt/dx;\n%%\n% Solving by EO metod\nfor j=1:nstep,\n uext=set_extend('iden',u,bndcond);\n u=u-lambda*diff(eoflux(uext));\nend;\nif (transpose)\n u=u';\nend;\n\n%% eoflux\nfunction f=eoflux(u)\n S=size(u);\n N=S(1);\n MM=max(u(1:N-1,:),0.0); mm=min(u(2:N,:),0.0);\n f=0.5*(MM.^2+mm.^2);\n \n \n \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/OperatorSplitting/Chapter4/EOBurg.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107861416413, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.8056861411177001}} {"text": "function [ i, j ] = i4_to_pascal ( k )\n\n%*****************************************************************************80\n%\n%% I4_TO_PASCAL converts a linear index to Pascal triangle coordinates.\n%\n% Location:\n%\n% http://people.sc.fsu.edu/~jburkardt/m_src/triangle_integrals/i4_to_pascal.m\n%\n% Discussion:\n%\n% We describe the grid points in Pascal's triangle in two ways:\n%\n% As a linear index K:\n%\n% 1\n% 2 3\n% 4 5 6\n% 7 8 9 10\n%\n% As elements (I,J) of Pascal's triangle:\n%\n% 0,0\n% 1,0 0,1\n% 2,0 1,1 0,2\n% 3,0 2,1 1,2 0,3\n%\n% Example:\n%\n% K I J\n%\n% 1 0 0\n% 2 1 0\n% 3 0 1\n% 4 2 0\n% 5 1 1\n% 6 0 2\n% 7 3 0\n% 8 2 1\n% 9 1 2\n% 10 0 3\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 April 2015\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer K, the linear index of the (I,J) element.\n% 1 <= K.\n%\n% Output, integer I, J, the Pascal indices.\n%\n if ( k <= 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'I4_TO_PASCAL - Fatal error!\\n' );\n fprintf ( 1, ' K must be positive.\\n' );\n error ( 'I4_TO_PASCAL - Fatal error!' );\n end\n\n d = i4_to_pascal_degree ( k );\n\n j = k - ( d * ( d + 1 ) ) / 2 - 1;\n i = d - j;\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/triangle_integrals/i4_to_pascal.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110483133801, "lm_q2_score": 0.903294209307224, "lm_q1q2_score": 0.8055677557376812}} {"text": "function value = not1d ( x1, x2, x3 )\n\n%*****************************************************************************80\n%\n%% NOT1D differentiates a factor for serendipity basis functions.\n%\n% Discussion:\n%\n% not1(x1,x2,x3) evaluates at the point x1, the basis factor that\n% is 0 at x2 and 1 at x3:\n%\n% not1(x1,x2,x3) = ( x1 - x2 ) / ( x3 - x2 ) \n%\n% This function returns the derivative of the factor with respect to x1:\n%\n% not1d(x1,x2,x3) = 1 / ( x3 - x2 );\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 June 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X1, the evaluation point.\n%\n% Input, real X2, X3, values that define the factor.\n%\n% Output, real VALUE, the derivative of the basis function factor.\n%\n value = 1.0 / ( x3 - x2 );\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_bvp_serene/not1d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629194, "lm_q2_score": 0.8539127548105612, "lm_q1q2_score": 0.8055365316893166}} {"text": "function V_times = crossTimesMatrix(V)\n% CROSSTIMESMATRIX\n% V_TIMES = CROSSTIMESMATRIX(V) returns a 3x3 (or a series of 3x3) cross times matrices of input vector(s) V\n% \n% Input:\n% V a 3xN matrix, rpresenting a series of 3x1 vectors\n% \n% Output: \n% V_TIMES (Vx) a series of 3x3 matrices where V_times(:,:,i) is the Vx matrix for the vector V(:,i)\n% \n% \tBabak Taati, 2003\n% (revised 2009)\n\n[a,b] = size(V);\nV_times = zeros(a, 3, b);\n\n% V_times(1,1,:) = 0;\nV_times(1,2,:) = - V(3,:);\nV_times(1,3,:) = V(2,:);\n\nV_times(2,1,:) = V(3,:);\n% V_times(2,2,:) = 0;\nV_times(2,3,:) = - V(1,:);\n\nV_times(3,1,:) = - V(2,:);\nV_times(3,2,:) = V(1,:);\n% V_times(3,3,:) = 0;\n", "meta": {"author": "jianxiongxiao", "repo": "ProfXkit", "sha": "7376c50abf5ead846247774a36be026e6f24953c", "save_path": "github-repos/MATLAB/jianxiongxiao-ProfXkit", "path": "github-repos/MATLAB/jianxiongxiao-ProfXkit/ProfXkit-7376c50abf5ead846247774a36be026e6f24953c/align2RGBD/align2RGBD/lib/estimateRigidTransform/crossTimesMatrix.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.8705972768020108, "lm_q1q2_score": 0.805502684649807}} {"text": "%normu Normalize image points to be used for LS estimation.\n% A = normu(u) finds normalization matrix A so that mean(A*u)=0 and\n% mean(||A*u||)=sqrt(2). (see Hartley: In Defence of 8-point Algorithm,\n% ICCV`95).\n%\n% Parameters:\n% u ... Size (2,N) or (3,N). Points to normalize.\n% A ... Size (3,3). Normalization matrix.\n\nfunction A = normu(u)\n\nif size(u,1)==3, u = p2e(u); end\n\nm = mean(u')'; % <=> mean (u,2)\nu = u - m*ones(1,size(u,2));\ndistu = sqrt(sum(u.*u));\nr = mean(distu)/sqrt(2);\nif ~r, A = []; return; end % one of degenarate configurations\nA = diag([1/r 1/r 1]);\nA(1:2,3) = -m/r;\n", "meta": {"author": "strawlab", "repo": "MultiCamSelfCal", "sha": "0a26c88c63d8513eab76553033a9a6fb15ba6575", "save_path": "github-repos/MATLAB/strawlab-MultiCamSelfCal", "path": "github-repos/MATLAB/strawlab-MultiCamSelfCal/MultiCamSelfCal-0a26c88c63d8513eab76553033a9a6fb15ba6575/MultiCamSelfCal/MartinecPajdla/fill_mm/normu.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248242542283, "lm_q2_score": 0.8577681122619883, "lm_q1q2_score": 0.8054655508676948}} {"text": "% 预测世界石油产量\n%% 历史数据\nclear;clc;\nx = (1994 : 2003)'; % 年份\nyear = 1990;\nx = x - year;\ny = [67.052, 68.008, 69.803, 72.024, 73.400, 72.063, 74.669, 74.487, 74.065, 76.777]'; % 百万桶每日\nplot(x,y,'rp');\n%% 直线拟合\nC = [x.^0, x.^1];\nA = C' * C; % 法方程系数矩阵\nb = C' * y; % 法方程向量\np_1 = A \\ b % 一次多项式系数,升幂排列\nRMSE_1 = sqrt(sum((y - C * p_1).^2)) / sqrt(length(C))\n%% 抛物线拟合\nC = [x.^0, x.^1, x.^2];\nA = C' * C; % 法方程系数矩阵\nb = C' * y; % 法方程向量\np_2 = A \\ b % 二次多项式系数,升幂排列\nRMSE_2 = sqrt(sum((y - C * p_2).^2)) / sqrt(length(C))\n%% 三次曲线拟合\nC = [x.^0, x.^1, x.^2, x.^3];\nA = C' * C; % 法方程系数矩阵\nb = C' * y; % 法方程向量\np_3 = A \\ b % 三次多项式系数,升幂排列\nRMSE_3 = sqrt(sum((y - C * p_3).^2)) / sqrt(length(C))\n%% 开始预测\nx1=x(end) + (1:5)'; % 待预测时间, 10年\nxi=[x;x1];\np = p_1; % 指定模型\nplot(x + year,y,'*',xi + year,polyval(flip(p),xi),x1 + year,polyval(flip(p),x1),'rp');\n% 结论:预测结果仅供参考", "meta": {"author": "qxr777", "repo": "NumericalAnalysis", "sha": "145e47521459defdcfd6a929702651abe29ba6de", "save_path": "github-repos/MATLAB/qxr777-NumericalAnalysis", "path": "github-repos/MATLAB/qxr777-NumericalAnalysis/NumericalAnalysis-145e47521459defdcfd6a929702651abe29ba6de/第二章 插值方法/application_2_5.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542794197472, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.8054344267434537}} {"text": "function [ pn, dist ] = circle_arc_point_near_2d ( r, center, theta1, ...\n theta2, p )\n\n%*****************************************************************************80\n%\n%% CIRCLE_ARC_POINT_NEAR_2D : nearest point on a circular arc.\n%\n% Discussion:\n%\n% A circular arc is defined by the portion of a circle (R,C)\n% between two angles (THETA1,THETA2).\n%\n% Thus, a point (X,Y) on a circular arc satisfies\n%\n% ( X - C(1) ) * ( X - C(1) ) + ( Y - C(2) ) * ( Y - C(2) ) = R * R\n%\n% and\n%\n% Theta1 <= Theta <= Theta2\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 THETA1, THETA2, the angles defining the arc,\n% in radians. Normally, THETA1 < THETA2.\n%\n% Input, real P(2), the point to be checked.\n%\n% Output, real PN(2), a point on the circular arc which is\n% nearest to the point.\n%\n% Output, real DIST, the distance to the nearest point.\n%\n ndim = 2;\n%\n% Special case, the zero circle.\n%\n if ( r == 0.0 )\n pn(1:ndim) = center(1:ndim);\n dist = sqrt ( sum ( ( p(1:ndim) - pn(1:ndim) ).^2 ) );\n return\n end\n%\n% Determine the angle made by the point.\n%\n theta = atan4 ( p(2) - center(2), p(1) - center(1) );\n%\n% If the angle is between THETA1 and THETA2, then you can\n% simply project the point onto the arc.\n%\n if ( r8_modp ( theta - theta1, 2.0 * pi ) <= ...\n r8_modp ( theta2 - theta1, 2.0 * pi ) ) \n\n r2 = sqrt ( sum ( ( p(1:ndim) - center(1:ndim) ).^2 ) );\n\n pn(1:ndim) = center(1:ndim) + ( p(1:ndim) - center(1:ndim) ) * r / r2;\n%\n% Otherwise, if the angle is less than the negative of the\n% average of THETA1 and THETA2, it's on the side of the arc\n% where the endpoint associated with THETA2 is closest.\n%\n% As usual, MATLAB has some ninny problem with using cosine in a vector.\n% So I have to write the assignment as two scalar assignments.\n%\n elseif ( r8_modp ( theta - 0.5 * ( theta1 + theta2 ), 2.0 * pi ) <= pi )\n\n pn(1) = center(1) + r * cos ( theta2 );\n pn(2) = center(2) + r * sin ( theta2 );\n%\n% Otherwise, the endpoint associated with THETA1 is closest.\n%\n else\n\n pn(1) = center(1) + r * cos ( theta1 );\n pn(2) = center(2) + r * sin ( theta1 );\n \n end\n\n dist = sqrt ( sum ( ( p(1:ndim) - pn(1:ndim) ).^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_triangulation/circle_arc_point_near_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642528975397, "lm_q2_score": 0.8757869965109764, "lm_q1q2_score": 0.8054109683151215}} {"text": "% Spectral factorization using Kolmogorov 1939 approach.\n% (code follows pp. 232-233, Signal Analysis, by A. Papoulis)\n%\n% Computes the minimum-phase impulse response which satisfies\n% given auto-correlation.\n%\n% Input:\n% r: top-half of the auto-correlation coefficients\n% starts from 0th element to end of the auto-corelation\n% should be passed in as a column vector\n% Output\n% h: impulse response that gives the desired auto-correlation\n\nfunction h = spectral_fact(r)\n\n% length of the impulse response sequence\nn = length(r);\n\n% over-sampling factor\nmult_factor = 100; % should have mult_factor*(n) >> n \nm = mult_factor*n;\n\n% computation method:\n% H(exp(jTw)) = alpha(w) + j*phi(w)\n% where alpha(w) = 1/2*ln(R(w)) and phi(w) = Hilbert_trans(alpha(w))\n\n% compute 1/2*ln(R(w))\nw = 2*pi*((0:m-1)/m);\nR = [ ones(m,1) 2*cos(kron(w',1:n-1)) ]*r;\nalpha = 1/2*log(R);\n\n% find the Hilbert transform \nalphatmp = fft(alpha);\nalphatmp(floor(m/2)+1:m) = -alphatmp(floor(m/2)+1:m);\nalphatmp(1) = 0;\nalphatmp(floor(m/2)+1) = 0;\nphi = real(ifft(1j*alphatmp));\n\n% now retrieve the original sampling \nindex = find(rem(0:m-1,mult_factor)==0);\nalpha1 = alpha(index);\nphi1 = phi(index);\n\n% compute the impulse response (inverse Fourier transform)\nh = real(ifft(exp(alpha1+1j*phi1),n));\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/filter_design/spectral_fact.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342012360933, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.8053192113329286}} {"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 temp = P.*log(P./repmat(Q,[size(P,1) 1]));\n temp(isnan(temp))=0;% resolving the case when P(i)==0\n dist = sum(temp,2);\n \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 temp = P.*log(P./Q);\n temp(isnan(temp))=0; % resolving the case when P(i)==0\n dist = sum(temp,2);\nend\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/20688-kullback-leibler-divergence/KLDiv.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.947381048137938, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.805246585081721}} {"text": "function rgb = hsi2rgb(hsi)\n%HSI2RGB Converts an HSI image to RGB.\n% RGB = HSI2RGB(HSI) converts an HSI image to RGB, where HSI is\n% assumed to be of class double with:\n% HSI(:,:,1) = hue image, assumed to be in the range [0,1] by\n% having been divided by 2*pi. \n% HSI(:,:,2) = saturation image, in the range [0,1]. \n% HSI(:,:,3) = intensity image, in the range [0,1].\n%\n% The components of the output image are:\n% RGB(:,:,1) = red.\n% RGB(:,:,2) = green.\n% RGB(:,:,3) = blue.\n%\n% All the conversion equations are explained in Chapter 7 of DIPUM3E.\n%\n% Copyright 2002-2020 Gatesmark\n%\n% This function, and other functions in the DIPUM Toolbox, are based \n% on the theoretical and practical foundations established in the \n% book Digital Image Processing Using MATLAB, 3rd ed., Gatesmark \n% Press, 2020.\n%\n% Book website: http://www.imageprocessingplace.com\n% License: https://github.com/dipum/dipum-toolbox/blob/master/LICENSE.txt\n\n% Extract the individual HSI component images.\nH = hsi(:,:,1) * 2 * pi;\nS = hsi(:,:,2);\nI = hsi(:,:,3);\n\n% Implement the conversion equations.\nR = zeros(size(hsi,1),size(hsi,2));\nG = zeros(size(hsi,1),size(hsi,2));\nB = zeros(size(hsi,1),size(hsi,2));\n\n% RG sector (0 <= H < 2*pi/3).\nidx = find( (0 <= H) & (H < 2*pi/3));\nB(idx) = I(idx).*(1 - S(idx));\nR(idx) = I(idx).*(1 + S(idx).*cos(H(idx))./...\n cos(pi/3 - H(idx)));\nG(idx) = 3*I(idx) - (R(idx) + B(idx));\n\n% BG sector (2*pi/3 <= H < 4*pi/3).\nidx = find( (2*pi/3 <= H) & (H < 4*pi/3) );\nR(idx) = I(idx).*(1 - S(idx));\nG(idx) = I(idx).*(1 + S(idx).*cos(H(idx) - 2*pi/3)./...\n cos(pi - H(idx)));\nB(idx) = 3*I(idx) - (R(idx) + G(idx));\n\n% BR sector.\nidx = find( (4*pi/3 <= H) & (H <= 2*pi));\nG(idx) = I(idx).*(1 - S(idx));\nB(idx) = I(idx).*(1 + S(idx).*cos(H(idx) - 4*pi/3)./...\n cos(5*pi/3 - H(idx)));\nR(idx) = 3*I(idx) - (G(idx) + B(idx));\n\n% Combine all three results into an RGB image. Clip to [0,1] to\n% compensate for floating-point arithmetic rounding effects.\nrgb = cat(3,R,G,B);\nrgb = max(min(rgb,1),0);\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/hsi2rgb.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.8824278556326343, "lm_q1q2_score": 0.8051590760867499}} {"text": "function ImgOut = fftsf(ImgIn,degree)\n% FFTSF Frequency domain auto filtering (enhances powerfull frequencies)\n%\n% Input :\tImgIn - grayscale image\n% degree - emphasis given to regular patterns\n% values: 1, 2, 3, {4} (default)\n% \n% Filtering | soft strong\n% ------------------------------\n% emphasis | 1 2\n% attenuation | 3 4\n%\n% Output: class double data\n% Display:\n% \n% im = imread('kb818c.jpg');\n% figure\n% subplot(2,3,2)\n% imshow(im,[])\n% title('Input')\n% subplot(2,3,3)\n% imshow(fftsf(im,1),[])\n% title('1. Soft emphazis')\n% subplot(2,3,6)\n% imshow(fftsf(im,2),[])\n% title('2. Strong emphazis')\n% subplot(2,3,5)\n% title([{'Self-filtering'},{'emphasizes or attenuates'},{'regular patterns'}])\n% axis off\n% subplot(2,3,1)\n% imshow(fftsf(im,3),[])\n% title('3. Soft attenuation')\n% subplot(2,3,4)\n% imshow(fftsf(im,4),[])\n% title('4. Strong attenuation')\n%\n% Proceedure: The most powerfull frequencies in an image are enhanced /\n% attenuated by multiplying / dividing the complex FFT signal with the \n% magnitude of the same FFT.\n%\n% Reference: This code is based on the technique described in:\n% D.G. Bailey - Detecting regular patterns using frequency domain\n% self-filtering, 1997 Intl. Conf. on Image Processing, 1:440-3.\n%\n% Written by Vlad Atanasiu 2003.09.25\n% 2008.11.07 - modified sample code\n% 2007.07.07 - added new magnitude enhancement options\n% - removed bug in 'switch'\n% - changed name from 'fftselffilter' to 'fftsf' (is shorter)\n\nF = fft2(double(ImgIn));\t% FFT\nR = abs(F); % magnitude\nZ = angle(F); % phase\nswitch degree % filtering\ncase(2)\n F2 = F.*R.*sqrt(R.^2+Z.^2);\ncase(3)\n R = R + eps;\n F2 = sqrt(R).*exp(i*Z);\ncase(4)\n R = R + eps;\n F2 = F./R;\notherwise\n F2 = F.*R;\nend\nImgOut = real(ifft2(F2));\t\t% filtered image\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/4131-fftselffilter-frequency-domain-image-auto-filtering/fftsf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947148047777, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.8050908968992658}} {"text": "function s1 = stirling1 ( n, m )\n\n%*****************************************************************************80\n%\n%% STIRLING1 computes the Stirling numbers of the first kind.\n%\n% Discussion:\n%\n% The absolute value of the Stirling number S1(N,M) gives the number\n% of permutations on N objects having exactly M cycles, while the\n% sign of the Stirling number records the sign (odd or even) of\n% the permutations. For example, there are six permutations on 3 objects:\n%\n% A B C 3 cycles (A) (B) (C)\n% A C B 2 cycles (A) (BC)\n% B A C 2 cycles (AB) (C)\n% B C A 1 cycle (ABC)\n% C A B 1 cycle (ABC)\n% C B A 2 cycles (AC) (B)\n%\n% There are\n%\n% 2 permutations with 1 cycle, and S1(3,1) = 2\n% 3 permutations with 2 cycles, and S1(3,2) = -3,\n% 1 permutation with 3 cycles, and S1(3,3) = 1.\n%\n% Since there are N! permutations of N objects, the sum of the absolute\n% values of the Stirling numbers in a given row,\n%\n% sum ( 1 <= I <= N ) abs ( S1(N,I) ) = N!\n%\n% First terms:\n%\n% N/M: 1 2 3 4 5 6 7 8\n%\n% 1 1 0 0 0 0 0 0 0\n% 2 -1 1 0 0 0 0 0 0\n% 3 2 -3 1 0 0 0 0 0\n% 4 -6 11 -6 1 0 0 0 0\n% 5 24 -50 35 -10 1 0 0 0\n% 6 -120 274 -225 85 -15 1 0 0\n% 7 720 -1764 1624 -735 175 -21 1 0\n% 8 -5040 13068 -13132 6769 -1960 322 -28 1\n%\n% Recursion:\n%\n% S1(N,1) = (-1)^(N-1) * (N-1)! for all N.\n% S1(I,I) = 1 for all I.\n% S1(I,J) = 0 if I < J.\n%\n% S1(N,M) = S1(N-1,M-1) - (N-1) * S1(N-1,M)\n%\n% Properties:\n%\n% sum ( 1 <= K <= M ) S2(I,K) * S1(K,J) = Delta(I,J)\n%\n% X_N = sum ( 0 <= K <= N ) S1(N,K) X^K\n% where X_N is the falling factorial function.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 25 August 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of rows of the table.\n%\n% Input, integer M, the number of columns of the table.\n%\n% Output, integer S1(N,M), the Stirling numbers of the first kind.\n%\n if ( n <= 0 )\n s1 = [];\n return\n end\n\n if ( m <= 0 )\n s1 = [];\n return\n end\n\n s1(1,1) = 1;\n s1(1,2:m) = 0;\n\n for i = 2 : n\n\n s1(i,1) = - ( i - 1 ) * s1(i-1,1);\n\n for j = 2 : m\n s1(i,j) = s1(i-1,j-1) - ( i - 1 ) * s1(i-1,j);\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/polpak/stirling1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.8050723749795802}} {"text": "function Z = poly2DApproxLocal( D, lsX, nrBfsX, lsY, nrBfsY )\n%\n% Purpose : This function performs local polynomial approximation for\n% data which lie on a 2D grid. \n%\n% This function uses the discrete orthogonal polynomial toolbox DOPbox. The\n% toolbox is available at MATLAB file exchange:\n%\n% http://www.mathworks.com/matlabcentral/fileexchange/41250\n%\n% The use of the DOPbox enable the computation with polynomials of very\n% high degree. There is no problem to compute a polynomial of degree d =\n% 1000, the only disadvantage is the corresponding loss in speed.\n%\n% Some of the theory associated with this function can be found in the\n% publication, Discrete Polynomial Moments and Savitzky-Golay Smoothing,\n% available at:\n%\n% www.waset.org/journals/waset/v48/v48-85.pdf\n%\n% Use (syntax):\n% Z = poly2DApproxLocal( D, lsX, nrBfsX, lsY, nrBfsY )\n%\n% Input Parameters :\n% D: The 2D data lying on a grid, the function can be applied to any \n% form of data, e.g. surface data or images.\n% nrBfsX: the number of basis functions used in the x direction.\n% lsX: the support length in the x direction.\n% nrBfsY: the number of basis functions used in the y direction.\n% lsY: the support length in the y direction.\n%\n% Return Parameters :\n% Z: The 2D local polynomial approximation to the data.\n%\n% Description and algorithms:\n%\n% References : \n%\n% Author : Matther Harker and Paul O'Leary\n% Date : 29. Jan 2013\n% Version : 1.0\n%\n% (c) 2013 Matther Harker and Paul O'Leary\n% url: www.harkeroleary.org\n% email: office@harkeroleary.org\n%\n% History:\n% Date: Comment:\n%\n[ny, nx] = size( D );\n%\n% generate the rquired polynomial bases\n%\nxs = (1:nx)';\nys = (1:ny)';\n%\nSx = dopApproxLocal( xs, lsX, nrBfsX, 'sparse' );\nSy = dopApproxLocal( ys, lsY, nrBfsY, 'sparse' );\n%\n%\n% Generate the 2D local approximation\n%\nZ = Sy * D * Sx';", "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/42474-2d-polynomial-data-modelling-version-1-0/dop2DBoxV1-0/dop2DBox/dop2DApproxLocal.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.8050171433672703}} {"text": "function [data_mean,data_diff,md,sd] = bland_altman_x_gt(data1,data2)\n% Function to generate Bland Altman plots. Barry Greene, September 2008\n% Bland, J.M., Altman, D.G. 'Statistical methods for assessing agreement ...\n% between two methods of clinical measurement'(1986) Lancet, 1 (8476), pp. 307-310.\n%\n% Inputs: data1: ground truth\n% data2: estimated\n%\n% Produces Bland Altman plot with mean difference and mean difference +/-\n% 2*SD difference lines.\n\n[m,n] = size(data1);\nif(n>m)\n data1 = data1';\nend\n\nif(size(data1)~=size(data2))\n error('Data matrices must be the same size')\nend\n\ndata_mean = data1; % Mean of values from each instrument \ndata_diff = data2 - data1; % Difference between data from each instrument\nmd = mean(data_diff); % Mean of difference between instruments \nsd = std(data_diff); % Std dev of difference between instruments \n\n% figure;\nplot(data_mean,data_diff,'ok','MarkerSize',3,'LineWidth',1); % Bland Altman plot\nhold on; x = [min(data_mean),max(data_mean)];\ny = md*ones(1,2); plot(x,y,'-k'); % Mean difference line \ny = md+2*sd*ones(1,2); \nplot(x,y,'--k'); % Mean plus 2*SD line \n% text(x(2),y(2),'+2 SD'); \ny = md-2*sd*ones(1,2); \nplot(x,y,'--k'); % Mean minus 2*SD line \n\n% text(x(2),y(2),'-2 SD'); \n% grid on\n% title('Bland Altman plot','FontSize',9)\n% xlabel('Mean of two measures','FontSize',8)\n% ylabel('Difference between two measures','FontSize',8)", "meta": {"author": "zhouyuanzxcv", "repo": "Hyperspectral", "sha": "f32dcca86677f8d37596376f57e9c733058f8cff", "save_path": "github-repos/MATLAB/zhouyuanzxcv-Hyperspectral", "path": "github-repos/MATLAB/zhouyuanzxcv-Hyperspectral/Hyperspectral-f32dcca86677f8d37596376f57e9c733058f8cff/common/bland_altman_x_gt.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.805017135236535}} {"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% ====================== 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\ncount = zeros(K, 1);\nfor i = 1 : m\n count(idx(i,1),1) = count(idx(i,1),1) + 1;\n centroids(idx(i,1),:) = centroids(idx(i,1),:) + X(i,:);\nend\n\nfor i = 1 : K\n centroids(i,:) = centroids(i,:) ./ count(i,1);\nend\n\n% =============================================================\n\n\nend\n\n", "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-ex7/ex7/computeCentroids.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355092, "lm_q2_score": 0.8872045959539037, "lm_q1q2_score": 0.8049715638619633}} {"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n\n\n% DTFT properties\n\n% Differentiation in frequency\n\nsyms n\nx=0.8.^n\nL=symsum(n/j*x*exp(-j*w*n),n,0,inf);\nsubplot(211);\nw1=-pi:.01:pi;\nLi=subs(L,w,w1);\nplot(w1,abs(Li));\nlegend('magnitude of DTFT of left part')\nsubplot(212);\nplot(w1,angle(Li))\nlegend('angle of DTFT of left part')\n\nfigure\nsyms n w\nX=1/(1-0.8*exp(-j*w));\nR=diff(X,w);\nsubplot(211);\nw1=-pi:.01:pi;\nRi=subs(R,w,w1);\nplot(w1,abs(Ri));\nlegend('magnitude of right part')\nsubplot(212);\nplot(w1,angle(Ri))\nlegend('angle of right part')\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/28762-signals-and-systems-laboratory-with-matlab-m-files/M-FILES/7/c72e.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.8670357666736772, "lm_q1q2_score": 0.8049636310238087}} {"text": "function [ xtab, weight ] = ncc_rule ( norder )\n\n%*****************************************************************************80\n%\n%% NCC_RULE computes the coefficients of a Newton-Cotes closed quadrature rule.\n%\n% Discussion:\n%\n% For the interval [-1,1], the Newton-Cotes quadrature rule estimates\n%\n% Integral ( -1 <= X <= 1 ) F(X) dX\n%\n% using NORDER equally spaced abscissas XTAB(I) and a weight vector\n% WEIGHT(I):\n%\n% Sum ( 1 <= I <= N ) WEIGHT(I) * F ( XTAB(I) ).\n%\n% For the CLOSED rule, the abscissas include A and B.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NORDER, the order of the rule.\n%\n% Output, real XTAB(NORDER), the abscissas of the rule.\n%\n% Output, real WEIGHT(NORDER), the weights of the rule.\n%\n\n%\n% Compute a closed quadrature rule.\n%\n a = -1.0;\n b = 1.0;\n\n for i = 1 : norder\n xtab(i) = ( ( norder - i ) * a ...\n + ( i - 1 ) * b ) ...\n / ( norder - 1 );\n end\n\n weight = nc_rule ( norder, a, b, xtab );\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/ncc_rule.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.8049636236621782}} {"text": "function [err,Eq] = Plane_Equation (Triplets, verbose)\n%\n% [err,Eq] = Plane_Equation (Triplets, [verbose])\n%\n%Purpose:\n% Determine the equation of the plane passing through three points\n%\n%\n%Input Parameters:\n% Triplets is an Nx1 vector of strucutres. Each structure defines a plane\n% .XYZ : is a 3x3 matrix containing the XYZ of each of the three points\n% Each row is a point. ie: XYZ = [0 0 0; 1 0 0; 1 1 1]; is for the\n% three points (0 0 0), (1 0 0) and (1 1 1).\n% If the three points are colinear, Eq = [0 0 0 0]\n%\n% verbose (0/1), default is 1\n%\n%Output Parameters:\n% err : 0 No Problem\n% : 1 Mucho Problems\n%\n% Eq is a Nx4 matrix containing the equation of the plane containing each\n% triplet in Triplets. The plane passing by triplet i is speicifed in\n% Eq(i,:) the plane would be Eq(i,1)x + Eq(i,2)y + Eq(i,3)z + Eq(i,4) = 0\n%\n%More Info :\n%\n% see also ShowPlane\n% try\n% Triplets(1).XYZ = [0 0 0; 1 0 0; 1 1 0];\n% Triplets(2).XYZ = [0 0 0; 1 0 0; 1 1 1];\n% Triplets(3).XYZ = [0 5 0; 1 5 0; 1 1 1];\n%\n% [err,Eq] = Plane_Equation (Triplets);\n% [err,PatchHandles] = ShowPlane (Eq); view(3)\n%\n% Author : Ziad Saad\n% Date : Thu Oct 22 16:09:56 CDT 1998\n\n\n%Define the function name for easy referencing\nFuncName = 'Plane_Equation';\n\n%initailize return variables\nerr = 1;\n\nif (nargin == 1), \tverbose = 1;\tend\n\nif (is_row(Triplets) == -1),\terr = ErrEval(FuncName,'Err_Triplets must be an Nx1 vector');\treturn;\tend\n\nTriplets = Triplets(:);\nNplanes = size(Triplets,1);\nEq = zeros(Nplanes,4); %allocate\n\nfor (i=1:1:Nplanes),\n\t%Form the equation of the plane\n\tx1 = Triplets(i).XYZ(1,1); y1 = Triplets(i).XYZ(1,2); z1 = Triplets(i).XYZ(1,3);\n\tx2 = Triplets(i).XYZ(2,1); y2 = Triplets(i).XYZ(2,2); z2 = Triplets(i).XYZ(2,3);\n\tx3 = Triplets(i).XYZ(3,1); y3 = Triplets(i).XYZ(3,2); z3 = Triplets(i).XYZ(3,3);\n\tEq(i,1) = y1.*(z2-z3) + y2.*(z3-z1) + y3.*(z1-z2);\n\tEq(i,2) = z1.*(x2-x3) + z2.*(x3-x1) + z3.*(x1-x2);\n\tEq(i,3) = x1.*(y2-y3) + x2.*(y3-y1) + x3.*(y1-y2);\n\tEq(i,4) = -x1.*(y2.*z3 - y3.*z2) - x2.*(y3.*z1 - y1.*z3) - x3.*(y1.*z2 - y2.*z1);\n\t\n\tif (verbose),\n\t\tif (~rem (i,200)),\n\t\t\tfprintf (1,'[%g/%g]\\b\\b\\b\\b\\b\\b\\b\\b\\b\\b\\b\\b\\b\\b\\b\\b\\b\\b\\b\\b\\b',i,Nplanes);\n\t\tend\n\n\tend\nend\n\nerr = 0;\nreturn;\n\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/afni/Plane_Equation.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8774767842777551, "lm_q1q2_score": 0.8049117919102374}} {"text": "function [U,T,mu] = pcasecon(X,k)\n% Input:\n% X : m x n matrix\n% Each column of X is a feature vector\n%\n% Output:\n% X = U*T approximately (up to k)\n%\n% Description:\n% Principal Component Analysis (PCA) while trying to conserve memory and be faster\n% Requires that k <= min(m,n) where [m,n] = size(X)\n% This function is useful if k is much smaller than m and n\n% or if X is sparse (see doc eigs)\n%\n% Vipin Vijayan (2014)\n\nmu = mean(X,2);\nX = bsxfun(@minus,X,mu);\n\n[m,n] = size(X);\nassert(k <= m && k <= n, 'k needs to be smaller than size(X,1) and size(X,2)');\n\nif m <= n\n C = X*X';\n [U,~] = eigs(C,k);\n clear C;\n\n T = U'*X;\nelse\n C = X'*X; \n [V,D] = eigs(C,k);\n clear C;\n \n U = X*V; % convert evecs from X'*X to X*X'. the evals are the same.\n %s = sqrt(sum(U.^2,1))';\n s = sqrt(abs(diag(D)));\n U = bsxfun(@(x,c)x./c, U, s');\n %S = diag(s);\n %T = S*V';\n T = bsxfun(@(c,vt)c.*vt,s,V');\nend\n\n", "meta": {"author": "andrewssobral", "repo": "lrslibrary", "sha": "06d457349cb5f1fc56a583cd61af9f1d5150e3a1", "save_path": "github-repos/MATLAB/andrewssobral-lrslibrary", "path": "github-repos/MATLAB/andrewssobral-lrslibrary/lrslibrary-06d457349cb5f1fc56a583cd61af9f1d5150e3a1/libs/SVD/pcasecon.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067179697694, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.8048185044650564}} {"text": "%% RATE OF CONVERGENCE OF BILINEAR FINITE ELEMENT METHOD\n%\n% This example is to show the rate of convergence of bilinear finite\n% element approximation of the Poisson equation on the unit square:\n%\n% $$- \\Delta u = f \\; \\hbox{in } (0,1)^2$$\n%\n% for the following boundary condition:\n%\n% # Non-empty Dirichlet boundary condition. $u=g_D \\hbox{ on }\\Gamma_D, \\quad \\nabla u\\cdot n=g_N \\hbox{ on }\\Gamma_N. \\Gamma _D = \\{(x,y): x=0, y\\in [0,1]\\}, \\; \\Gamma _N = \\partial \\Omega \\backslash \\Gamma _D$. \n% # Pure Neumann boundary condition. $\\Gamma _N = \\partial \\Omega$.\n% # Robin boundary condition. $g_R u + \\nabla u\\cdot n=g_N \\hbox{ on }\\partial \\Omega$\n\n%% \nclear all; close all; clc;\n[node,elem] = squarequadmesh([0,1,0,1],1/2^5); \noption.L0 = 1;\noption.maxIt = 4;\noption.printlevel = 1;\noption.plotflag = 0;\noption.elemType = 'Q1';\n\n%% Non-empty Dirichlet boundary condition.\npde = sincosdata;\nbdFlag = setboundary(node,elem,'Dirichlet','~(x==0)','Neumann','x==0');\n% bdFlag = setboundary(node,elem,'Dirichlet');\nfemPoisson(node,elem,pde,bdFlag,option);\nreturn\n\n%% Pure Neumann boundary condition.\npde = sincosNeumanndata;\nbdFlag = setboundary(node,elem,'Neumann');\nfemPoisson(node,elem,pde,bdFlag,option);\n\n%% Pure Robin boundary condition.\noption.plotflag = 0;\npdeRobin = sincosRobindata;\nbdFlag = setboundary(node,elem,'Robin');\nfemPoisson(node,elem,pdeRobin,bdFlag,option);\n\n%% Conclusion\n%\n% The optimal rate of convergence of the H1-norm (2nd order) and L2-norm\n% (3rd order) is observed. The order of ||DuI-Duh|| is almost 3rd order and\n% thus superconvergence exists.\n%\n% MGCG converges uniformly in all cases.\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/example/femratePoissonQ1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939516, "lm_q2_score": 0.8688267626522814, "lm_q1q2_score": 0.804797471224026}} {"text": "function inside = triangle_contains_point_2d_1 ( t, p )\n\n%*****************************************************************************80\n%\n%% TRIANGLE_CONTAINS_POINT_2D_1 finds if a point is inside a triangle in 2D.\n%\n% Discussion:\n%\n% It is conventional to list the triangle vertices in counter clockwise\n% order. However, this routine does not require a particular order\n% for the vertices.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 December 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real T(2,3), the triangle vertices.\n%\n% Input, real P(2,1), the point to be checked.\n%\n% Output, logical INSIDE, is TRUE if the point is inside\n% the triangle or on its boundary.\n%\n xsi = triangle_barycentric_2d ( t, p );\n\n if ( any ( xsi(1:3,1) < 0.0 ) )\n inside = 0;\n else\n inside = 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/triangle_contains_point_2d_1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.8688267660487572, "lm_q1q2_score": 0.8047974708350085}} {"text": "function [xi,w]=thirdOrder3DCubPoints()\n%%THIRDORDER3DCUBPOINTS Generate third-order cubature points\n% for integration over a 3-dimensional cube with vertices of \n% (1,-1,-1), (-1,-1,-1), (-1,1,-1), (1,1,-1), (1,-1,1),\n% (-1,-1,1), (-1,1,1), and (1,1,1).\n%\n%INPUTS: None\n%\n%OUTPUTS: xi This is a 3XnumCubPoints set of points for the standard\n% cube.\n% w A 1XnumCubPoints set of cubature weights. This sums to the\n% volume of the standard cube (8).\n%\n%This function implements the points given in [1] (6 points).\n%\n%EXAMPLE:\n%We compare a 2nd-order moment computed using these cubature points\n%to one computed using monomialIntCube (a 3rd order moment would have\n%just been 0). The results are the same within typical finite precision\n%limits.\n% [xi,w]=thirdOrder3DCubPoints();\n% alpha=[2;0;0];\n% theMoment=findMomentFromSamp(alpha,xi,w);\n% intVal=monomialIntCube(alpha);\n% RelErr=(theMoment-intVal)/intVal\n%\n%REFERENCES:\n%[1] F. D. Witherden and P. E. Vincent, \"On the identification of symmetric\n% quadrature rules for finite element methods,\" Computer and Mathematics\n% with Applications, vol. 69, no. 10, pp. 1232-1241, May 2015.\n%\n%October 2022 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nM=[-1, 0, 0, 1.3333333333333333333333333333333333333;\n 0, 0, 1, 1.3333333333333333333333333333333333333;\n 0, 1, 0, 1.3333333333333333333333333333333333333;\n 0, 0, -1, 1.3333333333333333333333333333333333333;\n 1, 0, 0, 1.3333333333333333333333333333333333333;\n 0, -1, 0, 1.3333333333333333333333333333333333333];\n\nw=M(:,4);\nxi=M(:,1:3)';\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/Numerical_Integration/Cubature_Points/Cube_Space/Cube/thirdOrder3DCubPoints.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037241905732, "lm_q2_score": 0.8688267660487573, "lm_q1q2_score": 0.8047974690674157}} {"text": "function [a,f,B,W]=ldatrace(b,w,n,c)\n%LDATRACE Calculates an LDA transform to maximize trace discriminant [a,f,B,W]=(b,w,n,c)\n% If a feature vector X can come from one of several class and W and B are respectively\n% the within-class and between-class covariance matrices, then the generalized Fisher discriminant\n% F=trace(W\\B) is a measure of how well the feature vector discriminates between the classes.\n% If we choose a rectangular (tall, skinny) transformation matrix, we can define a smaller\n% feature vector Y=A'*X. The aim of this routine is to choose A to maximize the Fisher\n% discriminant. We assume that W is positive definite and B is positive semi-definite.\n% The input argument C allows the uset to pre-specify some of the columns of A.\n%\n% Inputs:\n% w[m,m] = within class covariance matrix of x\n% b[m,m] = between class covariance matrix of x [default = I]\n% n is the number of columns in output matrix A [default = M]\n% c[m,r] specifies the first few columns of A to be predefined values [default = null)\n%\n% Outputs:\n% a[m,n] is the transformation matrix: y=a'*x\n% f[n,1] gives the incremental gain in f value for successive columns of A \n% B(n,n) gives the between-class covariance matrix of y\n% W[n,n] gives the within-class covariance matrix of y \n\n% Copyright (C) Mike Brookes 1997\n% Version: $Id: ldatrace.m 713 2011-10-16 14:45:43Z 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\nm=size(b,1); % dimension of data vectors\nif nargin<4\n r=0;\n if nargin<3\n n=m;\n if nargin<2\n w=eye(m);\n end\n end\nelse\n r=size(c,2); % number of columns that are pre-specified\nend\nif r\n if n>r % 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": "jtkim-kaist", "repo": "VAD", "sha": "a1e0b1299fcf22eb7654b2906a67184c73b37faa", "save_path": "github-repos/MATLAB/jtkim-kaist-VAD", "path": "github-repos/MATLAB/jtkim-kaist-VAD/VAD-a1e0b1299fcf22eb7654b2906a67184c73b37faa/lib/matlab/voicebox/ldatrace.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.8046928552253453}} {"text": "function [rwproc] = ranwalk(npoints, p)\n% RANWALK generate and plot a trajectory of a random walk which\n% starts at 0, jumps up with probability p and down with\n% probability 1-p \n%\n% [rwproc] = ranwalk(npoints, p)\n%\n% Inputs: npoints - length of the trajectory \n% p - probability of the jump upwards\n%\n% Outputs: rwproc - trajectory of the process\n\n% Authors: R.Gaigalas, I.Kaj\n% v1.2 07-Oct-02\n\n % default parameter values\n if (nargin==0)\n npoints = 100;\n p = 0.5;\n end\n\n % generate jumps and sum up\n rwproc = [0 cumsum(2.*(rand(1, npoints-1)abs(dx)\nif steep t=dx;dx=dy;dy=t; end\n\n%The main algorithm goes here.\nif dy==0 \n q=zeros(dx+1,1);\nelse\n q=[0;diff(mod([floor(dx/2):-dy:-dy*dx+floor(dx/2)]',dx))>=0]\nend\n\n%and ends here.\n\nif steep\n if y1<=y2 y=[y1:y2]'; else y=[y1:-1:y2]'; end\n if x1<=x2 x=x1+cumsum(q);else x=x1-cumsum(q); end\nelse\n if x1<=x2 x=[x1:x2]'; else x=[x1:-1:x2]'; end\n if y1<=y2 y=y1+cumsum(q);else y=y1-cumsum(q); 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/28190-bresenham-optimized-for-matlab/bresenham.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680097, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.8042169118842408}} {"text": "%% Creating one filter\n% In this demo, we will show how to build some filters in spatial domain or\n% Fourier domain. Gabor, Morlet and Gaussian filters are pointed out.\n%\n%% Reviewed functions\n% The following function will be demonstrated:\n%%\n% \n% # gabor_2d\n% # gaussian_2d\n% # morlet_2d_noDC\n% # morlet_2d_pyramid\n%\n%% Demonstration\n%\n% Here are shown 4 examples of filters:\n\nN=50;\nM=50;\nsigma=10;\nslant=3;\ntheta=pi/3;\nxi=2;\n\ngab = gabor_2d(N, M, sigma, slant, xi, theta);\nmorlet = morlet_2d_noDC(N, M, sigma, slant, xi, theta);\nmorlet2 = morlet_2d_pyramid(N, M, sigma, slant, xi, theta);\ngaussian = gaussian_2d(N, M, sigma);\nsubplot(2,2,1)\nimagesc(real(gab));\naxis off\ntitle('Real part of Gabor wavelet in Fourier domain')\nsubplot(2,2,2)\nimagesc(real(morlet));\naxis off\ntitle('Real part of Morlet wavelet in Fourier domain')\nsubplot(2,2,3)\nimagesc(real(morlet2));\naxis off\ntitle('Real part of Morlet wavelet in Spatial domain')\nsubplot(2,2,4)\nimagesc(gaussian);\naxis off\ntitle('Gaussian wavelet')\n\n\n\n", "meta": {"author": "scatnet", "repo": "scatnet", "sha": "59d935afa20359845282a3518134e24244862c1f", "save_path": "github-repos/MATLAB/scatnet-scatnet", "path": "github-repos/MATLAB/scatnet-scatnet/scatnet-59d935afa20359845282a3518134e24244862c1f/demo/filters/demo_individual_filter.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191335436404, "lm_q2_score": 0.8418256393148982, "lm_q1q2_score": 0.8042121403451297}} {"text": "function [ x, seed ] = truncated_normal_ab_sample ( mu, sigma, a, b, seed )\n\n%*****************************************************************************80\n%\n%% TRUNCATED_NORMAL_AB_SAMPLE samples the truncated Normal PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 14 August 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real MU, SIGMA, the mean and standard deviation of the\n% parent Normal distribution.\n%\n% Input, real A, B, the lower and upper truncation limits.\n%\n% Input/output, integer SEED, a seed for the random number\n% generator.\n%\n% Output, real X, a sample of the PDF.\n%\n alpha = ( a - mu ) / sigma;\n beta = ( b - mu ) / sigma;\n\n alpha_cdf = normal_01_cdf ( alpha );\n beta_cdf = normal_01_cdf ( beta );\n\n [ u, seed ] = r8_uniform_01 ( seed );\n xi_cdf = alpha_cdf + u * ( beta_cdf - alpha_cdf );\n xi = normal_01_cdf_inv ( xi_cdf );\n\n x = mu + sigma * xi;\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/truncated_normal_ab_sample.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216356, "lm_q2_score": 0.8652240930029117, "lm_q1q2_score": 0.8041742337712087}} {"text": "%ZNCC Normalized cross correlation\n%\n% M = ZNCC(I1, I2) is the zero-mean normalized cross-correlation between the \n% two equally sized image patches I1 and I2. The result M is a scalar in\n% the interval -1 to 1 that indicates similarity. A value of 1 indicates \n% identical pixel patterns.\n%\n% Notes::\n% - The ZNCC similarity measure is invariant to affine changes in image\n% intensity (brightness offset and scale).\n%\n% See also NCC, SAD, SSD, ISIMILARITY.\n\n\n\n% Copyright (C) 1993-2011, by Peter I. Corke\n%\n% This file is part of The Machine Vision Toolbox for Matlab (MVTB).\n% \n% MVTB 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% MVTB 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 MVTB. If not, see .\n\n\nfunction m = zncc(w1, w2)\n\n\tw1 = w1 - mean(w1(:));\n\tw2 = w2 - mean(w2(:));\n\n\tdenom = sqrt( sum(sum(w1.^2))*sum(sum(w2.^2)) );\n\n\tif denom < 1e-10,\n\t\tm = 0;\n\telse\n\t\tm = sum(sum((w1.*w2))) / denom;\n\tend\n", "meta": {"author": "petercorke", "repo": "machinevision-toolbox-matlab", "sha": "2d791168c19c5e56acef74d22eafd227b4b58e42", "save_path": "github-repos/MATLAB/petercorke-machinevision-toolbox-matlab", "path": "github-repos/MATLAB/petercorke-machinevision-toolbox-matlab/machinevision-toolbox-matlab-2d791168c19c5e56acef74d22eafd227b4b58e42/zncc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216356, "lm_q2_score": 0.8652240756264638, "lm_q1q2_score": 0.8041742176208357}} {"text": "function [J, grad] = lrCostFunction(theta, X, y, lambda)\n%LRCOSTFUNCTION Compute cost and gradient for logistic regression with\n%regularization\n% J = LRCOSTFUNCTION(theta, X, y, lambda) computes the cost of using\n% theta as the parameter for regularized logistic regression and the\n% gradient of the cost w.r.t. to the parameters.\n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly\nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n% Hint: The computation of the cost function and gradients can be\n% efficiently vectorized. For example, consider the computation\n%\n% sigmoid(X * theta)\n%\n% Each row of the resulting matrix will contain the value of the\n% prediction for that example. You can make use of this to vectorize\n% the cost function and gradient computations.\n%\n% Hint: When computing the gradient of the regularized cost function,\n% there're many possible vectorized solutions, but one solution\n% looks like:\n% grad = (unregularized gradient for logistic regression)\n% temp = theta;\n% temp(1) = 0; % because we don't add anything for j = 0\n% grad = grad + YOUR_CODE_HERE (using the temp variable)\n%\n\n\nh = sigmoid(X * theta);\nJ = sum(-y .* log(h) - (1 - y) .* log(1 - h)) / m;\n% regularization for cost function\nJ = J + (lambda / (2 * m)) * sum(theta(2:end) .^ 2);\ngrad = (1 / m) * X' * (h - y);\n% regularization for gradient values\ngrad = grad + (lambda / m) * [0; theta(2:end)];\n\n\n% =============================================================\n\ngrad = grad(:);\n\nend\n", "meta": {"author": "zsiciarz", "repo": "ml-coursera", "sha": "54208ee72b88f1dc3c9235e644a47f618b80441c", "save_path": "github-repos/MATLAB/zsiciarz-ml-coursera", "path": "github-repos/MATLAB/zsiciarz-ml-coursera/ml-coursera-54208ee72b88f1dc3c9235e644a47f618b80441c/octave/mlclass-ex3/lrCostFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346504434783, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.8040834823472682}} {"text": "function varargout = rotation3dToEulerAngles(mat, varargin)\n%ROTATION3DTOEULERANGLES Extract Euler angles from a rotation matrix.\n%\n% [PHI, THETA, PSI] = rotation3dToEulerAngles(MAT)\n% Computes Euler angles PHI, THETA and PSI (in degrees) from a 3D 4-by-4\n% or 3-by-3 rotation matrix.\n%\n% ANGLES = rotation3dToEulerAngles(MAT)\n% Concatenates results in a single 1-by-3 row vector. This format is used\n% for representing some 3D shapes like ellipsoids.\n%\n% ... = rotation3dToEulerAngles(MAT, CONVENTION)\n% CONVENTION specifies the axis rotation sequence. \n% Supported conventions are: 'ZYX', 'ZYZ'. Default is 'ZYX'\n%\n% Example\n% rotation3dToEulerAngles\n%\n% References\n% Code from Graphics Gems IV on euler angles\n% http://tog.acm.org/resources/GraphicsGems/gemsiv/euler_angle/EulerAngles.c\n% Modified using explanations in:\n% http://www.gregslabaugh.name/publications/euler.pdf\n%\n% See also\n% transforms3d, rotation3dAxisAndAngle, createRotation3dLineAngle,\n% eulerAnglesToRotation3d\n%\n%\n% ------\n% Author: David Legland\n% e-mail: david.legland@grignon.inra.fr\n% Created: 2010-08-11, using Matlab 7.9.0.529 (R2009b)\n% Copyright 2010 INRA - Cepia Software Platform.\n\np = inputParser;\nvalidStrings = {'ZYX','ZYZ'};\naddOptional(p,'convention','ZYX',@(x) any(validatestring(x,validStrings)));\nparse(p,varargin{:});\nconvention=p.Results.convention;\n\n% conversion from radians to degrees\nk = 180 / pi;\n\nswitch convention\n case 'ZYX'\n % extract |cos(theta)|\n cy = hypot(mat(1,1), mat(2,1));\n % avoid dividing by 0\n if cy > 16*eps\n % normal case: theta <> 0\n phi = k * atan2( mat(2,1), mat(1,1));\n theta = k * atan2(-mat(3,1), cy);\n psi = k * atan2( mat(3,2), mat(3,3));\n else\n % \n phi = 0;\n theta = k * atan2(-mat(3,1), cy);\n psi = k * atan2(-mat(2,3), mat(2,2));\n end\n case 'ZYZ'\n cy = hypot(mat(3,2), mat(3,1));\n if cy > 16*eps\n phi = k * -atan2(mat(2,3), -mat(1,3));\n theta = k * -atan2(cy, mat(3,3));\n psi = k * -atan2(mat(3,2), mat(3,1));\n else\n phi = 0;\n theta = k * atan2(cy, mat(3,3));\n psi = k * atan2(mat(2,1), mat(2,2));\n end\nend\n\n% format output arguments\nif nargout <= 1\n % one array\n varargout{1} = [phi theta psi];\nelse\n % three separate arrays\n varargout = {phi, theta, psi};\nend\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/rotation3dToEulerAngles.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467158, "lm_q2_score": 0.867035758084294, "lm_q1q2_score": 0.8040571380605995}} {"text": "function STATS=mwwtest(x1,x2)\n% Mann-Whitney-Wilcoxon non parametric test for two unpaired groups.\n% This file execute the non parametric Mann-Whitney-Wilcoxon test to evaluate the\n% difference between unpaired samples. If the number of combinations is less than\n% 20000, the algorithm calculates the exact ranks distribution; else it \n% uses a normal distribution approximation. The result is not different from\n% RANKSUM MatLab function, but there are more output informations.\n% There is an alternative formulation of this test that yields a statistic\n% commonly denoted by U. Also the U statistic is computed.\n% \n% Syntax: \tSTATS=MWWTEST(X1,X2)\n% \n% Inputs:\n% X1 and X2 - data vectors. \n% Outputs:\n% - T and U values and p-value when exact ranks distribution is used.\n% - T and U values, mean, standard deviation, Z value, and p-value when\n% normal distribution is used.\n% If STATS nargout was specified the results will be stored in the STATS\n% struct.\n% \n% Example: \n% \n% X1=[181 183 170 173 174 179 172 175 178 176 158 179 180 172 177];\n% \n% X2=[168 165 163 175 176 166 163 174 175 173 179 180 176 167 176];\n% \n% Calling on Matlab the function: mwwtest(X1,X2)\n% \n% Answer is:\n% \n% MANN-WHITNEY-WILCOXON TEST\n% \n% Group_1 Group_2\n% _______ _______\n% \n% Numerosity 15 15 \n% Sum_of_Rank_W 270 195 \n% Mean_Rank 18 13 \n% Test_variable_U 75 150 \n% \n% Sample size is large enough to use the normal distribution approximation\n% \n% Mean SD Z p_value_one_tail p_value_two_tails\n% _____ ______ ______ ________________ _________________\n% \n% 112.5 24.047 1.5386 0.061947 0.12389 \n% \n% Created by Giuseppe Cardillo\n% giuseppe.cardillo-edta@poste.it\n% \n% To cite this file, this would be an appropriate format:\n% Cardillo G. (2009). MWWTEST: Mann-Whitney-Wilcoxon non parametric test for two unpaired samples.\n% http://www.mathworks.com/matlabcentral/fileexchange/25830\n%Input Error handling\np = inputParser;\naddRequired(p,'x1',@(x) validateattributes(x,{'numeric'},{'row','real','finite','nonnan','nonempty'}));\naddRequired(p,'x2',@(x) validateattributes(x,{'numeric'},{'row','real','finite','nonnan','nonempty'}));\nparse(p,x1,x2);\n%set the basic parameter\nn1=length(x1); n2=length(x2); NP=n1*n2; N=n1+n2; N1=N+1; k=min([n1 n2]);\n[A,B]=tiedrank([x1(:); x2(:)]); %compute the ranks and the ties\nR1=A(1:n1); R2=A(n1+1:end); \nT1=sum(R1); T2=sum(R2);\nU1=NP+(n1*(n1+1))/2-T1; U2=NP-U1;\ndisp('MANN-WHITNEY-WILCOXON TEST')\ndisp(' ')\ndisp(table([n1;T1;T1/n1;U1],[n2;T2;T2/n2;U2],...\n 'VariableNames',{'Group_1' 'Group_2'},...\n 'RowNames',{'Numerosity' 'Sum_of_Rank_W' 'Mean_Rank' 'Test_variable_U'}))\nif nargout\n STATS.n=[n1 n2];\n STATS.W=[T1 T2];\n STATS.mr=[T1/n1 T2/n2];\n STATS.U=[U1 U2];\nend \nif round(exp(gammaln(N1)-gammaln(k+1)-gammaln(N1-k))) > 20000\n mU=NP/2;\n if B==0\n sU=realsqrt(NP*N1/12);\n else\n sU=realsqrt((NP/(N^2-N))*((N^3-N-2*B)/12));\n end\n Z1=(abs(U1-mU)-0.5)/sU;\n p=1-normcdf(Z1); %p-value\n disp('Sample size is large enough to use the normal distribution approximation')\n disp(' ')\n disp(table(mU,sU,Z1,p,2*p,'VariableNames',{'Mean' 'SD' 'Z' 'p_value_one_tail' 'p_value_two_tails'}))\n if nargout\n STATS.method='Normal approximation';\n STATS.mU=mU;\n STATS.sU=sU;\n STATS.Z=Z1;\n STATS.p=[p 2*p];\n end\nelse\n disp('Sample size is small enough to use the exact Mann-Whitney-Wilcoxon distribution')\n disp(' ')\n if n1<=n2\n w=T1;\n else\n w=T2;\n end\n pdf=sum(nchoosek(A,k),2);\n P = [sum(pdf<=w) sum(pdf>=w)]./length(pdf);\n p = min(P);\n disp(table(w,p,2*p,'VariableNames',{'W' 'p_value_one_tail' 'p_value_two_tails'}))\n if nargout\n STATS.method='Exact distribution';\n STATS.T=w;\n STATS.p=[p 2*p];\n end\nend\ndisp(' ')\n", "meta": {"author": "kavli-ntnu", "repo": "MINI2P_toolbox", "sha": "83311a49baea69ecf027e19390e608fd4eaeae8d", "save_path": "github-repos/MATLAB/kavli-ntnu-MINI2P_toolbox", "path": "github-repos/MATLAB/kavli-ntnu-MINI2P_toolbox/MINI2P_toolbox-83311a49baea69ecf027e19390e608fd4eaeae8d/Analysis/+helpers/mwwtest.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.8887588023318196, "lm_q1q2_score": 0.8040161238203865}} {"text": "% book : Signals and Systems Laboratory with MATLAB \n% authors : Alex Palamides & Anastasia Veloni\n\n% Symmetry\n\n\n% \tEven symmetry \n\nsyms x t k T \nw=2*pi/T;\nc1=(2/T)*int(x*sin(k*w*t),t,-T/2,0);\n\nc2=(2/T)*int(x*sin(k*w*t),t,0,T/2);\nc=c1+c2\n\nt0=-2;\nT=4;\nw=2*pi/T;\nsyms t\nx=t^2;\nk=-5:5;\na=(1/T)*int(x*exp(-j*k*w*t),t,t0,t0+T);\nstem(k,eval(a))\nlegend('a_k')\n\n\n\n% \tOdd symmetry \nfigure\nsyms x t k T\nw=2*pi/T;\nb1=(2/T)*int(-x*cos(k*w*t),t,-T/2,0);\n\nb2=(2/T)*int(x*cos(k*w*t),t,0,T/2);\nb=b1+b2\n\nt0=-2;\nT=4;\nw=2*pi/T;\nsyms t\nx=t;\nk=-5:5;\na=(1/T)*int(x*exp(-j*k*w*t),t,t0,t0+T);\n\nstem(k,imag(eval(a)))\nlegend('a_k')\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/c510.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.948154531885212, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.8040044784627924}} {"text": "function p = multivariateGaussian(X, mu, Sigma2)\n%MULTIVARIATEGAUSSIAN Computes the probability density function of the\n%multivariate gaussian distribution.\n% p = MULTIVARIATEGAUSSIAN(X, mu, Sigma2) Computes the probability \n% density function of the examples X under the multivariate gaussian \n% distribution with parameters mu and Sigma2. If Sigma2 is a matrix, it is\n% treated as the covariance matrix. If Sigma2 is a vector, it is treated\n% as the \\sigma^2 values of the variances in each dimension (a diagonal\n% covariance matrix)\n%\n\nk = length(mu);\n\nif (size(Sigma2, 2) == 1) || (size(Sigma2, 1) == 1)\n Sigma2 = diag(Sigma2);\nend\n\nX = bsxfun(@minus, X, mu(:)');\np = (2 * pi) ^ (- k / 2) * det(Sigma2) ^ (-0.5) * ...\n exp(-0.5 * sum(bsxfun(@times, X * pinv(Sigma2), X), 2));\n\nend", "meta": {"author": "Ayatans", "repo": "Machine-Learning-homework", "sha": "4550cfc0426c9da8072dff165130fff40d138c10", "save_path": "github-repos/MATLAB/Ayatans-Machine-Learning-homework", "path": "github-repos/MATLAB/Ayatans-Machine-Learning-homework/Machine-Learning-homework-4550cfc0426c9da8072dff165130fff40d138c10/machine-learning-ex8/ex8/multivariateGaussian.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620550745211, "lm_q2_score": 0.8376199613065411, "lm_q1q2_score": 0.8039158554350068}} {"text": "%% Runge-Kutta 2\n% \n% for solving \n%\n% $\\frac{dv}{dt}=-\\alpha (t)v+\\beta (t)$\n%\n% where $\\alpha (t) = \\frac{3t}{1-t}$ and $\\beta (t)=2(1-t)^3 e^{-t}$\n%\n% Assuming v(0)=1.0 for the period 0 (eq 15 - 16 Watt Peselnick 1980).\nA = H - beta .* complianceTensor.eye - gamma .* dyad(tensor.eye,tensor.eye);\nB = inv(A);\n\n\n% now perform the averaging of the B matrix to get two numbers (B1 and B2)\n% that are related to the two isotropic moduli - perturbations of the\n% reference values (eq 21 and 22 Watt Peselnick 1980)\nsB1 = EinsteinSum(B,[-1 -1 -2 -2]);\nsB2 = EinsteinSum(B,[-1 -2 -1 -2]);\n\nB1 = (2*sB1 - sB2) / 15;\nB2 = (3*sB2 - sB1) / 30;\n\n% The Hashin-Shtrikman moduli are then calculated as changes from the\n% reference isotropic body. (eq 25 & 27 Watt and Peselnick 1980)\nkhs = Ko + ( 3 * B1 + 2 * B2 ) ./ ( 3 + alpha .* (3 * B1 + 2 * B2) );\nghs = Go + B2 ./ ( 1 + 2 * beta .* B2 );\n\n% The moduli are valid in two limits - minimizing or maximizing the\n% anisotropic difference elastic energy. Think of it as the maximum\n% positive deviations from the reference state or the maximum negative\n% deviations from the reference state. These are either in the positive\n% definite or negative definite regime of the matrix R. Here is a test of\n% the properties of R. A +1 is returned if positive definite, a -1 is\n% retunred if negative definite. 0 returned otherwise.\n\ndef = zeros(size(R));\nD = eig(R);\ndef(all(D>0,1)) = 1;\ndef(all(D<0,1)) = -1;\n\n% isf minmax == 0 this means ...\nkhs(def==0) = NaN;\nghs(def==0) = NaN;\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/TensorAnalysis/@stiffnessTensor/HashinShtrikmanModulus.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954105, "lm_q2_score": 0.8577681013541611, "lm_q1q2_score": 0.8039095181016837}} {"text": "function [A, b] = sllinrega(X, Y, varargin)\n%SLLINREGA Performs Augmented Multivariate Linear Regression\n%\n% $ Syntax $\n% - [A, b] = sllinrega(X, Y, ...)\n%\n% $ Arguments $\n% - X: The sample matrix of x\n% - Y: The sample matrix of y\n% - A: The solved transform matrix\n% - b: The solved shift vector\n%\n% $ Description $\n% - [A, b] = sllinrega(X, Y, ...) solves the regression problem given\n% by the following formula:\n% y = A * x + b\n% in least square error sense. The samples are stored in X and Y\n% in column-wise manner.\n% You can specify properties for regression as in sllinreg.\n%\n% $ Remarks $\n% - The implementation is based on sllinreg with an augmented \n% formulation as follows:\n% y = [A, b] * [x; 1]\n%\n% $ History $\n% - Created by Dahua Lin, on Sep 15th, 2006\n%\n\n%% parse and verify input arguments\n\nif nargin < 2\n raise_lackinput('sllinrega', 2);\nend\n\nif ~isnumeric(X) || ~isnumeric(Y) || ndims(X) ~= 2 || ndims(Y) ~= 2\n error('sltoolbox:invalidarg', ...\n 'The X and Y should be both 2D numeric matrices');\nend\n\n%% main\n\n% augment formulation\n[dx, nx] = size(X);\nXa = [X; ones(1, nx)];\n\n% solve\nAa = sllinreg(Xa, Y, varargin{:});\nclear Xa;\n\n% extract \nA = Aa(:, 1:dx);\nb = Aa(:, dx+1);\n\n\n\n\n\n\n\n", "meta": {"author": "lmthang", "repo": "nmt.hybrid", "sha": "50d5c025f18ed280ff0fd2e2adce327f4170a2c3", "save_path": "github-repos/MATLAB/lmthang-nmt.hybrid", "path": "github-repos/MATLAB/lmthang-nmt.hybrid/nmt.hybrid-50d5c025f18ed280ff0fd2e2adce327f4170a2c3/code/wordsim/code/sltoolbox_r101/sltoolbox_r101/sltoolbox/regression/sllinrega.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012732322215, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.8039038219448329}} {"text": "function y = compute_orthogonal_projection( x, A, C )\n\n% compute_orthogonal_projection - computer orthogonal projection\n%\n% y = compute_orthogonal_projection( x, A, C );\n%\n% y is the pojection of x onto the intersection of the sets\n% { y \\ =0 }\n% where the cj and the aj are the columns of C and A.\n%\n% Copyright (c) 2007 Gabriel Peyre\n\n% compute solution as\n% y = x + A*lambda\n\nD = (A'*A);\nif abs(det(D))<1e-9\n D = D+rand(size(D))*1e-9;\nend\nlambda = D \\ ( -A'*x + diag(A'*C) );\ny = x + A*lambda;\n\n", "meta": {"author": "gpeyre", "repo": "matlab-toolboxes", "sha": "0cd622c988cda6f63f64d35cd7bd096fa578e5c6", "save_path": "github-repos/MATLAB/gpeyre-matlab-toolboxes", "path": "github-repos/MATLAB/gpeyre-matlab-toolboxes/matlab-toolboxes-0cd622c988cda6f63f64d35cd7bd096fa578e5c6/toolbox_misc/compute_orthogonal_projection.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9458012686491108, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.8039038198465313}} {"text": "clear all; close all;\nfigure(1)\n% underdetermined\nn=20; m=100\nA=rand(n,m); b=rand(n,1);\n\ncvx_begin;\nvariable x2(m)\nminimize( norm(x2,2) );\nsubject to\nA*x2 == b;\ncvx_end;\n\ncvx_begin;\nvariable x1(m)\nminimize( norm(x1,1) );\nsubject to\nA*x1 == b;\ncvx_end;\n\nsubplot(3,1,1), bar(x2) \nsubplot(3,1,2), bar(x1) \nsubplot(3,2,5), hist(x2,40)\nsubplot(3,2,6), hist(x1,40)\n\nsubplot(3,1,1), axis([0 100 -.2 .2]), subplot(3,1,2), axis([0 100 -.4 .4])\nsubplot(3,2,5), axis([-.15 .15 0 82]), set(gca,'Ytick',[0 40 80],'Xtick',[-0.1 0 0.1])\nh = findobj(gca,'Type','patch'); h.FaceColor = [0.6 0.6 0.6]; h.EdgeColor = 'k';\nsubplot(3,2,6), axis([-.15 .15 0 82]), set(gca,'Ytick',[0 40 80],'Xtick',[-0.1 0 0.1])\nh = findobj(gca,'Type','patch'); h.FaceColor = [0.6 0.6 0.6]; h.EdgeColor = 'k';\n\n%%\nclear A\nclear b\nclear x\nfigure(2)\n\n% overdetermined\nn=500; m=100;\nA=rand(n,m);\nb=rand(n,1);\nxdag=pinv(A)*b;\n\nlam=[0 0.1 0.5];\nfor j=1:3\n \n cvx_begin;\n variable x(m)\n minimize( norm(A*x-b,2) + lam(j)*norm(x,1) );\n cvx_end;\n \n subplot(4,1,j),bar(x) \n subplot(4,3,9+j), hist(x,20)\nend\n\n\nfor j=1:3\n \n \n subplot(4,1,j), axis([0 100 -.15 .15])\n subplot(4,3,9+j), axis([-.15 .15 0 80]), set(gca,'Ytick',[0 40 80])\n h = findobj(gca,'Type','patch');\n h.FaceColor = [0.6 0.6 0.6];\n h.EdgeColor = 'k';\nend\n\n\n%%\n% matrix overdetermined system\n\nclear A\nclear b\nclear x\nfigure(3)\n\n% overdetermined\nn=300; m=60; p=20;\nA=rand(n,m); b=rand(n,p);\n\nlam=[0 0.1];\nfor j=1:2\n cvx_begin;\n variable x(m,p)\n minimize(norm(A*x-b,2) + lam(j)*norm(x,1));\n cvx_end;\n subplot(2,1,j), pcolor(x.'), colormap(hot), colorbar\nend\n\n%%\nsubplot(2,1,1), set(gca,'Fontsize',[15],'Xtick',[1 20 40 60],'Ytick',[1 10 20])\nsubplot(2,1,2), set(gca,'Fontsize',[15],'Xtick',[1 20 40 60],'Ytick',[1 10 20])\n\n\n\n\n\n\n\n", "meta": {"author": "dynamicslab", "repo": "databook_matlab", "sha": "d390d39d18489a4804ee87a143ae8db8a1f3010b", "save_path": "github-repos/MATLAB/dynamicslab-databook_matlab", "path": "github-repos/MATLAB/dynamicslab-databook_matlab/databook_matlab-d390d39d18489a4804ee87a143ae8db8a1f3010b/CH04/CH04_SEC03_1_OverUnderDetermined.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.945801274759925, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.8039038160544953}} {"text": "function hsi = rgb2hsi(rgb)\n%RGB2HSI Converts an RGB image to HSI.\n% HSI = RGB2HSI(RGB) converts an RGB image to HSI. The input image is\n% assumed to be of size M-by-N-by-3, where the third dimension\n% accounts for three image planes: red, green, and blue, in that\n% order. If all RGB component images are equal, the HSI conversion is\n% undefined. The input image can be of class double (with values in\n% the range [0, 1]), uint8, or uint16.\n%\n% The output image, HSI, is of class double, where:\n% HSI(:,:,1) = hue image normalized to the range [0,1] by dividing\n% all angle values by 2*pi. \n% HSI(:,:,2) = saturation image, in the range [0,1]. \n% HSI(:,:,3) = intensity image, in the range [0,1].\n%\n% All the conversion equations are explained in Chapter 7 of DIPUM3E.\n%\n% Copyright 2002-2020 Gatesmark\n%\n% This function, and other functions in the DIPUM Toolbox, are based \n% on the theoretical and practical foundations established in the \n% book Digital Image Processing Using MATLAB, 3rd ed., Gatesmark \n% Press, 2020.\n%\n% Book website: http://www.imageprocessingplace.com\n% License: https://github.com/dipum/dipum-toolbox/blob/master/LICENSE.txt\n\n% Extract the individual component images.\nrgb = im2double(rgb);\nr = rgb(:,:,1);\ng = rgb(:,:,2);\nb = rgb(:,:,3);\n\n% Implement the conversion equations.\nnum = 0.5*((r - g) + (r - b));\nden = sqrt((r - g).^2 + (r - b).*(g - b));\ntheta = acos(num./(den + eps));\n\nH = theta;\nH(b > g) = 2*pi - H(b > g);\nH = H/(2*pi);\n\nnum = min(min(r,g),b);\nden = r + g + b;\nden(den == 0) = eps;\nS = 1 - 3.* num./den;\n\nH(S == 0) = 0;\n\nI = (r + g + b)/3;\n\n% Combine all three results into an hsi image.\nhsi = cat(3,H,S,I);\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/rgb2hsi.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.8688267898240861, "lm_q1q2_score": 0.803864575260621}} {"text": "function dist = segment_point_dist_2d ( p1, p2, p )\n\n%*****************************************************************************80\n%\n%% SEGMENT_POINT_DIST_2D: distance ( line segment, point ) in 2D.\n%\n% Discussion:\n%\n% A line segment is the finite portion of a line that lies between\n% two points.\n%\n% The nearest point will satisfy the condition\n%\n% PN = (1-T) * P1 + T * P2.\n%\n% T will always be between 0 and 1.\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 P1(2,1), P2(2,1), the endpoints of the line segment.\n%\n% Input, real P(2,1), the point whose nearest neighbor on the line\n% segment is to be determined.\n%\n% Output, real DIST, the distance from the point to the line segment.\n%\n\n%\n% If the line segment is actually a point, then the answer is easy.\n%\n if ( p1(1:2,1) == p2(1:2,1) )\n\n t = 0.0;\n\n else\n\n bot = sum ( ( p2(1:2,1) - p1(1:2,1) ).^2 );\n\n t = ( p(1:2,1) - p1(1:2,1) )' * ( p2(1:2,1) - p1(1:2,1) ) / bot;\n\n t = max ( t, 0.0 );\n t = min ( t, 1.0 );\n\n end\n\n pn(1:2,1) = p1(1:2,1) + t * ( p2(1:2,1) - p1(1:2,1) );\n\n dist = sqrt ( sum ( ( pn(1:2,1) - p(1:2,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/segment_point_dist_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.8688267847293731, "lm_q1q2_score": 0.8038645687555718}} {"text": "function [pgx,pgy,area,perim] = minboundparallelogram(x,y,metric)\n% minboundparallelogram: Compute the minimal bounding parallelogram of points in the plane\n% usage: [pgx,pgy,area,perimeter] = minboundparallelogram(x,y,metric)\n%\n% While minboundrect allows you to choose between a minimal area or\n% perimeter, it turns out that the minimal area paralellogram is not\n% always unique. However, there will exist a unique parallelogram of\n% minimal perimeter.\n%\n% arguments: (input)\n% x,y - vectors of points, describing points in the plane as\n% (x,y) pairs. x and y must be the same lengths.\n%\n% metric - (OPTIONAL) - single letter character flag which\n% denotes the use of minimal area or perimeter as the\n% metric to be minimized. metric may be either 'a' or 'p',\n% capitalization is ignored. Any other contraction of 'area'\n% or 'perimeter' is also accepted.\n%\n% DEFAULT: 'a' ('area')\n%\n% arguments: (output)\n% pgx,pgy - 5x1 vectors of points that define the minimal\n% bounding parallelogram.\n%\n% area - (scalar) area of the minimal parallelogram itself.\n%\n% perimeter - (scalar) perimeter of the minimal parallelogram as found\n%\n%\n% Example usage:\n% x = rand(50000,1);\n% y = rand(50000,1);\n% tic,[px,py,area,perim] = minboundparallelogram(x,y);toc\n%\n% Elapsed time is 0.083340 seconds.\n%\n% [px,py]\n% ans =\n% 8.73336658824275e-05 3.51448852413649e-05\n% 1.00002616513798 3.7428827532671e-05\n% 0.999923888887252 0.999977663164396\n% -1.49425848464391e-05 0.999975379222104\n% 8.73336658824275e-05 3.51448852413649e-05\n%\n% area\n% area =\n% 0.999879069698332\n% \n% perim\n% perim =\n% 3.9997581420842\n%\n%\n% See also: minboundcircle, minboundtri, minboundrect\n%\n%\n% Author: John D'Errico\n% E-mail: woodchips@rochester.rr.com\n% Release: 1.0\n% Release date: 8/19/2010\n\n% default for metric\nif (nargin<3) || isempty(metric)\n metric = 'a';\nelseif ~ischar(metric)\n error('metric must be a character flag if it is supplied.')\nelse\n % check for 'a' or 'p'\n metric = lower(metric(:)');\n ind = strmatch(metric,{'area','perimeter'});\n if isempty(ind)\n error('metric does not match either ''area'' or ''perimeter''')\n end\n \n % just keep the first letter.\n metric = metric(1);\nend\n\n% preprocess data\nx=x(:);\ny=y(:);\n\n% not many error checks to worry about\nn = length(x);\nif n~=length(y)\n error('x and y must be the same sizes')\nend\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, so we drop them.\nif n>3\n edges = convhull(x,y); % 'Pp' will silence the warnings\n\n % exclude those points inside the hull as not relevant\n % also sorts the points into their convex hull as a\n % closed polygon\n \n x = x(edges(1:(end-1)));\n y = y(edges(1:(end-1)));\n \n % probably fewer points now, unless the points are fully convex\n nedges = length(x) - 1;\n \nelseif n > 1\n % n must be 2 or 3\n nedges = n;\n x(end+1) = x(1);\n y(end+1) = y(1);\nelse\n % n must be 0 or 1\n nedges = n;\nend\n\n% now we must find the bounding parallelogram of those\n% that remain.\n\n% special case small numbers of points. If we trip any\n% of these cases, then we are done, so return.\nswitch nedges\n case 0\n % empty begets empty\n pgx = [];\n pgy = [];\n area = [];\n perimeter = [];\n return\n case 1\n % with one point, the rect is simple.\n pgx = repmat(x,1,5);\n pgy = repmat(y,1,5);\n area = 0;\n perimeter = 0;\n return\n case 2\n % only two points. also simple.\n pgx = x([1 2 2 1 1]);\n pgy = y([1 2 2 1 1]);\n area = 0;\n perimeter = 2*sqrt(diff(x).^2 + diff(y).^2);\n return\nend\n% 3 or more points.\n\n% will need a 2x2 rotation matrix through an angle theta\nRmat = @(theta) [cos(theta) sin(theta);-sin(theta) cos(theta)];\n\n% get the angle of each edge of the hull polygon.\nnx = length(x);\nind1 = 1:nx;\nind2 = circshift(ind1,[0 -1]);\nedgeangles = atan2(y(ind2) - y(ind1),x(ind2) - x(ind1));\n% move the angle to be in [0,pi).\nedgeangles = mod(edgeangles,pi);\n\n% now just check each edge of the convex hull\nnang = length(edgeangles);\narea = inf;\nperim = inf;\nmet = inf;\nxy = [x,y];\nfor i = 1:nang\n % line that defines the base of the parallelogram\n p1 = xy(i,:);\n \n % we will rotate and translate the points so this\n % edge lies on the x axis. The rotation matrix is...\n rot = Rmat(-edgeangles(i));\n xyr = (xy - repmat(p1,nx,1))*rot;\n \n % the height of the parallelogram is\n if max(xyr(:,2)) >= max(-xyr(:,2))\n pgheight = max(xyr(:,2));\n else\n pgheight = min(xyr(:,2));\n end\n \n % rotate everything, but keep the angles in the interval [0,pi)\n anglesr = mod(edgeangles - edgeangles(i),pi);\n \n % what are the smallest and largest possible angles of the\n % remaining edges? This will define the limits of where the\n % secondary sides of the bounding parallelogram may lie.\n anglesr(i) = [];\n anglesr(anglesr == 0) = [];\n anglebounds = [min(anglesr), max(anglesr)];\n \n % use fminbnd to search over the family of parallelograms with\n % the given base.\n sideang = fminbnd(@(ang) pgramobj(ang,xyr,pgheight),anglebounds(1),anglebounds(2));\n \n % get the final parallelogram\n [pmin,amin,pgxy] = pgramobj(sideang,xyr,pgheight);\n \n if metric=='a'\n M_i = amin;\n else\n M_i = pmin;\n end\n \n % A new metric value for the current interval.\n % Is it better than the previous best?\n if M_i < met\n % keep this one\n met = M_i;\n area = amin;\n perim = pmin;\n \n % recover the parallelogram in the original coordinate system\n pgxy = pgxy*rot' + repmat(p1,5,1);\n \n pgx = pgxy(:,1);\n pgy = pgxy(:,2);\n \n% plot(x,y,'kx',pgx,pgy,'-ro')\n% title(num2str([perim,area]))\n% axis equal\n% pause\n \n end\nend\n\n% all done\n% plot(x,y,'kx',pgx,pgy,'-ro')\n% title(num2str([perim,area]))\n% axis equal\n\n% =================================================================\nfunction [perim,area,pgxy] = pgramobj(ang,xyr,pgheight)\n% For a given angle (in radians) computes the bounding\n% parallelogram where the base is assumed to lie on the\n% x axis. Thus the upper face must be parallel to the x axis.\n\n% ang will always be in the open interval (0,pi)\n\n% The vector that points along the sides will be\nsidevec = [cos(ang),sin(ang)];\n\n% for this value of ang, what is the normal vector to\n% that side of the parallelogram? It always points in\n% the positive x direction, by the way it is constructed.\nnvec = [sin(ang);-cos(ang)];\n\n% What is the left most point that a side will hit against?\n% The rightmost? get that information from a dot product of\n% the points with the normal vector of the sides.\ndp = xyr*nvec;\nleftmost = min(dp);\nrightmost = max(dp);\n\n% a point on the line that contains the left side of the\n% parallelogram is \nleftpoint = leftmost*nvec.';\n\n% and the right hand side line passes through this point.\nrightpoint = rightmost*nvec.';\n\n% we can define each line by the parametric equations\n% Pleft(t) = leftpoint + t*sidevec\n% Pright(t) = rightpoint + s*sidevec\n% \n% now find the values of s and t, such that those lines\n% intersect the x axis (thus y == 0)\nt0 = -leftpoint(2)./sidevec(2);\ns0 = -rightpoint(2)./sidevec(2);\n\n% the actual x axis intercepts are at\nx1 = leftpoint(1) + t0*sidevec(1);\nx2 = rightpoint(1) + s0*sidevec(1);\n\n% the length of a side of the parallelogram is given by the\n% definition of the trig function from triangle sides.\nsidelength = pgheight./cos(pi/2 - ang);\nbaselength = abs(x2 - x1);\n\n% so the perimeter of the parallellogram is given by\nperim = 2*(abs(sidelength) + baselength);\n\n% don't bother to do these unless necessary\nif nargout > 1\n % the area is also trivial to compute, as\n area = abs(pgheight)*baselength;\n \n % and the vertices of the parallelogram are\n pgxy = [[x1,0]; [x2,0]; ...\n [x2,0] + sidelength*sidevec ; ...\n [x1,0] + sidelength*sidevec ; ...\n [x1,0]];\n \nend\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/34767-a-suite-of-minimal-bounding-objects/MinBoundSuite/minboundparallelogram.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8807970858005139, "lm_q1q2_score": 0.8036711090298352}} {"text": "function [xi,w]=thirdOrderCrossPolyCubPoints(numDim,algorithm)\n%%THIRDORDERCROSSPOLYCUBPOINTS Generate third order cubature points for\n% integration over the region sum(abs(x))<=1 with weighting\n% function w(x)=1. In two dimensions, this is a square, in\n% three an octohedron, in n a cross polytope (or\n% n-dimensional octahedron).\n%\n%INPUTS: numDim An integer specifying the dimensionality of the points to\n% be generated.\n% algorithm A value indicating which algorithm should be used. Possible\n% values are:\n% 0 (The default if omitted or an empty matrix is passed)\n% Formula G_n 3-1 in [1], pg. 304, 2*numDim points.\n% 1 Formula G_n 3-2 in [1], pg. 304, 2^numDim points,\n% numDim<4.\n%\n%OUTPUTS: xi A numDim X numCubaturePoints matrix containing the cubature\n% points. (Each \"point\" is a vector)\n% w A numCubaturePoints X 1 vector of the weights associated with\n% the cubature points.\n%\n%REFERENCES:\n%[1] A.H. Stroud, Approximate Calculation of Multiple Integrals. Cliffs,\n% NJ: Prentice-Hall, Inc., 1971.\n%\n%November 2015 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release\n\nif(nargin<2||isempty(algorithm))\n algorithm=0; \nend\n\nswitch(algorithm)\n case 0%G_n 3-1 in [1], pg. 304, 2*numDim points.\n V=exp(numDim*log(2)-gammaln(numDim+1));\n n=numDim;\n \n r=sqrt(2*n/((n+1)*(n+2)));\n \n w=V/(2*n)*ones(2*n,1);\n xi=fullSymPerms([r;zeros(numDim-1,1)]);\n case 1%G_n 3-2 in [1], pg. 304, 2^numDim points, numDim<4.\n if(numDim>=4)\n error('This algorithm requires numDim<4')\n end\n \n V=exp(numDim*log(2)-gammaln(numDim+1));\n n=numDim;\n \n r=sqrt(2/((n+1)*(n+2)));\n \n w=2^(-n)*V*ones(2^n,1);\n xi=PMCombos(r*ones(numDim,1));\n otherwise\n error('Unknown algorithm specified'); \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/Numerical_Integration/Cubature_Points/Cross_Polytope/thirdOrderCrossPolyCubPoints.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958426, "lm_q2_score": 0.8807970685907242, "lm_q1q2_score": 0.8036710933270007}} {"text": "function area = polygon_area_2 ( n, v )\n\n%*****************************************************************************80\n%\n%% POLYGON_AREA_2 computes the area of a polygon.\n%\n% Discussion:\n%\n% The area is the sum of the areas of the triangles formed by\n% node N with consecutive pairs of nodes.\n%\n% If the vertices are given in counterclockwise order, the area\n% will be positive. If the vertices are given in clockwise order,\n% the area will be negative.\n%\n% Thanks to Martin Pineault for noticing that an earlier version\n% of this routine would not correctly compute the area of a nonconvex\n% polygon.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 May 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Adrian Bowyer, 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(2,N), the coordinates of the vertices.\n%\n% Output, real AREA, the area of the polygon.\n%\n area = 0.0;\n\n for i = 1 : n - 2\n\n area_triangle = triangle_area ( ...\n v(1,i), v(2,i), ...\n v(1,i+1), v(2,i+1), ...\n v(1,n), v(2,n) );\n\n area = area + area_triangle;\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/polygon_properties/polygon_area_2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222396, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.8036654638403365}} {"text": "function f = make_gaussian_filter(sigma, cutoff)\n%MAKE_GAUSSIAN_FILTER Create Gaussian filter\n% MAKE_GAUSSSIAN_FILTER(SIGMA[, CUTOFF]) creates a Gaussian filter with\n% standard deviation SIGMA. The filter mask is cut off at CUTOFF times\n% the standard deviation. If CUTOFF is omitted, a default value of 3\n% is assumed.\n%\n% See also FSPECIAL.\n% \n% Author: Stefan Roth, Department of Computer Science, TU Darmstadt\n% Contact: sroth@cs.tu-darmstadt.de\n% $Date$\n% $Revision$\n\n% Copyright 2004-2007, Brown University, Providence, RI. USA\n% Copyright 2007-2010 TU Darmstadt, Darmstadt, Germany.\n% \n% All Rights Reserved\n% \n% All commercial use of this software, whether direct or indirect, is\n% strictly prohibited including, without limitation, incorporation into in\n% a commercial product, use in a commercial service, or production of other\n% artifacts for commercial purposes. \n%\n% Permission to use, copy, modify, and distribute this software and its\n% documentation for research purposes is hereby granted without fee,\n% provided that the above copyright notice appears in all copies and that\n% both that copyright notice and this permission notice appear in\n% supporting documentation, and that the name of the author and Brown\n% University not be used in advertising or publicity pertaining to\n% distribution of the software without specific, written prior permission. \n%\n% For commercial uses contact the Technology Venture Office of Brown University\n% \n% THE AUTHOR AND BROWN UNIVERSITY DISCLAIM ALL WARRANTIES WITH REGARD TO\n% THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n% FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR OR\n% BROWN UNIVERSITY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL\n% DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\n% PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\n% ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\n% THIS SOFTWARE. \n \n if (nargin < 2)\n cutoff = 3;\n end\n \n sz = ceil(cutoff * sigma);\n \n f = exp(-(-sz:sz).^2 / (2*sigma^2));\n f = f ./ sum(f);", "meta": {"author": "kristinbranson", "repo": "JAABA", "sha": "5d778a23e3e7cf272df9a89a72b1b66d94f535d7", "save_path": "github-repos/MATLAB/kristinbranson-JAABA", "path": "github-repos/MATLAB/kristinbranson-JAABA/JAABA-5d778a23e3e7cf272df9a89a72b1b66d94f535d7/spaceTime/optflow_deqing/utils/make_gaussian_filter.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723468, "lm_q2_score": 0.8705972818382005, "lm_q1q2_score": 0.8035953948457862}} {"text": "function Z = projectData(X, U, K)\n%PROJECTDATA Computes the reduced data representation when projecting only\n%on to the top k eigenvectors\n% Z = projectData(X, U, K) computes the projection of\n% the normalized inputs X into the reduced dimensional space spanned by\n% the first K columns of U. It returns the projected examples in Z.\n%\n\n% You need to return the following variables correctly.\nZ = zeros(size(X, 1), K);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the projection of the data using only the top K\n% eigenvectors in U (first K columns).\n% For the i-th example X(i,:), the projection on to the k-th\n% eigenvector is given as follows:\n% x = X(i, :)';\n% projection_k = x' * U(:, k);\n%\n\n\n% for i=1: size(X,1);\n% x = X(i, :)';\n% for k=1: K;\n% Z(i, k) = x' * U(:, k);\n% end\n% end\n\nU_reduce = U(:, 1:K);\nZ = X * U_reduce;\n\n\n% =============================================================\n\nend\n", "meta": {"author": "benoitvallon", "repo": "coursera-machine-learning", "sha": "74ec09a5072eb5f3fec942fee45076e4f05b35af", "save_path": "github-repos/MATLAB/benoitvallon-coursera-machine-learning", "path": "github-repos/MATLAB/benoitvallon-coursera-machine-learning/coursera-machine-learning-74ec09a5072eb5f3fec942fee45076e4f05b35af/machine-learning-ex7/ex7/projectData.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669026, "lm_q2_score": 0.885631470799559, "lm_q1q2_score": 0.8035442592976636}} {"text": "function [ r, pc ] = tetrahedron_insphere_3d ( tetra )\n\n%*****************************************************************************80\n%\n%% TETRAHEDRON_INSPHERE_3D finds the insphere of a tetrahedron in 3D.\n%\n% Discussion:\n%\n% The insphere of a tetrahedron is the inscribed sphere, which touches\n% each face of the tetrahedron at a single point.\n%\n% The points of contact are the centroids of the triangular faces\n% of the tetrahedron. Therefore, the point of contact for a face\n% can be computed as the average of the vertices of that face.\n%\n% The sphere can then be determined as the unique sphere through\n% the four given centroids.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 December 2010\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Philip Schneider, David Eberly,\n% Geometric Tools for Computer Graphics,\n% Elsevier, 2002,\n% ISBN: 1558605940,\n% LC: T385.G6974.\n%\n% Parameters:\n%\n% Input, real TETRA(3,4), the vertices of the tetrahedron.\n%\n% Output, real R, PC(3,1), the radius and the center\n% of the sphere.\n%\n dim_num = 3;\n\n v21(1:dim_num,1) = tetra(1:dim_num,2) - tetra(1:dim_num,1);\n v31(1:dim_num,1) = tetra(1:dim_num,3) - tetra(1:dim_num,1);\n v41(1:dim_num,1) = tetra(1:dim_num,4) - tetra(1:dim_num,1);\n v32(1:dim_num,1) = tetra(1:dim_num,3) - tetra(1:dim_num,2);\n v42(1:dim_num,1) = tetra(1:dim_num,4) - tetra(1:dim_num,2);\n v43(1:dim_num,1) = tetra(1:dim_num,4) - tetra(1:dim_num,3);\n\n n123 = r8vec_cross_product_3d ( v21, v31 );\n n124 = r8vec_cross_product_3d ( v41, v21 );\n n134 = r8vec_cross_product_3d ( v31, v41 );\n n234 = r8vec_cross_product_3d ( v42, v32 );\n\n l123 = norm ( n123 );\n l124 = norm ( n124 );\n l134 = norm ( n134 );\n l234 = norm ( n234 );\n\n pc(1:dim_num,1) = ( l234 * tetra(1:dim_num,1) ...\n + l134 * tetra(1:dim_num,2) ...\n + l124 * tetra(1:dim_num,3) ...\n + l123 * tetra(1:dim_num,4) ) ...\n / ( l234 + l134 + l124 + l123 );\n\n b(1:dim_num,1:4) = tetra(1:dim_num,1:4);\n b(4,1:4) = 1.0;\n\n gamma = abs ( r8mat_det_4d ( b ) );\n\n r = gamma / ( l234 + l134 + l124 + l123 );\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/tetrahedron_insphere_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679977, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.8033617426090688}} {"text": "function cdf = log_series_cdf ( x, a )\n\n%*****************************************************************************80\n%\n%% LOG_SERIES_CDF evaluates the Logarithmic Series CDF.\n%\n% Discussion:\n%\n% Simple summation is used, with a recursion to generate successive\n% values of the PDF.\n%\n% Thanks to Oscar van Vlijmen.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 December 1999\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer X, the argument of the PDF.\n% 0 < X\n%\n% Input, real A, the parameter of the PDF.\n% 0.0 < A < 1.0.\n%\n% Output, real CDF, the value of the CDF.\n%\n cdf = 0.0;\n\n for x2 = 1 : x\n\n if ( x2 == 1 )\n pdf = - a / log ( 1.0 - a );\n else\n pdf = ( x2 - 1 ) * a * pdf / x2;\n end\n\n cdf = cdf + pdf;\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/prob/log_series_cdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897492587142, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.803352359491872}} {"text": "function [A,b,x] = shaw(n)\n%SHAW Test problem: one-dimensional image restoration model.\n%\n% [A,b,x] = shaw(n)\n%\n% Discretization of a first kind Fredholm integral equation with\n% [-pi/2,pi/2] as both integration intervals. The kernel K and\n% the solution f, which are given by\n% K(s,t) = (cos(s) + cos(t))*(sin(u)/u)^2\n% u = pi*(sin(s) + sin(t))\n% f(t) = a1*exp(-c1*(t - t1)^2) + a2*exp(-c2*(t - t2)^2) ,\n% are discretized by simple quadrature to produce A and x.\n% Then the discrete right-hand b side is produced as b = A*x.\n%\n% The order n must be even.\n\n% Reference: C. B. Shaw, Jr., \"Improvements of the resolution of\n% an instrument by numerical solution of an integral equation\",\n% J. Math. Anal. Appl. 37 (1972), 83-112.\n\n% Per Christian Hansen, IMM, 08/20/91.\n\n% Check input.\nif (rem(n,2)~=0), error('The order n must be even'), end\n\n% Initialization.\nh = pi/n; A = zeros(n,n);\n\n% Compute the matrix A.\nco = cos(-pi/2 + (.5:n-.5)*h);\npsi = pi*sin(-pi/2 + (.5:n-.5)*h);\nfor i=1:n/2\n for j=i:n-i\n ss = psi(i) + psi(j);\n A(i,j) = ((co(i) + co(j))*sin(ss)/ss)^2;\n A(n-j+1,n-i+1) = A(i,j);\n end\n A(i,n-i+1) = (2*co(i))^2;\nend\nA = A + triu(A,1)'; A = A*h;\n\n% Compute the vectors x and b.\na1 = 2; c1 = 6; t1 = .8;\na2 = 1; c2 = 2; t2 = -.5;\nif (nargout>1)\n x = a1*exp(-c1*(-pi/2 + (.5:n-.5)'*h - t1).^2) ...\n + a2*exp(-c2*(-pi/2 + (.5:n-.5)'*h - t2).^2);\n b = A*x;\nend", "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/shaw.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.803349856100833}} {"text": "% QP test problem. Demo file\n%\nclc;\n\ndisp('----------------------------------');\ndisp('Problem #1:');\ndisp(' ');\ndisp('min x1^2 + x^2 - 3*x1 - 1/4*x2');\ndisp(' ');\ndisp('subject to');\ndisp(' |x1|+|x2| <= 1');\ndisp('----------------------------------');\n\nH=2*eye(2);\nq=[-3,-1/4]';\nA=[1 1;1 -1;-1 1;-1 -1];\nb=ones(4,1);\n\n[x, obj, lambda, info] = qpng (H, q, A, b)\n\npause;\nclc\n\ndisp('----------------------------------');\ndisp('Problem #2:');\ndisp(' ');\ndisp('min 4*x1^2 + 1 x1*x2 + 4*x2^2 + 3*x1 ? 4*x2');\ndisp(' ');\ndisp('s.t. x1+x2 <= 5');\ndisp(' x1-x2 == 0');\ndisp(' x1 >= 0');\ndisp(' x2 >= 0');\ndisp('----------------------------------');\n\nH=[8 1;1 8];\nq=[3 -4]';\nA=[1 1; 1 -1];\nb=[5 0]';\nctype=char(['U', 'E']');\nlb=[0 0]';\nub=[];\n\n[x, obj, lambda, info] = qpng (H, q, A, b,ctype,lb,ub)\n\npause;\nclc\n\ndisp('----------------------------------');\ndisp('Problem #3:');\ndisp(' ');\ndisp('min .5*x1''*H*x + q''*x');\ndisp(' ');\ndisp('s.t. -2.5 <= x1 <= 2.5');\ndisp('----------------------------------');\n\nH=[.16 -1.2 2.4 -1.4;\n -1.2 12.0 -27.0 16.8;\n 2.4 -27.0 64.8 -42.0;\n -1.4 16.8 -42.0 28.0];\nq=[5.04 -59.4 146.4 -96.6]';\nA=[-1 0 0 0; 1 0 0 0];\nb=[2.5; 2.5];\n\n[x, obj, lambda, info] = qpng (H, q, A, b)\n\npause;\nclc\n\ndisp('----------------------------------');\ndisp('Problem #4:');\ndisp(' Solve a portfolio example. ');\ndisp(' See Section 13.7 of \"Applications of optimization with Xpress-MP.');\ndisp('----------------------------------');\n\nH=[4 3 -1 0;\n 3 6 1 0;\n -1 1 10 0;\n 0 0 0 10];\nq=[];\nA=[1 1 1 1;\n 8 9 12 7];\nb=[1; 7];\nctype=char(['E', 'L']');\nlb=zeros(4,1);\nub=[];\n\n[x, obj, lambda, info] = qpng (H, q, A, b, ctype, lb, ub)\n\npause;\nclc\n\ndisp('----------------------------------');\ndisp('Problem #5:');\ndisp(' An indefinite QP problem is not solved x*=(3, 25/4). ');\ndisp(' ');\ndisp('min .5*x1^2 - .5*x2^2');\ndisp(' ');\ndisp('s.t. x2 >= 0');\ndisp('s.t. x1+x2 >= 2');\ndisp('s.t. -5x1+4x2 <= 10');\ndisp('s.t. x1 <= 3');\ndisp('----------------------------------');\n\nH=[1 0;0 -1];\nq=[];\nA=[0 1;1 2;-5 4;1 0];\nb=[0 2 10 3]';\nctype=char(['L', 'L', 'U', 'U']);\n\n[x, obj, lambda, info]=qpng(H, q, A, b)", "meta": {"author": "opencobra", "repo": "cobratoolbox", "sha": "e60274d127f65d518535fd0814d20c53dc530f73", "save_path": "github-repos/MATLAB/opencobra-cobratoolbox", "path": "github-repos/MATLAB/opencobra-cobratoolbox/cobratoolbox-e60274d127f65d518535fd0814d20c53dc530f73/external/base/solvers/glpkmex/qptest.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810511092412, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.8033485807788767}} {"text": "function [r, c] = partial_corr_coef(S, i, j, Y)\n% PARTIAL_CORR_COEF Compute a partial correlation coefficient\n% [r, c] = partial_corr_coef(S, i, j, Y)\n%\n% S is the covariance (or correlation) matrix for X, Y, Z\n% where X=[i j], Y is conditioned on, and Z is marginalized out.\n% Let S2 = Cov[X | Y] be the partial covariance matrix.\n% Then c = S2(i,j) and r = c / sqrt( S2(i,i) * S2(j,j) ) \n%\n\n% Example: Anderson (1984) p129\n% S = [1.0 0.8 -0.4;\n% 0.8 1.0 -0.56;\n% -0.4 -0.56 1.0];\n% r(1,3 | 2) = 0.0966 \n%\n% Example: Van de Geer (1971) p111\n%S = [1 0.453 0.322;\n% 0.453 1.0 0.596;\n% 0.322 0.596 1];\n% r(2,3 | 1) = 0.533\n\nX = [i j];\ni2 = 1; % find_equiv_posns(i, X);\nj2 = 2; % find_equiv_posns(j, X);\nS2 = S(X,X) - S(X,Y)*inv(S(Y,Y))*S(Y,X);\nc = S2(i2,j2);\nr = c / sqrt(S2(i2,i2) * S2(j2,j2));\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/dmlt/external/murphy/KPMstats/partial_corr_coef.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338101862454, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.8033456648401671}} {"text": "function [x,gpd,nu]=gdpower(N,k,c)\n%GDPOWER Signal with power-law group delay.\n%\t[X,GPD,F]=GDPOWER(N,K,C) generates a signal with a\n%\tpower-law group delay of the form tx(f) = T0 + C*f^(K-1).\n%\tThe output signal is of unit energy.\n%\n%\tN : number of points in time\t\t(must be even)\n%\tK : degree of the power-law\t\t(default : 0)\n%\tC : rate-coefficient of the power-law group delay. \n%\t C must be non-zero. \t\t(default : 1)\t\n%\tX : time row vector containing the modulated signal samples\n%\tGPD : group delay\t (length : round(N/2)-1)\n%\tF : frequency bins\n%\n%\tExamples : \n%\t sig=gdpower(64,0); tfrbert(sig,1:64,0.01,0.32,256,1);\n%\t [sig,gpd,f]=gdpower(256,1/2); plot(gpd,f); \n%\n%\tSee also FMPOWER.\n\n%\tO. Lemoine - April, July 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 (nargin < 1),\n error ( 'At least one parameter.' );\nelseif nargin==1,\n k=0; c=1;\nelseif nargin==2,\n c=1;\nend\n\nif (N <= 0),\n error ('The signal length N must be strictly positive' );\nend \n\nt0=0;\n\nLnu=round(N/2);\nnu=linspace(0,0.5,Lnu+1); nu=nu(2:Lnu+1);\nAM=nu.^((k-2)/6);\n\nif c==0,\n error('C must be non-zero');\nend\n\nt=1:N;\nTFx=zeros(1,N);\n\nif (k<1 & k~=0),\n d=N^k*c; t0=N/10;\n TFx(1:Lnu)=exp(-j*2*pi*(t0*(nu)+d*(nu).^k/k)).*AM;\n x=ifft(TFx).';\nelseif k==0,\n d=c; t0=N/10;\n TFx(1:Lnu)=exp(-j*2*pi*(t0*(nu)+d*log(nu))).*AM;\n x=ifft(TFx).';\nelseif k==1,\n t0=N;\n x=anapulse(N,t0);\nelseif (k>1),\n d=N*2^(k-1)*c; \n TFx(1:Lnu)=exp(-j*2*pi*(t0*(nu)+d*(nu).^k/k)).*AM;\n x=ifft(TFx).';\nend\n\nif k~=1,\n gpd=t0+abs(sign(c)-1)/2*(N+1)+d*nu.^(k-1);\nelse\n gpd=t0*ones(1,N/2);\nend\n\nx=x-mean(x);\nx=x/norm(x);\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/gdpower.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915913, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.8033441606026129}} {"text": "function loc=LMSloc(X)\n%Syntax: loc=LMSloc(X)\n%_____________________\n%\n% Calculates the Least Median of Squares (LMS) location parameter \n% of the columns of a matrix X. If X is a vector, it returns the LMS\n% location parameter of its components. If X is a scalar, it returns\n% X.\n%\n% loc is the LMS estimated vector of locations.\n% X is the matrix with the data sets.\n%\n% Reference:\n% Rousseeuw PJ, Leroy AM (1987): Robust regression and outlier detection. Wiley.\n%\n%\n% Alexandros Leontitsis\n% Institute of Mathematics and Statistics\n% University of Kent at Canterbury\n% Canterbury\n% Kent, CT2 7NF\n% U.K.\n%\n% University e-mail: al10@ukc.ac.uk (until December 2002)\n% Lifetime e-mail: leoaleq@yahoo.com\n% Homepage: http://www.geocities.com/CapeCanaveral/Lab/1421\n%\n% Sep 3, 2001.\n\nif nargin<1 | isempty(X)==1\n error('Not enough input arguments.');\nelse\n % X must be 2-dimensional\n if ndims(X)>2\n error('Invalid data set.');\n end\n % If X is a row vector make it a column vector\n if size(X,1)==1\n X=X';\n end\n \n % n is the length of the data set\n n=size(X,1);\nend\n\n% For a single data point there is no need to proceed\nif n==1\n loc=X;\nelse\n % Sort the data set to ascending order\n X=sort(X);\n \n % P. 169: the length of the \"half\" of the data points\n h=floor(n/2)+1;\n \n % P. 169: determine the shortest half and compute its midpoint\n j=1:n-h+1;\n range=X(j+h-1,:)-X(j,:);\n \n % Calculate the location parameter for every column of X\n for i=1:size(X,2);\n f=find(range(:,i)==min(range(:,i)));\n loc(i)=median((X(f+h-1,i)+X(f,i))/2);\n end\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/801-lms-toolbox/LMSloc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951607140232, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.8032656516772686}} {"text": "function z = g_three ( x, y )\n\n%*****************************************************************************80\n%\n%% G_THREE evaluates a function which has 6 minima, 2 global, in [-3,3]x[-2,2].\n%\n% Discussion:\n%\n% Actually, F_THREE evaluates that function; this function returns the \n% log of that function plus 2, which is useful when trying to draw contours.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 March 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X, Y, the arguments.\n%\n% Output, real Z, the function value.\n%\n z = ( 4.0 - 2.1 * x.^2 + x.^4 / 3.0 ) .* x.^2 ...\n + x .* y + ( - 4.0 + 4.0 * y.^2 ) .* y.^2;\n\n z = log ( 2 + z );\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/spinterp_examples/g_three.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678381, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.8032656497790184}} {"text": "function z = log_sigmoid(x)\n% computes and returns the logistic sigmoid of x. Operation is performed \n% element-wise if x is a vector or matrix.\n%\n% z = 1 ./ (1-exp(-x))\n\nz = (1+exp(-x)).^-1;\n\nend", "meta": {"author": "OHBA-analysis", "repo": "HMM-MAR", "sha": "bb0433b75482e473980791a2b30afe2012cf6578", "save_path": "github-repos/MATLAB/OHBA-analysis-HMM-MAR", "path": "github-repos/MATLAB/OHBA-analysis-HMM-MAR/HMM-MAR-bb0433b75482e473980791a2b30afe2012cf6578/utils/math/log_sigmoid.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.8723473647220787, "lm_q1q2_score": 0.8032484472267896}} {"text": "function v = r8vec_house_column ( n, a_vec, 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_VEC(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_vec = a_vec(:);\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_vec(k:n,1).^2 ) );\n\n if ( s == 0.0 )\n return\n end\n\n if ( a_vec(k,1) < 0.0 )\n v(k,1) = a_vec(k,1) - abs ( s ) ;\n else\n v(k,1) = a_vec(k,1) + abs ( s );\n end\n v(k+1:n,1) = a_vec(k+1:n,1);\n%\n% Normalize V.\n%\n s = sqrt ( sum ( v(k:n,1).^2 ) );\n\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/r8lib/r8vec_house_column.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.867035763237924, "lm_q1q2_score": 0.8031384617855524}} {"text": "function [ q_min, q_max, q_ave, q_area ] = q_measure ( n, z, triangle_order, ...\n triangle_num, triangle_node )\n\n%*****************************************************************************80\n%\n%% Q_MEASURE determines the triangulated pointset quality measure Q.\n%\n% Discussion:\n%\n% The Q measure evaluates the uniformity of the shapes of the triangles\n% defined by a triangulated pointset.\n%\n% For a single triangle T, the value of Q(T) is defined as follows:\n%\n% TAU_IN = radius of the inscribed circle,\n% TAU_OUT = radius of the circumscribed circle,\n%\n% Q(T) = 2 * TAU_IN / TAU_OUT\n% = ( B + C - A ) * ( C + A - B ) * ( A + B - C ) / ( A * B * C )\n%\n% where A, B and C are the lengths of the sides of the triangle T.\n%\n% The Q measure computes the value of Q(T) for every triangle T in the\n% triangulation, and then computes the standard deviation of this\n% set of values:\n%\n% Q_MEASURE = min ( all T in triangulation ) Q(T)\n%\n% In an ideally regular mesh, all triangles would have the same\n% equilateral shape, for which Q = 1. In a good mesh, 0.5 < Q.\n%\n% Given the 2D coordinates of a set of N nodes, stored as Z(1:2,1:N),\n% a triangulation is a list of NT triples of node indices that form\n% triangles. Generally, a maximal triangulation is expected, namely,\n% a triangulation whose image is a planar graph, but for which the\n% addition of any new triangle would mean the graph was no longer planar.\n% A Delaunay triangulation is a maximal triangulation which maximizes\n% the minimum angle that occurs in any triangle.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 21 June 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Per-Olof Persson and Gilbert Strang,\n% A Simple Mesh Generator in MATLAB,\n% SIAM Review,\n% Volume 46, Number 2, pages 329-345, June 2004.\n%\n% Parameters:\n%\n% Input, integer N, the number of points.\n%\n% Input, real Z(DIM_NUM,N), the points.\n%\n% Input, integer TRIANGLE_ORDER, the order of the triangles.\n%\n% Input, integer TRIANGLE_NUM, the number of triangles.\n%\n% Input, integer TRIANGLE_NODE(TRIANGLE_ORDER,TRIANGLE_NUM), the triangulation.\n%\n% Output, real ( kind = 8 ) Q_MIN, Q_MAX, the minimum and maximum values\n% of Q over all triangles.\n%\n% Output, real ( kind = 8 ) Q_AVE, the average value of Q.\n%\n% Output, real ( kind = 8 ) Q_AREA, the average value of Q, weighted by\n% the area of each triangle.\n%\n q_min = r8_huge ( );\n q_max = - r8_huge ( );\n q_ave = 0.0;\n q_area = 0.0;\n area_total = 0.0;\n\n for triangle = 1 : triangle_num\n\n a_index = triangle_node(1,triangle);\n b_index = triangle_node(2,triangle);\n c_index = triangle_node(3,triangle);\n\n ab_length = sqrt ( ...\n ( z(1,a_index) - z(1,b_index) )^2 ...\n + ( z(2,a_index) - z(2,b_index) )^2 );\n\n bc_length = sqrt ( ...\n ( z(1,b_index) - z(1,c_index) )^2 ...\n + ( z(2,b_index) - z(2,c_index) )^2 );\n\n ca_length = sqrt ( ...\n ( z(1,c_index) - z(1,a_index) )^2 ...\n + ( z(2,c_index) - z(2,a_index) )^2 );\n\n q = ( bc_length + ca_length - ab_length ) ...\n * ( ca_length + ab_length - bc_length ) ...\n * ( ab_length + bc_length - ca_length ) ...\n / ( ab_length * bc_length * ca_length );\n\n x1 = z(1,triangle_node(1,triangle));\n y1 = z(2,triangle_node(1,triangle));\n x2 = z(1,triangle_node(2,triangle));\n y2 = z(2,triangle_node(2,triangle));\n x3 = z(1,triangle_node(3,triangle));\n y3 = z(2,triangle_node(3,triangle));\n\n area = 0.5 * abs ( x1 * ( y2 - y3 ) ...\n + x2 * ( y3 - y1 ) ...\n + x3 * ( y1 - y2 ) );\n\n q_min = min ( q_min, q );\n q_max = max ( q_max, q );\n q_ave = q_ave + q;\n q_area = q_area + q * area;\n\n area_total = area_total + area;\n\n end\n\n q_ave = q_ave / triangle_num;\n\n if ( 0.0 < area_total )\n q_area = q_area / area_total;\n else\n q_area = 0.0;\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/triangulation/q_measure.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.8670357512127872, "lm_q1q2_score": 0.8031384506466233}} {"text": "function fx = p18_fun ( n, x )\n\n%*****************************************************************************80\n%\n%% P18_FUN evaluates the integrand for problem 18.\n%\n% Integral:\n%\n% Integral ( 0 <= x < +oo ) x^2 * exp ( - x / 2^beta ) dx\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 December 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Robert Piessens, Elise de Doncker-Kapenga,\n% Christian Ueberhuber, David Kahaner,\n% QUADPACK: A Subroutine Package for Automatic Integration,\n% Springer, 1983, page 84.\n%\n% Parameters:\n%\n% Input, integer N, the number of points.\n%\n% Input, real X(N), the point at which the integrand\n% is to be evaluated.\n%\n% Output, real FX(N), the value of the integrand at X.\n%\n beta = 1.0;\n\n fx(1:n) = x(1:n).^2 .* exp ( - x(1:n) / 2^beta );\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/laguerre_test_int/p18_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850004144265, "lm_q2_score": 0.8577681068080748, "lm_q1q2_score": 0.8031154122382802}} {"text": "function ex4bvp\n%EX4BVP Example 4 of the BVP tutorial.\n% This is a nerve impulse model considered in Example 7.1 of\n% R. Seydel, From Equilibrium to Chaos, Elsevier, 1988. The\n% differential equations\n%\n% y1' = 3*(y1 + y2 - 1/3*y1^3 + lambda)\n% y2' = -(y1 - 0.7 + 0.8*y2)/3\n%\n% are to be solved subject to periodic boundary conditions\n%\n% y1(0) = y1(T)\n% y2(0) = y2(T)\n%\n% This is an example of non-separated boundary conditions, meaning\n% that some conditions involve values of the solution at both ends\n% of the interval. Periodic boundary conditions are a common source\n% of such problems. BVP4C is unusual in that it accepts problems\n% with non-separated boundary conditions.\n%\n% The parameter lambda has the value -1.3 in the text cited. The\n% period T is unknown, which is to say that the length of the \n% interval is not known. Such problems require some preparation. \n% By scaling the independent variable to tau = t/T the problem is \n% posed on the fixed interval [0,1]. When this is done, T becomes \n% an unknown parameter, but BVP4C provides for unknown parameters.\n\n% Copyright 2002, The MathWorks, Inc.\n\n% Periodic functions evaluated in EX4INIT are used as a guess for the\n% solution on a crude mesh of 5 equally spaced points. A guess of 2*pi \n% is provided for the unknown parameter T.\nsolinit = bvpinit(linspace(0,1,5),@ex4init,2*pi);\n\noptions = bvpset('stats','on');\n\nsol = bvp4c(@ex4ode,@ex4bc,solinit,options);\nT = sol.parameters;\n\n% The independent variable needs to be rescaled to its original value\n% before plotting the solution. The initial guess is also plotted.\nfigure\nplot(T*sol.x,sol.y(1,:),T*solinit.x,solinit.y(1,:),'o')\nlegend('solution found','initial guess');\naxis([0 T -2.2 2]);\ntitle('Nerve impulse model');\nylabel('solution y_1(t)');\nxlabel(['Periodic solution with period ',num2str(sol.parameters,4)]);\n\n% --------------------------------------------------------------------------\n\nfunction v = ex4init(x)\n%EX4INIT Guess function for Example 4 of the BVP tutorial.\n% V = EX4INIT(X) returns a column vector V that is a guess for y(x).\nv = [ sin(2*pi*x) \n cos(2*pi*x)];\n\n% --------------------------------------------------------------------------\n\nfunction dydt = ex4ode(t,y,T);\n%EX4ODE ODE funcion for Example 4 of the BVP tutorial.\ndydt = [ 3*T*(y(1) + y(2) - 1/3*(y(1)^3) - 1.3);\n (-1/3)*T*(y(1) - 0.7 + 0.8*y(2)) ];\n\n% --------------------------------------------------------------------------\n\nfunction res = ex4bc(ya,yb,T)\n%EX4BC Boundary conditions for Example 4 of the BVP tutorial.\nres = [ya(1) - yb(1)\n ya(2) - yb(2)\n T*(-1/3)*(ya(1) - 0.7 + 0.8*ya(2)) - 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/3819-tutorial-on-solving-bvps-with-bvp4c/BVP_tutorial/BVP_examples_65/ex4bvp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.8902942239389252, "lm_q1q2_score": 0.8029747687653372}} {"text": "% Euclidean projection on a rectangle\n% Section 8.1.1, Boyd & Vandenberghe \"Convex Optimization\"\n% Joelle Skaf - 10/07/05\n%\n% The projection of x0 on a rectangle C = {x | l <= x <= u} is given by\n% minimize || x - x0 ||^2\n% s.t. l <= x <= u\n% It is also given by P_C(x0)_k = l_k if x0_k <= l_k\n% x0_k if l_k <= x0_k <= u_k\n% u_k if x0_k >= u_k\n\n% Input data: generate vectors l and u such that l < 0 < u\nn = 10;\nl = -rand(n,1);\nu = rand(n,1);\nx0 = randn(n,1);\n\n% Analytical solution\nfprintf(1,'Computing the analytical solution ...');\npc_x0 = x0;\npc_x0(find(x0<=l)) = l(find(x0<=l));\npc_x0(find(x0>=u)) = u(find(x0>=u));\nfprintf(1,'Done! \\n');\n\n% Solution via QP\nfprintf(1,'Computing the optimal solution by solving a QP ...');\n\ncvx_begin quiet\n variable x(n)\n minimize ( norm(x-x0) )\n x <= u;\n x >= l;\ncvx_end\n\nfprintf(1,'Done! \\n');\n\n% Verification\ndisp('-----------------------------------------------------------------');\ndisp('Verifying that the analytical solution and the solution obtained via QP are equal: ');\n[pc_x0 x]\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/Ch08_geometric_probs/eucl_proj_rect.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294587, "lm_q2_score": 0.8519528057272544, "lm_q1q2_score": 0.8029712482944815}} {"text": "function area = triangle_area ( vert1, vert2, vert3 )\n\n%*****************************************************************************80\n%\n%% TRIANGLE_AREA returns the area of a triangle.\n%\n% Licensing:\n%\n% This code is distributed under the GNU GPL license.\n%\n% Modified:\n%\n% 26 June 2014\n%\n% Author:\n%\n% Original FORTRAN77 version by Hong Xiao, Zydrunas Gimbutas.\n% This MATLAB version by John Burkardt.\n%\n% Reference:\n%\n% Hong Xiao, Zydrunas Gimbutas,\n% A numerical algorithm for the construction of efficient quadrature\n% rules in two and higher dimensions,\n% Computers and Mathematics with Applications,\n% Volume 59, 2010, pages 663-676.\n%\n% Parameters:\n%\n% Input, real VERT1(2), VERT2(2), VERT3(2), the vertices of\n% the triangle.\n%\n% Output, real AREA, the area of the triangle.\n%\n area = 0.5 * ...\n ( ...\n ( vert2(1) - vert1(1) ) * ( vert3(2) - vert1(2) ) ...\n - ( vert3(1) - vert1(1) ) * ( vert2(2) - vert1(2) ) ...\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/triangle_symq_rule/triangle_area.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067195846918, "lm_q2_score": 0.8519528019683105, "lm_q1q2_score": 0.8029712406241388}} {"text": "function [ x, seed ] = circular_normal_sample ( a, b, seed )\n\n%*****************************************************************************80\n%\n%% CIRCULAR_NORMAL_SAMPLE samples the Circular Normal PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 January 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real A(2), a parameter of the PDF, the mean value.\n%\n% Input, real B, a parameter of the PDF, the standard deviation.\n%\n% Input/output, integer SEED, a seed for the random\n% number generator.\n%\n% Output, real X(2), a sample of the PDF.\n%\n [ v1, seed ] = r8_uniform_01 ( seed );\n [ v2, seed ] = r8_uniform_01 ( seed );\n\n r = sqrt ( - 2.0 * log ( v1 ) );\n\n x(1) = a(1) + b * r * cos ( 2.0 * pi * v2 );\n x(2) = a(2) + b * r * sin ( 2.0 * pi * v2 );\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/circular_normal_sample.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067211996141, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.8029712366857317}} {"text": "function f = bohach2 ( m, x )\n\n%*****************************************************************************80\n%\n%% BOHACH2 evaluates the Bohachevsky function #2.\n%\n% Discussion:\n%\n% The minimizer is\n%\n% X* = [ 0.0, 0.0 ]\n% F(X*) = 0.0\n%\n% Suggested starting point:\n%\n% X = [ 0.6, 1.3 ];\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 04 January 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Zbigniew Michalewicz,\n% Genetic Algorithms + Data Structures = Evolution Programs,\n% Third Edition,\n% Springer Verlag, 1996,\n% ISBN: 3-540-60676-9,\n% LC: QA76.618.M53.\n%\n% Parameters:\n%\n% Input, integer M, the number of variables.\n%\n% Input, real X(M), the argument of the function.\n%\n% Output, real F, the value of the function at X.\n%\n f = x(1) * x(1) ... \n + 2.0 * x(2) * x(2) ...\n - 0.3 * cos ( 3.0 * pi * x(1) ) * cos ( 4.0 * pi * x(2) ) ...\n + 0.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/compass_search/bohach2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.924141826246517, "lm_q2_score": 0.8688267898240861, "lm_q1q2_score": 0.8029191762399297}} {"text": "function [X,W]=simplexquad(varargin)\n\n% simplexquad.m - Gaussian Quadrature for an n-dimensional simplex.\n%\n% Construct Gauss points and weights for a n-dimensional simplex \n% domain with vertices specified by the n*(n-1) matrix vert. Where each \n% row contains the coordinates (x1,...,xn) for a vertex. The order of\n% the quadrature scheme in each dimension must be the same in this\n% implementation.\n%\n% Sample Usage:\n%\n% [X,W]=simplexquad(n,vert); % Specify the vertices \n% [X,W]=simplexquad(n,dim); % Specify the dimension and use unit simplex \n%\n% X will be a matrix for which the jth column are the grid points in each\n% coordinate xj. \n%\n% Note: The standard n-dimensional simplex has vertices specified\n% vert=eye(n+1,n).\n%\n% The first four simplexes are\n%\n% n | Domain\n% --|------------\n% 1 | Interval \n% 2 | Triangle\n% 3 | Tetrahedron\n% 4 | Pentatope \n%\n% Written by: Greg von Winckel \n% Contact: gregvw(at)math(dot)unm(dot)edu\n% http://math.unm.edu/~gregvw\n\nnargin=length(varargin);\n\nif nargin~=2\n error('simplexquad takes two input arguments');\nend\n\nN=varargin{1}; \n\nif length(N)~=1\n error('First argument must be a scalar');\nend\n\nif N~=abs(round(N-1))+1;\n error('Number of Gauss points must be a natural number');\nend\n \nif length(varargin{2})==1 % Dimension specified\n n=varargin{2}; \n \n if n~=abs(round(n-1))+1;\n error('Dimension must be a natural number');\n end \n \n m=n+1; vert=eye(m,n); \nelse % Vertices specified\n vert=varargin{2}; \n [m,n]=size(vert);\n \n if m~=n+1 \n error('The matrix of vertices must have n+1 rows and n columns');\n end\nend\n \nNn=N^n;\n\nif n==1 % The 1-D simplex is only an interval\n [q,w]=rquad(N,0); len=diff(vert);\n X=vert(1)+len*q; W=abs(len)*w;\n\nelse % Find quadrature rules for higher dimensional domains \n\n for k=1:n \n [q{k},w{k}]=rquad(N,n-k);\n end\n\n [Q{1:n}]=ndgrid(q{:}); q=reshape(cat(n,Q{:}),Nn,n);\n [W{1:n}]=ndgrid(w{:}); w=reshape(cat(n,W{:}),Nn,n);\n\n map=eye(m); map(2:m,1)=-1; c=map*vert;\n W=abs(det(c(2:m,:)))*prod(w,2);\n\n qp=cumprod(q,2); e=ones(Nn,1);\n X=[e [(1-q(:,1:n-1)),e].*[e,qp(:,1:n-2),qp(:,n)]]*c;\nend\n\n\nfunction [x,w]=rquad(N,k)\n\nk1=k+1; k2=k+2; n=1:N; nnk=2*n+k;\nA=[k/k2 repmat(k^2,1,N)./(nnk.*(nnk+2))];\nn=2:N; nnk=nnk(n);\nB1=4*k1/(k2*k2*(k+3)); nk=n+k; nnk2=nnk.*nnk;\nB=4*(n.*nk).^2./(nnk2.*nnk2-nnk2);\nab=[A' [(2^k1)/k1; B1; B']]; s=sqrt(ab(2:N,2));\n[V,X]=eig(diag(ab(1:N,1),0)+diag(s,-1)+diag(s,1));\n[X,I]=sort(diag(X)); \nx=(X+1)/2; w=(1/2)^(k1)*ab(1,2)*V(1,I)'.^2;", "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/9435-n-dimensional-simplex-quadrature/simplexquad.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164656, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.8028945141040089}} {"text": "function divdif_test05 ( )\n\n%*****************************************************************************80\n%\n%% DIVDIF_TEST05 tests DIF_TO_R8POLY and DIF_SHIFT_ZERO.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 07 October 2006\n%\n% Author:\n%\n% John Burkardt\n%\n maxtab = 10;\n\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'DIVDIF_TEST05\\n' );\n fprintf ( 1, ' DIF_TO_R8POLY converts a difference table to a\\n' );\n fprintf ( 1, ' polynomial;\\n' );\n fprintf ( 1, ' DIF_SHIFT_ZERO shifts a divided difference\\n' );\n fprintf ( 1, ' table to all zero abscissas;\\n' );\n fprintf ( 1, '\\n' );\n fprintf ( 1, ' These are equivalent operations!\\n' );\n fprintf ( 1, '\\n' );\n%\n% Set XTAB, YTAB to X, F(X)\n%\n ntab = 4;\n\n xtab1 = r8vec_indicator ( ntab );\n\n ytab1(1:ntab) = xtab1(1:ntab).^3 - 2.0 * xtab1(1:ntab).^2 ...\n + 3.0 * xtab1(1:ntab) - 4.0;\n\n xtab2 = r8vec_indicator ( ntab );\n\n ytab2(1:ntab) = xtab2(1:ntab).^3 - 2.0 * xtab2(1:ntab).^2 ...\n + 3.0 * xtab2(1:ntab) - 4.0;\n%\n% Compute and display the finite difference table.\n%\n diftab1 = data_to_dif_display ( ntab, xtab1, ytab1 );\n\n diftab2 = data_to_dif_display ( ntab, xtab2, ytab2 );\n%\n% Examine corresponding polynomial.\n%\n dif_print ( ntab, xtab1, diftab1, ' The divided difference polynomial:' );\n%\n% Shift to zero.\n%\n [ xtab1, diftab1 ] = dif_shift_zero ( ntab, xtab1, diftab1 );\n\n r8poly_print ( ntab, diftab1, ' Using DIF_SHIFT_ZERO' );\n%\n% Shift to zero.\n%\n c = dif_to_r8poly ( ntab, xtab2, diftab2 );\n\n r8poly_print ( ntab, c, ' Using DIF_TO_R8POLY' );\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/divdif_test05.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.918480237330998, "lm_q1q2_score": 0.8028226633870247}} {"text": "function b = isPerpendicular(v1, v2, varargin)\n%ISPERPENDICULAR Check orthogonality of two vectors\n%\n% B = isPerpendicular(V1, V2)\n% where V1 and V2 are two 1-by-2 row arrays, returns 1 if the vectors are\n% perpendicular, and 0 otherwise.\n%\n% Also works when V1 and V2 are two N-by-2 arrays with same number of\n% rows. In this case, return a N-by-1 array containing 1 at the positions\n% of perpendicular vectors.\n%\n% Also works when one of V1 or V2 is 1-by-2 and the other one is a N-by-2\n% array. In this case the result has size N-by-1.\n%\n% B = isPerpendicular(V1, V2, ACCURACY)\n% specifies accuracy of numerical tests, default is 1e-14.\n%\n%\n% Example\n% isPerpendicular([1 2 1], [2 4 2])\n% ans =\n% 1\n%\n% isPerpendicular([1 2 1], [1 3 2])\n% ans =\n% 0\n%\n% See also\n% vectors2d, isParallel, lines2d\n%\n\n% ------\n% Author: David Legland\n% e-mail: david.legland@inra.fr\n% Created: 2006-04-25\n% Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas).\n\n% HISTORY\n% 2007-09-18 copy from isPerpendicular, adapt to any dimension, and add\n% psb to specify precision\n% 2009-09-21 fix bug for array of 3 vectors\n% 2011-01-20 replace repmat by ones-indexing (faster)\n% 2017-08-31 use normalized vectors\n\n% default accuracy\nacc = 1e-14;\nif ~isempty(varargin)\n acc = abs(varargin{1});\nend\n\n% normalize vectors\nv1 = normalizeVector(v1);\nv2 = normalizeVector(v2);\n\n% adapt size of inputs\nn1 = size(v1, 1);\nn2 = size(v2, 1);\nif n1 ~= n2\n if n1 == 1\n v1 = v1(ones(n2, 1), :);\n elseif n2==1\n v2 = v2(ones(n1, 1), :);\n else\n error('Inputs must either have same size, or one must be scalar');\n end\nend\n\n% performs test\nb = abs(dot(v1, v2, 2)) < acc;\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/geom2d/isPerpendicular.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.903294214513915, "lm_q2_score": 0.8887587890727755, "lm_q1q2_score": 0.802810672267831}} {"text": "function traj = ScrewTrajectory(Xstart, Xend, Tf, N, method)\n% *** CHAPTER 9: TRAJECTORY GENERATION ***\n% Takes Xstart: The initial end-effector configuration,\n% Xend: The final end-effector configuration,\n% Tf: Total time of the motion in seconds from rest to rest,\n% N: The number of points N > 1 (Start and stop) in the discrete\n% representation of the trajectory,\n% method: The time-scaling method, where 3 indicates cubic\n% (third-order polynomial) time scaling and 5 indicates \n% quintic (fifth-order polynomial) time scaling.\n% Returns traj: The discretized trajectory as a list of N matrices in SE(3)\n% separated in time by Tf/(N-1). The first in the list is \n% Xstart and the Nth is Xend .\n% This function calculates a trajectory corresponding to the screw motion \n% about a space screw axis.\n% Example Input:\n% \n% clear; clc;\n% Xstart = [[1 ,0, 0, 1]; [0, 1, 0, 0]; [0, 0, 1, 1]; [0, 0, 0, 1]];\n% Xend = [[0, 0, 1, 0.1]; [1, 0, 0, 0]; [0, 1, 0, 4.1]; [0, 0, 0, 1]];\n% Tf = 5;\n% N = 4;\n% method = 3;\n% traj = ScrewTrajectory(Xstart, Xend, Tf, N, method)\n% \n% Output:\n% traj =\n% 1.0000 0 0 1.0000\n% 0 1.0000 0 0\n% 0 0 1.0000 1.0000\n% 0 0 0 1.0000\n%\n% 0.9041 -0.2504 0.3463 0.4410\n% 0.3463 0.9041 -0.2504 0.5287\n% -0.2504 0.3463 0.9041 1.6007\n% 0 0 0 1.0000\n%\n% 0.3463 -0.2504 0.9041 -0.1171\n% 0.9041 0.3463 -0.2504 0.4727\n% -0.2504 0.9041 0.3463 3.2740\n% 0 0 0 1.0000\n%\n% -0.0000 0.0000 1.0000 0.1000\n% 1.0000 -0.0000 0.0000 -0.0000\n% 0.0000 1.0000 -0.0000 4.1000\n% 0 0 0 1.0000\n\ntimegap = Tf / (N - 1);\ntraj = cell(1, N);\nfor i = 1: N\n if method == 3\n s = CubicTimeScaling(Tf, timegap * (i - 1));\n else\n s = QuinticTimeScaling(Tf, timegap * (i - 1));\n end\n traj{i} = Xstart * MatrixExp6(MatrixLog6(TransInv(Xstart) * Xend) * s);\nend\nend\n\n", "meta": {"author": "ShuoYangRobotics", "repo": "QuadrupedSim", "sha": "8427715395b63bddb77329e66f7484e529998445", "save_path": "github-repos/MATLAB/ShuoYangRobotics-QuadrupedSim", "path": "github-repos/MATLAB/ShuoYangRobotics-QuadrupedSim/QuadrupedSim-8427715395b63bddb77329e66f7484e529998445/mr/ScrewTrajectory.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.8774767778695834, "lm_q1q2_score": 0.8028043461291077}} {"text": "function [log_rad,angle]=base(m,n)\n% Compute radius and angle matrix base for a given size of m,n\n% Input:\n% m: number of rows\n% n: number of cols\n% Output:\n% log_rad: radius matrix, store the distance between a pixel and\n% the center of matrix\n% angle: angle matrix, store the angle of a pixel\n\nctrm=ceil(m/2);\nctrn=ceil(n/2);\n\n% x span from -m/2 to m/2 with interval 2/m\n[x,y] = meshgrid(( (1:m)-ctrm)/(m/2),( (1:n)-ctrn)/(n/2));\n\n% radius matrix\nrad = sqrt(x.^2 + y.^2);\nrad(m/2,n/2) = rad(m/2,n/2-1);\nlog_rad = log2(rad); \n\n% angle matrix\nangle = atan2(y,x); ", "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/36488-simplified-steerable-pyramid/Steerable/base.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9559813476288299, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.8027700100650116}} {"text": "%................................................................\n\nfunction stiffness=formStiffness2D(GDof,numberElements,...\n elementNodes,numberNodes,nodeCoordinates,D,thickness)\n\n% compute stiffness matrix\n% for plane stress Q4 elements\n\nstiffness=zeros(GDof);\n\n% 2 by 2 quadrature\n[gaussWeights,gaussLocations]=gauss2d('2x2');\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]=shapeFunctionQ4(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'*D*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/Q4/Q4Taper/formStiffness2D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813476288299, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.802770004313606}} {"text": "%Geometry domain\nL=15; H=1; B=1; A=H*B; I = B*H^3/12;\ninterval = nrbline ([0 0],[L 0]);\nproblem_data.geo_name = interval;\n\n%Boundary conditions\n%Left end: Sliding restraint + concentrated force\n%Right end: Simple support + moment\nproblem_data.drchlt1_ends = [false true]; %deflections, homogeneous\nproblem_data.drchlt2_ends = [true false]; %rotation angles, homogeneous\nproblem_data.nmnn1_ends = [true false]; %forces \nproblem_data.nmnn2_ends = [false true]; %moments\n\nM(1) = 0; M(2) = 10; \nP = 3;\nproblem_data.M = M; %moment values\nproblem_data.P = P; %force value \n\nf_c = 0.5;\nproblem_data.f = @(x) f_c * sin(pi*x/L); %distributed loading\n\n%Physical parameters\nE = 210000;\nproblem_data.EI = @(x) E * I* ones (size (x));\n\n% Discretization parameters\nmethod_data.degree = 3; % Degree of the basis functions\nmethod_data.regularity = 2; % Regularity of the basis functions\nmethod_data.nsub = 20; % Number of subdivisions\nmethod_data.nquad = 5; % Points for the Gaussian quadrature rule\n\n% Solving\n[geometry, msh, space, w] = solve_BE_Beam (problem_data, method_data);\n\n%Postprocessing\n%Exact solution\nc1 = (L*f_c+P*pi)/(pi*E*I);\nc2 = -(L^2*f_c+L*P*pi+M(2)*pi)/(pi*E*I);\nc3 = -f_c*L^3/(pi^3*E*I);\nc4 = L^2*(2*L^2*pi^2*f_c+2*L*P*pi^3+3*M(2)*pi^3+6*L^2*f_c)/(pi^3*E*I*6);\n\nw_ex = @(x) f_c*sin(pi*x/L)/E/I*(L/pi)^4 + c1*x.^3/6 + c2*x.^2/2 + c3*x + c4;\n%Gradient of exact solution\ngradwex = @(x) f_c*cos(pi*x/L)/E/I*(L/pi)^3 + c1*x.^2/2 + c2*x + c3;\n%Hessian of exact solution\nhesswex = @(x) -f_c*sin(pi*x/L)/E/I*(L/pi)^2 + c1*x + c2;\n\n%L2, H1 and H2 norms of error \n\n[errh2, errh1, errl2] = sp_h2_error (space, msh, w, w_ex, gradwex, hesswex);\nerrors = [errh2, errh1, errl2]\n[normh2, normh1, norml2] = sp_h2_error (space, msh, zeros (size (w)), w_ex, gradwex, hesswex);\nrelative_errors = [errh2/normh2, errh1/normh1, errl2/norml2]\n\n[eu, F] = sp_eval (w, space, geometry, 100);\nhan = figure;\nplot(F,eu,F,w_ex(F),'--')\nlegend('FEM-solution', 'Exact solution')\nxlabel('x')\nylabel('w')\n\n%!test\n%! ex_BE_beam_static\n%! close (han)\n%! assert (errors, [1.65638054386650e-06 1.95594407043227e-07 4.14113201313776e-08], 2e-11);\n%! assert (relative_errors, [1.31307379889248e-06 1.55064145756187e-07 3.30097917469054e-08], 2e-11);\n", "meta": {"author": "rafavzqz", "repo": "geopdes", "sha": "3bfa57b1a38bd4da3148536c9f67cce81afce701", "save_path": "github-repos/MATLAB/rafavzqz-geopdes", "path": "github-repos/MATLAB/rafavzqz-geopdes/geopdes-3bfa57b1a38bd4da3148536c9f67cce81afce701/geopdes/inst/examples/elasticity/ex_BE_beam_static.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966717067252, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.8026834541581729}} {"text": "function [energy, kinetic, potential] = energy_3_link(z,P) \n%[ENERGY, KINETIC, POTENTIAL] = ENERGY_3_LINK(Z,P)\n% \n%FUNCTION: This function computes the energy of a double\n% pendulum.\n%INPUTS: \n%\n%\n%OUTPUTS: \n% energy = [1 X nTime] vector of total energy\n% kinetic = [1 X nTime] vector of kinetic energy\n% potential = [1 X nTime] vector of potential energy\n% \n%NOTES:\n% This file was automatically generated by writeEnergy.m\n\ng = P.g ; %gravity\nm1 = P.m(1); % Link 1 mass\nm2 = P.m(2); % Link 2 mass\nm3 = P.m(3); % Link 3 mass\nl1 = P.l(1); % Link 1 length\nl2 = P.l(2); % Link 2 length\nl3 = P.l(3); % Link 3 length\nI1 = P.I(1); % Link 1 moment of inertia about its center of mass\nI2 = P.I(2); % Link 2 moment of inertia about its center of mass\nI3 = P.I(3); % Link 3 moment of inertia about its center of mass\nd1 = P.d(1); % Link 1 distance between center of mass and parent joint\nd2 = P.d(2); % Link 2 distance between center of mass and parent joint\nd3 = P.d(3); % Link 3 distance between center of mass and parent joint\n\nth1 = z(1,:); \nth2 = z(2,:); \nth3 = z(3,:); \n\ndth1 = z(4,:); \ndth2 = z(5,:); \ndth3 = z(6,:); \n\nkinetic = (I1.*dth1.^2)./2 + (I2.*dth2.^2)./2 + (I3.*dth3.^2)./2 + (m1.*(d1.^2.*dth1.^2.*cos(th1).^2 + d1.^2.*dth1.^2.*sin(th1).^2))./2 + (m2.*((dth1.*l1.*cos(th1) + d2.*dth2.*cos(th2)).^2 + (d2.*dth2.*sin(th2) + dth1.*l1.*sin(th1)).^2))./2 + (m3.*((dth1.*l1.*cos(th1) + dth2.*l2.*cos(th2) + d3.*dth3.*cos(th3)).^2 + (d3.*dth3.*sin(th3) + dth1.*l1.*sin(th1) + dth2.*l2.*sin(th2)).^2))./2;\npotential = g.*m3.*(d3.*sin(th3) + l1.*sin(th1) + l2.*sin(th2)) + g.*m2.*(d2.*sin(th2) + l1.*sin(th1)) + d1.*g.*m1.*sin(th1);\nenergy = potential + kinetic;\n\nend \n", "meta": {"author": "MatthewPeterKelly", "repo": "dscTutorials", "sha": "e1e97a9be03ec146f88bd6ddd9e06db7ee52e242", "save_path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials", "path": "github-repos/MATLAB/MatthewPeterKelly-dscTutorials/dscTutorials-e1e97a9be03ec146f88bd6ddd9e06db7ee52e242/LagrangeMechanics/nLinkPendulum/energy_3_link.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951142225532629, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.8026642659598138}} {"text": "function E = r8mat_expm3 ( A )\n\n%*****************************************************************************80\n%\n%% R8MAT_EXPM3 approximates the matrix exponential using an eigenvalue approach.\n%\n% Discussion:\n%\n% exp(A) = V * D * V\n%\n% where V is the matrix of eigenvectors of A, and D is the diagonal matrix\n% whose i-th diagonal entry is exp(lambda(i)), for lambda(i) an eigenvalue\n% of A.\n%\n% This function is accurate for matrices which are symmetric, orthogonal,\n% or normal.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 18 March 2011\n%\n% Author:\n%\n% Cleve Moler, Charles Van Loan\n%\n% Reference:\n%\n% Cleve Moler, Charles VanLoan,\n% Nineteen Dubious Ways to Compute the Exponential of a Matrix,\n% Twenty-Five Years Later,\n% SIAM Review,\n% Volume 45, Number 1, March 2003, pages 3-49.\n%\n% Parameters:\n%\n% Input, real A(N,N), the matrix.\n%\n% Output, real E(N,N), the estimate for exp(A).\n%\n [ V, D ] = eig ( A );\n E = V * diag ( exp ( diag ( D ) ) ) / V;\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/matrix_exponential/r8mat_expm3.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422158380861, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.8026642652470878}} {"text": "function p = predict(Theta1, Theta2, X)\n%PREDICT Predict the label of an input given a trained neural network\n% p = PREDICT(Theta1, Theta2, X) outputs the predicted label of X given the\n% trained weights of a neural network (Theta1, Theta2)\n\n% Useful values\nm = size(X, 1);\nnum_labels = size(Theta2, 1);\n\n% You need to return the following variables correctly \np = zeros(size(X, 1), 1);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Complete the following code to make predictions using\n% your learned neural network. You should set p to a \n% vector containing labels between 1 to num_labels.\n%\n% Hint: The max function might come in useful. In particular, the max\n% function can also return the index of the max element, for more\n% information see 'help max'. If your examples are in rows, then, you\n% can use max(A, [], 2) to obtain the max for each row.\n%\n\nX = [ones(m, 1) X];\ntemp = sigmoid(X * Theta1');\ntemp = [ones(m, 1) temp];\nr = sigmoid(temp * Theta2');\nfor i = 1:m\n [~, temp] = max(r(i, :));\n p(i) = temp;\nend\n\n% =========================================================================\n\nend\n", "meta": {"author": "JY-112553", "repo": "machine-learning", "sha": "db9c6e5a5175739821acd97787453472b8f46cac", "save_path": "github-repos/MATLAB/JY-112553-machine-learning", "path": "github-repos/MATLAB/JY-112553-machine-learning/machine-learning-db9c6e5a5175739821acd97787453472b8f46cac/machine-learning-ex3/ex3/predict.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455083, "lm_q2_score": 0.870597271765821, "lm_q1q2_score": 0.8026226379414076}} {"text": "function n = hex_grid_01_n ( nodes_per_layer )\n\n%*****************************************************************************80\n%\n%% HEX_GRID_01_N computes the number of unit square hex grid points.\n%\n% Discussion:\n%\n% This routine determines the value of N, the number of\n% hex grid points, from the fundamental hexagonal grid\n% parameter NODES_PER_LAYER.\n%\n% A hexagonal grid is defined in the unit square [0,1] x [0,1].\n%\n% All nodes of the grid lie on one of LAYERS horizontal lines.\n% The first of these lines is the X axis, and each successive\n% line is HY units higher.\n%\n% On all the odd numbered lines, there are NODES_PER_LAYER points,\n% equally spaced from 0 to 1, with a spacing of HX.\n%\n% On the even numbered lines, there are NODES_PER_LAYER-1 points,\n% whose values are the midpoints of successive intervals on\n% an odd numbered line. (The grid is staggered).\n%\n% HY = HX * sqrt ( 3 ) / 2.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 08 March 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NODES_PER_LAYER, the number of grid points on the first\n% horizontal layer of points.\n%\n% Output, integer N, the number of hex grid points.\n%\n if ( nodes_per_layer < 1 )\n\n n = 0;\n\n elseif ( nodes_per_layer == 1 )\n\n n = 1;\n\n else\n\n layers = hex_grid_01_layers ( nodes_per_layer );\n\n n = nodes_per_layer * floor ( ( layers + 1 ) / 2 ) + ...\n ( nodes_per_layer - 1 ) * floor ( ( layers ) / 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/square_hex_grid/hex_grid_01_n.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.8872045877523148, "lm_q1q2_score": 0.8026101096155471}} {"text": "function fx = p25_fun ( n, x )\n\n%*****************************************************************************80\n%\n%% P25_FUN evaluates the integrand for problem 25.\n%\n% Interval:\n%\n% 0 <= x <= 1.\n%\n% Integrand:\n%\n% ln ( abs ( x - 0.7 ) )\n%\n% Exact Integral:\n%\n% 0.3 * ln ( 0.3 ) + 0.7 * ln ( 0.7 ) - 1\n%\n% Approximate Integral (20 digits):\n%\n% -1.6108643020548934630\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 November 2009\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Kendall Atkinson,\n% An Introduction to Numerical Analysis,\n% Prentice Hall, 1984, page 303.\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 = log ( abs ( x - 0.7 ) );\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/p25_fun.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.880797071719777, "lm_q1q2_score": 0.8025644225133166}} {"text": "function f = local_xy ( x , y )\n\n%*****************************************************************************80\n%\n%% LOCAL_XY computes the local minimum function.\n%\n% Discussion:\n%\n% This function has a local minimum:\n%\n% X* = ( 0.28581..., 0.27936...), F(X*) = 5.9225...\n%\n% and a global minimum:\n%\n% X* = ( -21.026653..., -36.760090...), F(X*) = 0.\n%\n% Suggested starting point:\n%\n% X = ( 1, 1 ), F(X) = 3.33 * 10^6.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 12 February 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% David Himmelblau,\n% Applied Nonlinear Programming,\n% McGraw Hill, 1972,\n% ISBN13: 978-0070289215,\n% LC: T57.8.H55.\n%\n% Parameters:\n%\n% Input, real X, Y, the argument of the function.\n%\n% Output, real F, the value of the function at (X,Y).\n%\n f = ( x^2 + 12 * y - 1 )^2 ...\n + ( 49 * x^2 + 49 * y^2 + 84 * x + 2324 * y - 681 )^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/levels/local_xy.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.802490542044511}} {"text": "function loc=RLSloc(X)\n%Syntax: loc=RLSloc(X)\n%_____________________\n%\n% Calculates the Reweighterd Least Squares (RLS) location parameter \n% of the columns of a matrix X. If X is a vector, it returns the RLS\n% location parameter of its components. If X is a scalar, it returns\n% X.\n%\n% loc is the RLS estimated vector of locations.\n% X is the matrix with the data sets.\n%\n% Reference:\n% Rousseeuw PJ, Leroy AM (1987): Robust regression and outlier detection. Wiley.\n%\n%\n% Alexandros Leontitsis\n% Institute of Mathematics and Statistics\n% University of Kent at Canterbury\n% Canterbury\n% Kent, CT2 7NF\n% U.K.\n%\n% University e-mail: al10@ukc.ac.uk (until December 2002)\n% Lifetime e-mail: leoaleq@yahoo.com\n% Homepage: http://www.geocities.com/CapeCanaveral/Lab/1421\n%\n% Sep 3, 2001.\n\nif nargin<1 | isempty(X)==1\n error('Not enough input arguments.');\nelse\n % If X is a row vector make it a column vector\n if size(X,1)==1\n X=X';\n end\n % n is the length of the data set\n n=size(X,1);\nend\n\n% For a single data point there is no need to proceed\nif n==1\n loc=X;\nelse\n % Find the LMS location parameter\n l=LMSloc(X);\n % Find the LMS scale parameter\n s=LMSsca(X);\n \n % Calculate the location parameter for every column of X\n for i=1:size(X,2);\n r=X(:,i)-l(i);\n if s(i)==0\n w=1:n;\n else\n w=find(abs(r)/s(i)<=2.5);\n end\n loc(i)=mean(X(w,i));\n end\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/801-lms-toolbox/RLSloc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.8633916134888613, "lm_q1q2_score": 0.802471053264528}} {"text": "function [neighborIds neighborDistances] = kNearestNeighbors(dataMatrix, queryMatrix, k)\n%--------------------------------------------------------------------------\n% Program to find the k - nearest neighbors (kNN) within a set of points. \n% Distance metric used: Euclidean distance\n% \n% Usage:\n% [neighbors distances] = kNearestNeighbors(dataMatrix, queryMatrix, k);\n% dataMatrix (N x D) - N vectors with dimensionality D (within which we search for the nearest neighbors)\n% queryMatrix (M x D) - M query vectors with dimensionality D\n% k (1 x 1) - Number of nearest neighbors desired\n% \n% Example:\n% a = [1 1; 2 2; 3 2; 4 4; 5 6];\n% b = [1 1; 2 1; 6 2];\n% [neighbors distances] = kNearestNeighbors(a,b,2);\n% \n% Output:\n% neighbors =\n% 1 2\n% 1 2\n% 4 3\n% \n% distances =\n% 0 1.4142\n% 1.0000 1.0000\n% 2.8284 3.0000\n%--------------------------------------------------------------------------\n\nneighborIds = zeros(size(queryMatrix,1),k);\nneighborDistances = neighborIds;\n\nnumDataVectors = size(dataMatrix,1);\nnumQueryVectors = size(queryMatrix,1);\nfor i=1:numQueryVectors,\n dist = sum((repmat(queryMatrix(i,:),numDataVectors,1)-dataMatrix).^2,2);\n [sortval sortpos] = sort(dist,'ascend');\n neighborIds(i,:) = sortpos(1:k);\n neighborDistances(i,:) = sqrt(sortval(1:k));\nend", "meta": {"author": "aludnam", "repo": "MATLAB", "sha": "020b5cb02cc843e09a0ed689589382f18cce5e6d", "save_path": "github-repos/MATLAB/aludnam-MATLAB", "path": "github-repos/MATLAB/aludnam-MATLAB/MATLAB-020b5cb02cc843e09a0ed689589382f18cce5e6d/PatternAnalysis/kNearestNeighbors.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948495, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.8024710398726613}} {"text": "function f = local ( x )\n\n%*****************************************************************************80\n%\n%% LOCAL computes the local function.\n%\n% Discussion:\n%\n% This function has a local minimizer:\n%\n% X* = ( 0.2858054412..., 0.2793263206...), F(X*) = 5.9225...\n%\n% and a global minimizer:\n%\n% X* = ( -21.02667179..., -36.75997872...), F(X*) = 0.\n%\n% Suggested starting point for local minimizer:\n%\n% X = ( 1, 1 ), F(X) = 3.33 * 10^6.\n%\n% Suggested starting point for global minimizer:\n%\n% X = ( -15, -35), F(X) = 1.49 * 10^8.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 01 January 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% David Himmelblau,\n% Applied Nonlinear Programming,\n% McGraw Hill, 1972,\n% ISBN13: 978-0070289215,\n% LC: T57.8.H55.\n%\n% Parameters:\n%\n% Input, real X(2), the argument of the function.\n%\n% Output, real F, the value of the function at X.\n%\n if ( length ( x ) ~= 2 )\n error ( 'Error: function expects a two dimensional input\\n' );\n end\n\n f = ( x(1)^2 + 12 * x(2) - 1 )^2 ...\n + ( 49 * x(1)^2 + 49 * x(2)^2 + 84 * x(1) + 2324 * x(2) - 681 )^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/nelder_mead/local.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948494, "lm_q2_score": 0.8633916029436189, "lm_q1q2_score": 0.802471033338545}} {"text": "function [ vX, paramLambda ] = SolveLsNormConst( mA, vB, normConst )\n% ----------------------------------------------------------------------------------------------- %\n%[ vX ] = SolveLsNormConst( mA, vB, normConst )\n% Solves norm constrained Least Squares problem by finding the optimal Dual\n% Variable (paramLambda) of the KKT Conditions by succesively solving\n% Tikhonov Regularized Least Squares problems.\n% The objective Funciton is given by:\n% \\arg \\min_{x} \\frac{1}{2} {\\left\\| A x - b \\right\\|}_{2}^{2}\n% subject to {\\left\\| x \\right\\|}_{2} \\leq normSquaredConst\n% Input:\n% - mA - Input Matrix.\n% The given matrix of the problem 0.5 || A x - b|| ^ 2.\n% Structure: Vector (Column Vector).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% - vB - Input Vector.\n% The given vector of the problem 0.5 || A x - b|| ^ 2.\n% Structure: Scalar.\n% Type: 'Single' / 'Double'.\n% Range: {1, 2, ...}.\n% - normConst - Norm Constraint.\n% The solution must obey || x || <= normConst.\n% Structure: Scalar.\n% Type: 'Single' / 'Double'.\n% Range: (0, inf).\n% Output:\n% - vX - Solution Vector.\n% The optimal solution of the problem 0.5 || A x\n% - b || ^ 2 subject to || x || <= normConst.\n% Structure: Vector (Column Vector).\n% Type: 'Single' / 'Double'.\n% Range: (-inf, inf).\n% References\n% 1. See - https://stats.stackexchange.com/questions/401212.\n% Remarks:\n% 1. T\n% TODO:\n% 1. U\n% Release Notes:\n% - 1.0.000 14/04/2019\n% * First realease version.\n% ----------------------------------------------------------------------------------------------- %\n\nparamLambda = 0; %\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 11 January 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer NODE_NUM, the number of nodes.\n%\n% Input, integer ELEMENT_NUM, the number of elements.\n%\n% Input, integer ELEMENT_NODE(3,ELEMENT_NUM), the nodes that make\n% up each element.\n%\n% Input, real X(NODE_NUM), Y(NODE_NUM), the coordinates\n% of the nodes.\n%\n% Output, real A(NODE_NUM,NODE_NUM), the mass matrix.\n%\n element_order = 3;\n%\n% Zero out the matrix.\n%\n a(1:node_num,1:node_num) = 0.0;\n%\n% Get the weights and abscissas for a unit triangle.\n%\n rule = 4;\n quad_num = triangle_unit_size ( rule );\n [ rtab, stab, weight ] = triangle_unit_set ( rule );\n%\n% For each element.\n%\n for element = 1 : element_num\n\n p1 = element_node(1,element);\n p2 = element_node(2,element);\n p3 = element_node(3,element);\n\n area = 0.5 * abs ( ...\n x(p1) * ( y(p2) - y(p3) ) ...\n + x(p2) * ( y(p3) - y(p1) ) ...\n + x(p3) * ( y(p1) - y(p2) ) );\n\n if ( area == 0.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'MASS_MATRIX_T3 - Fatal error!\\n' );\n fprintf ( 1, ' Zero area for element %d\\n', element );\n error ( 'MASS_MATRIX_T3 - Fatal error!' );\n end\n%\n% For each quadrature point in the element...\n%\n for quad = 1 : quad_num\n\n r = rtab(quad);\n s = stab(quad);\n\n [ w, dwdr, dwds ] = shape_t3 ( r, s );\n%\n% For each basis function PHI(I) associated with a node in the element,\n%\n for iq = 1 : element_order\n\n ip = element_node(iq,element);\n%\n% For each \"neighbor\" basis function PHI(J) associated with a node in\n% the element.\n%\n for jq = 1 : element_order\n\n jp = element_node(jq,element);\n\n a(ip,jp) = a(ip,jp) + area * weight(quad) * w(iq) * w(jq);\n\n end\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/fem2d_pack/mass_matrix_t3.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.8022074560564528}} {"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 (computeCost) and gradient here.\n %\n\n h = X * theta;\n errors = h - y;\n delta = X' * errors;\n theta = theta - (alpha / m) * delta;\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": "zsiciarz", "repo": "ml-coursera", "sha": "54208ee72b88f1dc3c9235e644a47f618b80441c", "save_path": "github-repos/MATLAB/zsiciarz-ml-coursera", "path": "github-repos/MATLAB/zsiciarz-ml-coursera/ml-coursera-54208ee72b88f1dc3c9235e644a47f618b80441c/octave/ex1/gradientDescentMulti.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.867035752930664, "lm_q1q2_score": 0.8022074524813017}} {"text": "function p = predict(theta, X)\n%PREDICT Predict whether the label is 0 or 1 using learned logistic \n%regression parameters theta\n% p = PREDICT(theta, X) computes the predictions for X using a \n% threshold at 0.5 (i.e., if sigmoid(theta'*x) >= 0.5, predict 1)\n\nm = size(X, 1); % Number of training examples\n\n% You need to return the following variables correctly\np = zeros(m, 1);\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Complete the following code to make predictions using\n% your learned logistic regression parameters. \n% You should set p to a vector of 0's and 1's\n%\n\np = sigmoid(X * theta)>=0.5 ;\n\n\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 3 Assignments/Logistic Regression and Regularization/mlclass-ex2/predict.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8840392863287585, "lm_q1q2_score": 0.8020996486490065}} {"text": "function exactness_test08 ( )\n\n%*****************************************************************************80\n%\n%% EXACTNESS_TEST08 tests Gauss-Chebyshev1 rules for the Chebyshev1 integral.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 27 May 2014\n%\n% Author:\n%\n% John Burkardt\n%\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'EXACTNESS_TEST08\\n' );\n fprintf ( 1, ' Test Gauss-Chebyshev1 rules for the Chebyshev1 integral.\\n' );\n fprintf ( 1, ' Density function rho(x) = 1/sqrt(1-x^2).\\n' );\n fprintf ( 1, ' Region: -1 <= x <= +1.\\n' );\n fprintf ( 1, ' Exactness: 2*N-1.\\n' );\n\n for n = 1 : 5\n\n [ x, w ] = chebyshev1_set ( n );\n p_max = 2 * n;\n chebyshev1_exactness ( n, x, w, p_max );\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/exactness/exactness_test08.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8688267813328976, "lm_q1q2_score": 0.801961149845204}} {"text": "function l = l1dd_inverse ( n, h )\n\n%*****************************************************************************80\n%\n%% L1DD_INVERSE stores the inverse of the 1D DD Laplacian.\n%\n% Discussion:\n%\n% The N grid points are assumed to be evenly spaced by H.\n%\n% For N = 5, the discrete Laplacian with Dirichlet boundary conditions\n% at both ends of [0,6] has the matrix form L:\n%\n% 2 -1 0 0 0\n% -1 2 -1 0 0\n% 0 -1 2 -1 0\n% 0 0 -1 2 -1\n% 0 0 0 -1 2\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 29 October 2013\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the number of points.\n% N must be at least 3.\n%\n% Input, real H, the spacing between points.\n%\n% Output, real L(N,N), the inverse of the Laplacian matrix.\n%\n if ( n < 3 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'L1DD_INVERSE - Fatal error!\\n' );\n fprintf ( 1, ' N < 3.\\n' );\n error ( 'L1DD_INVERSE - Fatal error!' );\n end\n\n l = zeros ( n, n );\n\n for j = 1 : n\n for i = 1 : n\n l(i,j) = min ( i, j ) * ( n + 1 - max ( i, j ) ) * h * h / ( n + 1 );\n end\n end\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/laplacian/l1dd_inverse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381606, "lm_q2_score": 0.8688267660487573, "lm_q1q2_score": 0.801961135737344}} {"text": "%% Machine Learning Online Class - Exercise 2: Logistic Regression\n%\n% Instructions\n% ------------\n% \n% This file contains code that helps you get started on the logistic\n% regression exercise. You will need to complete the following functions \n% in this exericse:\n%\n% sigmoid.m\n% costFunction.m\n% predict.m\n% costFunctionReg.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\n%% Initialization\nclear ; close all; clc\n\n%% Load Data\n% The first two columns contains the exam scores and the third column\n% contains the label.\n\ndata = load('ex2data1.txt');\nX = data(:, [1, 2]); y = data(:, 3);\n\n%% ==================== Part 1: Plotting ====================\n% We start the exercise by first plotting the data to understand the \n% the problem we are working with.\n\nfprintf(['Plotting data with + indicating (y = 1) examples and o ' ...\n 'indicating (y = 0) examples.\\n']);\n\nplotData(X, y);\n\n% Put some labels \nhold on;\n% Labels and Legend\nxlabel('Exam 1 score')\nylabel('Exam 2 score')\n\n% Specified in plot order\nlegend('Admitted', 'Not admitted')\nhold off;\n\nfprintf('\\nProgram paused. Press enter to continue.\\n');\npause;\n\n\n%% ============ Part 2: Compute Cost and Gradient ============\n% In this part of the exercise, you will implement the cost and gradient\n% for logistic regression. You neeed to complete the code in \n% costFunction.m\n\n% Setup the data matrix appropriately, and add ones for the intercept term\n[m, n] = size(X);\n\n% Add intercept term to x and X_test\nX = [ones(m, 1) X];\n\n% Initialize fitting parameters\ninitial_theta = zeros(n + 1, 1);\n\n% Compute and display initial cost and gradient\n[cost, grad] = costFunction(initial_theta, X, y);\n\nfprintf('Cost at initial theta (zeros): %f\\n', cost);\nfprintf('Gradient at initial theta (zeros): \\n');\nfprintf(' %f \\n', grad);\n\nfprintf('\\nProgram paused. Press enter to continue.\\n');\npause;\n\n\n%% ============= Part 3: Optimizing using fminunc =============\n% In this exercise, you will use a built-in function (fminunc) to find the\n% optimal parameters theta.\n\n% Set options for fminunc\noptions = optimset('GradObj', 'on', 'MaxIter', 400);\n\n% Run fminunc to obtain the optimal theta\n% This function will return theta and the cost \n[theta, cost] = ...\n\tfminunc(@(t)(costFunction(t, X, y)), initial_theta, options);\n\n% Print theta to screen\nfprintf('Cost at theta found by fminunc: %f\\n', cost);\nfprintf('theta: \\n');\nfprintf(' %f \\n', theta);\n\n% Plot Boundary\nplotDecisionBoundary(theta, X, y);\n\n% Put some labels \nhold on;\n% Labels and Legend\nxlabel('Exam 1 score')\nylabel('Exam 2 score')\n\n% Specified in plot order\nlegend('Admitted', 'Not admitted')\nhold off;\n\nfprintf('\\nProgram paused. Press enter to continue.\\n');\npause;\n\n%% ============== Part 4: Predict and Accuracies ==============\n% After learning the parameters, you'll like to use it to predict the outcomes\n% on unseen data. In this part, you will use the logistic regression model\n% to predict the probability that a student with score 45 on exam 1 and \n% score 85 on exam 2 will be admitted.\n%\n% Furthermore, you will compute the training and test set accuracies of \n% our model.\n%\n% Your task is to complete the code in predict.m\n\n% Predict probability for a student with score 45 on exam 1 \n% and score 85 on exam 2 \n\nprob = sigmoid([1 45 85] * theta);\nfprintf(['For a student with scores 45 and 85, we predict an admission ' ...\n 'probability of %f\\n\\n'], prob);\n\n% Compute accuracy on our training set\np = predict(theta, X);\n\nfprintf('Train Accuracy: %f\\n', mean(double(p == y)) * 100);\n\nfprintf('\\nProgram paused. Press enter to continue.\\n');\npause;\n\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 3 Assignments/Logistic Regression and Regularization/mlclass-ex2/ex2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.8918110497511051, "lm_q1q2_score": 0.8018463865488218}} {"text": "function a = cauchy ( n, x, y )\n\n%*****************************************************************************80\n%\n%% CAUCHY returns the CAUCHY matrix.\n%\n% Formula:\n%\n% A(I,J) = 1.0 / ( X(I) + Y(J) )\n%\n% Example:\n%\n% N = 5, X = ( 1, 3, 5, 8, 7 ), Y = ( 2, 4, 6, 10, 9 )\n%\n% 1/3 1/5 1/7 1/11 1/10\n% 1/5 1/7 1/9 1/13 1/12\n% 1/7 1/9 1/11 1/15 1/14\n% 1/10 1/12 1/14 1/18 1/17\n% 1/9 1/11 1/13 1/17 1/16\n%\n% or, in decimal form,\n%\n% 0.333333 0.200000 0.142857 0.0909091 0.100000\n% 0.200000 0.142857 0.111111 0.0769231 0.0833333\n% 0.142857 0.111111 0.0909091 0.0666667 0.0714286\n% 0.100000 0.0833333 0.0714286 0.0555556 0.0588235\n% 0.111111 0.0909091 0.0769231 0.0588235 0.0625000\n%\n% Properties:\n%\n% A is generally not symmetric: A' /= A.\n%\n% A is totally positive if 0 < X(1) < ... < X(N) and 0 < Y1 < ... < Y(N).\n%\n% A will be singular if any X(I) equals X(J), or\n% any Y(I) equals Y(J), or if any X(I)+Y(J) equals zero.\n%\n% A is generally not normal: A' * A /= A * A'.\n%\n% The Hilbert matrix is a special case of the Cauchy matrix.\n%\n% The Parter matrix is a special case of the Cauchy matrix.\n%\n% The Ris or \"ding-dong\" matrix is a special case of the Cauchy matrix.\n%\n% det ( A ) = product ( 1 <= I < J <= N ) ( X(J) - X(I) )* ( Y(J) - Y(I) )\n% / product ( 1 <= I <= N, 1 <= J <= N ) ( X(I) + Y(J) )\n%\n% The inverse of A is\n%\n% INVERSE(A)(I,J) = product ( 1 <= K <= N ) [ (X(J)+Y(K)) * (X(K)+Y(I)) ] /\n% [ (X(J)+Y(I)) * product ( 1 <= K <= N, K /= J ) (X(J)-X(K))\n% * product ( 1 <= K <= N, K /= I ) (Y(I)-Y(K)) ]\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% 25 January 2015\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Robert Gregory, David Karney,\n% Example 3.26,\n% A Collection of Matrices for Testing Computational Algorithms,\n% Wiley, New York, 1969, page 54, \n% LC: QA263.G68.\n%\n% Nicholas Higham,\n% Accuracy and Stability of Numerical Algorithms,\n% SIAM, 1996.\n%\n% Donald Knuth,\n% The Art of Computer Programming,\n% Volume 1, Fundamental Algorithms, Second Edition\n% Addison-Wesley, Reading, Massachusetts, 1973, page 36.\n%\n% Olga Taussky, Marvin Marcus,\n% Eigenvalues of finite matrices,\n% in Survey of Numerical Analysis, \n% Edited by John Todd,\n% McGraw-Hill, New York, pages 279-313, 1962.\n%\n% Evgeny Tyrtyshnikov,\n% Cauchy-Toeplitz matrices and some applications,\n% Linear Algebra and Applications,\n% Volume 149, 1991, pages 1-18.\n%\n% Parameters:\n%\n% Input, integer N, the order of A.\n%\n% Input, real X(N), Y(N), vectors that determine A.\n%\n% Output, real A(N,N), the matrix.\n%\n for i = 1 : n\n\n for j = 1 : n\n\n if ( x(i) + y(j) == 0.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'CAUCHY - Fatal error!\\n' );\n fprintf ( 1, ' The denominator X(I)+Y(J) was zero\\n' );\n fprintf ( 1, ' for I = %d\\n', i );\n fprintf ( 1, ' X(I) = %g\\n', x(i) );\n fprintf ( 1, ' and J = %d\\n', j );\n fprintf ( 1, ' Y(J) = %g\\n', y(j) );\n error ( 'CAUCHY - Fatal error!' );\n end\n\n a(i,j) = 1.0 / ( x(i) + y(j) );\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/cauchy.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8918110346549901, "lm_q1q2_score": 0.801846365743528}} {"text": "function p=unrankTComposition(theRank,t,n,firstElMostSig)\n%%UNRANKTCOMPOSITION Return the composition of the given theRank, starting\n% from zero, of n unlabeled items in t parts. That is, a\n% method of putting n unlabeled balls into t labeled\n% slots. Compositions are tuples of t integers >=1 that\n% sum to n. Compositions are given in lexicographic order\n% where the first element is the least significant unless\n% otherwise specified.\n%\n%INPUTS: theRank The theRank (position in an ordered sequence) of the\n% desired composition starting from zero. There is a total\n% of binomial(n-1,t-1) compositions.\n% t The number of slots that can hold items, >=1.\n% n The number of items that are composed into slots, >=1;\n% n>=t\n% firstElMostSig An optional parameter specifying whether the first\n% element is the most or least significant. The default if\n% omitted or an empty matrix is passed is false (the first\n% element is the least significant).\n%\n%OUTPUTS: p A tX1 vector holding the current composition, whose elements\n% sum to n. Each element is the number of \"balls\" in that slot.\n% If theRank is larger than the maximum number of compositions,\n% an empty matrix is returned. The values of q can range from 0\n% to n.\n%\n%This is an implementation of the relation described in Chapter 7.2.1.3 of\n%[1] for mapping combinations to compositions. theRank is used to obtain a\n%combination in lexicographic order (p(1) is the least significant\n%element) and the elements of the combination are mapped to the equivalent\n%composition. However, a special case is if the input is one-dimensional,\n%in which case the only composition is for theRank=0 and the value is n.\n%\n%REFERENCES:\n%[1] D. E. Knuth, The Art of Computer Programming. Vol. 4, Fascicle 3:\n% Generating all Combinations and Partitions, Upper Saddle River, NJ:\n% Addison-Wesley, 2009.\n%\n%October 2013 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<4||isempty(firstElMostSig))\n firstElMostSig=false;\nend\n\nn=n-1;\nnCombo=n;\ntCombo=t-1;\n\nif(tCombo>0)\n c=unrankCombination(theRank,nCombo,tCombo);\n\n if(isempty(c))\n p=[];\n return;\n end\n\n %Transform the combination into a valid composition.\n p=zeros(t,1);\n p(1)=c(1)+1;\n for curIdx=2:tCombo\n p(curIdx)=c(curIdx)-c(curIdx-1);\n end\n p(t)=n-c(tCombo);\nelse%The t=1 case has to be handled separately.\n if(theRank==0)\n p=n+1;\n else\n p=[]; \n end\nend\n\nif(firstElMostSig)\n p=flipud(p(:)); \nend\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/Combinatorics/unrankTComposition.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.8918110368115781, "lm_q1q2_score": 0.8018463628611928}} {"text": "function [H] = lpfilter(type,M,N,D0,n)\n%LPFILTER Computes freq. domain lowpass filters\n%\t\tTHIS IS NOT A STANDARD MATLAB FUNCTION\n%\t\tH = lpfilter (type,M,N,D0,n) creates the\n%\t\ttransfer function of a lowpass filter, H, of\n%\t\tthe specified type and size MxN. Acceptable \n%\t\tvalues for type, D0, and n are:\n%\n%\t\t\t\t'ideal'\t\t\t\tIdeal lowpass filter with\n%\t\t\t\t\t\t\t\t\tcutoff frequency D0. If\n%\t\t\t\t\t\t\t\t\tsupplied, n is ignored.\n%\t\t\t\t'btw'\t\t\t\tButterworth lowpass filter\n%\t\t\t\t\t\t\t\t\tof order n, and cutoff D0.\n%\t\t\t\t'gauss'\t\t\t Gaussian lowpass filter with\n%\t\t\t\t\t\t\t\t\tcutoff (standard deviation)D0.\n%\t\t\t\t\t\t\t\t\tIf supplied, n is ignored.\n%\t\tM and N should be even numbers for DFT\n%\t\tfiltering.\n%\n%\t\tClass support: double, uint8, uint16\n%\t\tThe output is of class double\n\n%\t\tVerify the number of inputs\n\nerror(nargchk(4,5,nargin));\n\n%\t\tIssue warning if M or N not even\n\nL1 = M/2;\nL2 = N/2;\nif((L1-round(L1)) | (L2-round(L2)))\n\t\tdisp('Warning: M & N must be even for DFT filtering')\nend\n\n%\t\tSet up meshgrid to compute filter functions\n%\t\trunning from 0 to M-1 and 0 to N-1. But,\n%\t\trecall that U and V run from 1 to M and 1 to N,\n%\t\trepectively. See Section 2.10.4 for an \n%\t\texplanation of meshgrid. Recall also that\n%\t\tmeshgrid reverses the order of rows and \n%\t\tcolumns, so the final result must be transposed\n%\t\tin order to preserve the original order of \n%\t\tof the coordinates.\n\n\n[U,V] = meshgrid(0:M-1,0:N-1);\n\n% Compute the filter center\n\nU0=L1;\nV0=L2;\n\n%\t\tCompute distances D(U,V)\n\nD=((U-U0).^2 + (V-V0).^2).^0.5;\n\n%\t\tBegin filter computations\n\nswitch type\n\tcase 'ideal'\n\t\tH = D<=D0;\n H = H';\n\tcase 'btw'\n\t\tH = 1./(1 + (D./D0).^(2*n));\n H = H';\n\tcase 'gauss'\n\t\tH = exp(-(D.^2)./(2*(D0^2)));\n H = H';\n\totherwise\n\t\terror('Unknown filter type')\nend\n\n%\t\tEnd of function\n", "meta": {"author": "61--", "repo": "weiyanmin", "sha": "e15a7789602ec65c7ce1972bd905826ff4851435", "save_path": "github-repos/MATLAB/61---weiyanmin", "path": "github-repos/MATLAB/61---weiyanmin/weiyanmin-e15a7789602ec65c7ce1972bd905826ff4851435/Code/ImageProcess/数字图像处理matlab 图像库/lpfilter.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.957277806109987, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.8018350066741016}} {"text": "function [h,tf]=Jakes_Flat(fd,Ts,Ns,t0,E0,phi_N)\n% Inputs:\n% fd : Doppler frequency\n% Ts : sampling period\n% Ns : number of samples\n% t0 : initial time\n% E0 : channel power\n% phi_N : inital phase of the maximum doppler frequency sinusoid\n% Outputs:\n% h : complex fading vector\n% t_state: current time\nif nargin<6\n phi_N=0; \nend\nif nargin<5\n E0=1; \nend\nif nargin<4\n t0=0; \nend\nif nargin<3\n error('More arguments are needed for Jakes_Flat()'); \nend\nN0=8; % As suggested by Jakes \nN=4*N0+2; % an accurate approximation \nwd=2*pi*fd; % Maximum doppler frequency[rad]\n%t_state = t0;\n%for i=1:Ns\n% ich=sqrt(2)*cos(phi_N)*cos(wd*t_state);\n% qch=sqrt(2)*sin(phi_N)*cos(wd*t_state);\n% for k=1:N0\n% phi_n=pi*k/(N0+1);\n% wn=wd*cos(2*pi*k/N);\n% ich=ich+2*cos(phi_n)*cos(wn*t_state);\n% qch=qch+2*sin(phi_n)*cos(wn*t_state);\n% end\n% h1(i) = E0/sqrt(2*N0+1)*complex(ich,qch);\n% t_state=t_state+Ts; % save last time\n%end\nt = t0+[0:Ns-1]*Ts; \ntf = t(end)+Ts; \ncoswt = [sqrt(2)*cos(wd*t); 2*cos(wd*cos(2*pi/N*[1:N0]')*t)]; % (2.32)\nh = E0/sqrt(2*N0+1)*exp(j*[phi_N pi/(N0+1)*[1:N0]])*coswt; \n% discrepancy = norm(h-h1)", "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/第2章 SISO信道模型/Jakes模型/Jakes_Flat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993028, "lm_q2_score": 0.8499711699569786, "lm_q1q2_score": 0.8018182403832909}} {"text": "function [average, weight] = CrossWeightAverage(DATA,WEIGHT)\n% =========================================================================\n% Compute the weighted average of DATA, computing the weights form the\n% matrix WEIGHT. Note that if there are NaNs in DATA the weights are \n% rescaled. WEIGHTS CANNOT contain NaN\n% =========================================================================\n% [average, weight] = CrossWeightAverage(DATA,WEIGHT)\n% -------------------------------------------------------------------------\n% INPUT \n%\t- DATA: panel of time series DATA(T,N) of T observation x N series \n% (NaN are accepted and weights rescaled)\n% - WEIGHT: time series of FLOWS or WEIGHTS (TxN). You can also\n% provide a (1xN) matrix in this case the code would automatically \n% compute fixed weights\n% -------------------------------------------------------------------------\n% OUTPUT \n%\t- average : weighted average vector (T x 1)\n%\t- weight : matrix of weights (T x N)\n% =========================================================================\n% Example 1: foreign variables as in GVAR (example with fixed weights)\n% x = [1 NaN 3 ; \n% 2 3 4 ; \n% 3 4 5 ; \n% 4 5 6];\n% w = [0 .4 .6];\n% [average, weight] = CrossWeightAverage(x,w)\n% -------------------------------------------------------------------------\n% Example 2: weighted average (with time-varying weights)\n% x = [ 1 NaN 3 ;\n% 2 3 4 ;\n% 3 4 5 ; \n% 4 5 6];\n% w = [.4 .2 .4 ; \n% .3 .4 .3 ;\n% .4 .3 .3 ;\n% .5 .3 .2];\n% [average, weight] = CrossWeightAverage(x,w)\n% =========================================================================\n% Ambrogio Cesa Bianchi, March 2015\n\n\n\n%% Preliminaries\n% Check inputs\n[r1, c1] = size(DATA);\n[r2, c2] = size(WEIGHT);\nif r2==1 && c2==c1 \n % Create a matrix of fixed weights\n aux = [];\n for ii=1:r1\n aux = [aux; WEIGHT];\n end\n WEIGHT = aux;\nend\n\n\n% Re-Check inputs\n[r1, c1] = size(DATA);\n[r2, c2] = size(WEIGHT);\nif r1~=r2 || c1~=c2\n disp(' ')\n disp('The matrices of data and weights are not conformable.')\n return\nend\n\n%% Cross section weihgted average\n[nobs, nvars] = size(DATA);\nnans = isnan(DATA);\nWEIGHT(nans) = NaN;\n\naverage(1:nobs,1) = NaN;\nweight(1:nobs,1:nvars) = NaN;\n\nfor ii=1:nobs\n aux_weight = WEIGHT(ii,:)./nansum(WEIGHT(ii,:));\n weight(ii,:) = aux_weight;\n aux_weight(nans(ii,:)) = 0;\n DATA(ii,nans(ii,:)) = 0;\n average(ii,1) = DATA(ii,:) * aux_weight';\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/OldVersions/v2dot0/Stats/CrossWeightAverage.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426831, "lm_q2_score": 0.8740772384450967, "lm_q1q2_score": 0.801793367604716}} {"text": "function intVal=monomialIntPrism(alpha)\n%%MONOMIALINTPRISM Evaluate the integral of prod_{i=1}^3 x(i)^alpha(i)\n% over a standard prism in 3D. This is a triangle that has been extruded\n% upward. The vertices are (1,-1,-1), (-1,-1,-1), (-1,1,-1), (1,-1,1),\n% (-1,-1,1), and (-1,1,1).\n%\n%INPUTS: alpha A 3X1 or 1X3 vector of the integer exponents of the\n% monomial term. All elements must be >=0.\n%\n%OUTPUTS: intVal The value of the specified integral.\n%\n%The solution was obtained via analytic integration. These types of\n%explicit moment formulae are useful for testing cubature integration\n%points.\n%\n%EXAMPLE:\n%An analytic solution for alpha=[10;18;6] is -4/3861. Here, we\n%show that this function produces the same result within resonable finite\n%precision limits.\n% alpha=[19;12;8];\n% intSol=monomialIntPrism(alpha);\n% trueSol=-4/3861;\n% RelErr=(intSol-trueSol)/trueSol\n%\n%October 2022 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(mod(alpha(3),2)==0)\n a=alpha(1);\n b=alpha(2);\n c=alpha(3);\n\n intVal=(2*(-1)^a*(1+a)+2*(-1)^b*(1+b+(-1)^a*(2+a+b)))/((1+a)*(1+b)*(2+a+b)*(1+c));\nelse\n intVal=0;\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/Specific_Integrals/Monomial_Integrals/monomialIntPrism.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.920789673717312, "lm_q2_score": 0.8705972784807408, "lm_q1q2_score": 0.8016369839914611}} {"text": "%% Example of dop2Dbox Applied to Illumination Correction\n%\n% (C) 2013 Matthew harker and Paul O'Leary\n% Institute for Automation\n% University of Leoben\n% A-8700 Leoben\n% Austria\n%\n% email: office@harkeroleary.org\n%\n% This program demonstrates the application of discrete orthogonal\n% polynomials to illumination correction in an image.\n%\n% This tool requires the discrete orthogonal toolbox: dopBox:\n%\n% http://www.mathworks.com/matlabcentral/fileexchange/41250\n%\n%%\nclose all;\nclear;\n%\n%% Load the Test Data\n% \\cellName{loadData}\n% \n% This is an image of a metallurgical sample taken with a microscope\n%\nload metallurgy;\n%\nfig1 = figure;\nimagesc( D );\ncolormap(gray);\naxis image;\n%\n%\\caption{Example metallurgical image, note the inhomogeneous illumination}\n%\n%% Generate the Basis Functions for the X and Y Directions\n% \\cellName{genBases}\n%\n% Determine the size of the image\n%\n[ny, nx] = size( D );\n%\n% Define the degree of the basis functions for the x and y directions\n%\ndegreeX = 2;\ndegreeY = 2;\n%\n% The function call dop uses the number of basis functions not degree\n%\nnoBfsX = degreeX + 1;\nnoBfsY = degreeY + 1;\n%\n% Generate the discrete orthogonal basis functions\n%\nBx = dop( nx, noBfsX );\nBy = dop( ny, noBfsY );\n%\n%% Compute the 2D Polynomial Spectrum\n% \\cellName{computeSpec}\n%\n% Only a few basis functions have been used. Consequently the 2D polynomial\n% is of low degree. The fit will model the global intensity of the image.\n%\nSp = By' * D * Bx;\n%\n% generate scale vectors for the x and y directions\n%\nxScale = 0:degreeX;\nyScale = 0:degreeY;\n%\nfig2 = figure;\nimagesc( xScale, yScale, Sp );\nxlabel('Degree in $$x$$');\nylabel('Degree in $$y$$');\ncolorbar;\n%\n% \\caption{2D polynomial spectrum}\n%\n%% Compute the Illumination Approximation\n% \\cellName{approx}\n%\n% Reconstructing the 2D data set corresponds to the global illumination\n% approximation.\n%\nZ = By * Sp * Bx';\n%\nfig3 = figure;\nimagesc( Z );\ncolorbar;\ncolormap(gray);\n%\n% \\caption{2D Polynomial approximation to the image. The low degree of \n% approximation ensures that the details in the image are not modelled. \n% In this manner the approximation corresponds to the global illumination}\n%\n%% Correct the Image Intensity\n% \\cellName{correct}\n%\nC = D - Z;\n%\nfig4 = figure;\nimagesc( C );\ncolorbar;\ncolormap(gray);\n%\n% \\caption{Metallurgical image corrected for the non-uniform illumination.}\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/42474-2d-polynomial-data-modelling-version-1-0/dop2DBoxV1-0/documentation/Sources/dop2DIlluminationDemo.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646392, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.8016369785016889}} {"text": "function [ x, seed ] = c_normal_01_sample ( seed )\n\n%*****************************************************************************80\n%\n%% C_NORMAL_01_SAMPLE samples the complex Normal 01 PDF.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 05 September 2004\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer SEED, a seed for the random number generator.\n%\n% Output, complex X, a sample of the PDF.\n%\n [ v1, seed ] = r8_uniform_01 ( seed );\n [ v2, seed ] = r8_uniform_01 ( seed );\n\n x_r = sqrt ( - 2.0 * log ( v1 ) ) * cos ( 2.0 * pi * v2 );\n x_c = sqrt ( - 2.0 * log ( v1 ) ) * sin ( 2.0 * pi * v2 );\n\n x = x_r + i * x_c;\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/c_normal_01_sample.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896758909757, "lm_q2_score": 0.8705972667296309, "lm_q1q2_score": 0.8016369750635461}} {"text": "function trans = createTranslation(varargin)\n%CREATETRANSLATION Create the 3*3 matrix of a translation.\n%\n% TRANS = createTranslation(DX, DY);\n% Returns the translation corresponding to DX and DY.\n% The returned matrix has the form :\n% [1 0 TX]\n% [0 1 TY]\n% [0 0 1]\n%\n% TRANS = createTranslation(VECTOR);\n% Returns the matrix corresponding to a translation by the vector [x y].\n%\n%\n% See also:\n% transforms2d, transformPoint, createRotation, createScaling\n%\n% ---------\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 06/04/2004.\n%\n\n% HISTORY\n% 22/04/2009: rename as createTranslation\n\n% process input arguments\nif isempty(varargin)\n tx = 0;\n ty = 0;\nelseif length(varargin)==1\n var = varargin{1};\n tx = var(1);\n ty = var(2);\nelse\n tx = varargin{1};\n ty = varargin{2};\nend\n\n% create the matrix representing the translation\ntrans = [1 0 tx ; 0 1 ty ; 0 0 1];", "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/private/createTranslation.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.8015963037667074}} {"text": "function [ x, w ] = ccoh_rule ( n )\n\n%*****************************************************************************80\n%\n%% CCOH_RULE computes a Clenshaw Curtis Open Half rule.\n%\n% Discussion:\n%\n% Our convention is that the abscissas are numbered from left to right.\n%\n% The rule is defined on [-1,1].\n%\n% The integral to approximate:\n%\n% Integral ( -1 <= X <= 1 ) F(X) dX\n%\n% The quadrature rule:\n%\n% Sum ( 1 <= I <= N ) W(I) * F ( X(I) )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 03 February 2011\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, integer N, the order of the rule.\n%\n% Output, real X(N), the abscissas.\n%\n% Output, real W(N), the weights.\n%\n x = zeros ( n, 1 );\n x = ( 1 : 2 : 2 * n - 1 )' / ( 2 * n );\n%\n% Chebyshev transformation from [0,1] to [-1,1].\n%\n x = cos ( x * pi );\n%\n% Compute the weights.\n%\n x_min = -1.0;\n x_max = +1.0;\n\n w = nc_compute ( n, x_min, x_max, x );\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/sparse_grid_total_poly/ccoh_rule.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087926320945, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.8015803687113016}} {"text": "function f = p03_f ( m, c, w, n, x )\n\n%*****************************************************************************80\n%\n%% P03_F evaluates the function for problem p03.\n%\n% Discussion:\n%\n% f(x) = 1 / ( 1 + sum ( c(1:m) * x(1:m) ) ) ^ ( m + 1 )\n%\n% Default values are:\n%\n% c(1:m) = 1/m\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 26 August 2012\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Alan Genz,\n% A Package for Testing Multiple Integration Subroutines,\n% in Numerical Integration: Recent Developments, Software\n% and Applications,\n% edited by Patrick Keast and Graeme Fairweather,\n% Reidel, 1987, pages 337-340,\n% ISBN: 9027725144,\n% LC: QA299.3.N38.\n%\n% Parameters:\n%\n% Input, integer M, the spatial dimension.\n%\n% Input, real C(M,1), W(M,1), the problem parameters.\n%\n% Input, integer N, the number of points.\n%\n% Input, real X(M,N), the evaluation points.\n%\n% Output, real F(N,1), the function values.\n%\n f = ones ( n, 1 );\n\n for i = 1 : m \n f = f + c(i) .* x(i,:)';\n end\n f = 1.0 ./ f .^ ( m + 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_interp_nd/p03_f.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087926320944, "lm_q2_score": 0.8633916047011595, "lm_q1q2_score": 0.80158035728929}} {"text": "function result = fit_rayleigh_pdf( x,y,W,hAx )\n% fit_rayleigh_pdf - Non Linear Least Squares fit of the Rayleigh 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)=r*exp(-r^2/(2*s))/s\n% with parameter: s\n%\n% format: result = fit_rayleigh_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% s - 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 rayleigh distribution is given by:\n%\n% p(x,s) = x*exp(-x^2/(2*s))/s\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% s(n+1) = s(n) + inv(H'*W*H)*(H') * (y-h) = s(n) + G * err\n% \n% where: h = p(x,s)\n% H = diff( p(x,a) ) with respect to \"s\"\n% W = weighting matrix of size NxN (N = length(y))\n% s = a single parameter to be estimated\n%\n% The error estimation is given by:\n%\n% VAR( s ) = G * VAR( err ) * (G')\n%\n% or when W=I and the noise is a gaussian noise \n%\n% VAR( s ) = inv( H' * H )\n%\n\nif (nargin<3)\n error( 'fit_rayleigh_pdf - insufficient input arguments' );\nend\n\ns = x(find(y==max(y))).^2; % initial guess\ny = y(:); % both should be column vectors !\nx = x(:);\nx2 = x.^2; % save computation time\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 = x.*exp( -x2/(2*s) )/s;\n H = h.*(x2/(2*s^2) - 1/s);\n HTW = H'*W;\n e = inv( HTW * H ) * HTW * (y-h);\n s = s + 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 = x.*exp( -x2/(2*s) )/s;\n H = h.*(x2/(2*s^2) - 1/s);\n HTW = H'*W;\n G = inv( HTW * H ) * HTW;\n err = (y-h);\n VAR = G * var(err) * (G');\nelse\n\n % loop for convergence (without a weighting matrix)\n % ==================================================\n while (1)\n iter = iter + 1;\n h = x.*exp( -x2/(2*s) )/s;\n H = h.*(x2/(2*s^2) - 1/s);\n HT = H';\n control = inv( HT * H );\n s = s + 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 = x.*exp( -x2/(2*s) )/s;\n H = h.*(x2/(2*s^2) - 1/s);\n err = (y-h);\n VAR = inv( (H') * H );\nend\n\n\n% finish summarizing results\n% ============================\nresult.s = s;\nresult.VAR = VAR;\nresult.RMS = sqrt( (err')*err/ (x(2)-x(1))^2 / (length(err)-1) );\nresult.iter = iter;\nresult.type = type;\n\n% plot distribution if asked for\n% ===============================\nif (nargin>3)\n if ishandle( hAx )\n plot_rayleigh( x,result,hAx,4 );\n else\n figure;\n plot_rayleigh( x,result1,gca,4 );\n end\nend\n\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_rayleigh_pdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678382, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.8014943643556064}} {"text": "% RM_histogram Computes the frequency histogram of the row vector x.\n% [RESULT,DESCRIPTOR] = HISTOGRAM(X) or\n% [RESULT,DESCRIPTOR] = HISTOGRAM(X,DESCRIPTOR) or\n% where\n% DESCRIPTOR = [LOWER,UPPER,NCELL]\n%\n% RESULT : A row vector containing the histogram\n% DESCRIPTOR: The used descriptor\n%\n% X : The row vector be analyzed\n% DESCRIPTOR: The descriptor of the histogram\n% LOWER : The lowerbound of the histogram\n% UPPER : The upperbound of the histogram\n% NCELL : The number of cells of the histogram\n%\n% See also: http://www.cs.rug.nl/~rudy/matlab/\n%\n% R. Moddemeijer \n% Copyright (c) by R. Moddemeijer\n% $Revision: 1.2 $ $Date: 2001/02/05 09:54:29 $\n\nfunction [result,descriptor] = RM_histogram(x,descriptor)\n\nif nargin < 1\n disp('Usage: RESULT = HISTOGRAM(X)')\n disp(' RESULT = HISTOGRAM(X,DESCRIPTOR)')\n disp('Where: DESCRIPTOR = [LOWER,UPPER,NCELL]')\n return\nend\n\n% Some initial tests on the input arguments\n\n[NRowX, NColX] = size(x);\n\nif NRowX ~= 1\n error('Invalid dimension of X');\nend;\n\nif nargin > 2\n error('Too many arguments');\nend;\n\nif nargin==1\n minx=min(x);\n maxx=max(x);\n delta=(maxx-minx)/(length(x)-1);\n ncell=ceil(sqrt(length(x)));\n descriptor=[minx-delta/2,maxx+delta/2,ncell];\nend;\n\nlower=descriptor(1);\nupper=descriptor(2);\nncell=descriptor(3);\n\nif ncell<1 \n error('Invalid number of cells')\nend;\n\nif upper<=lower\n error('Invalid bounds')\nend;\n\nresult(1:ncell)=0;\n\ny=round( (x-lower)/(upper-lower)*ncell + 1/2 );\nfor n=1:NColX\n index=y(n);\n if index >= 1 & index<=ncell\n result(index)=result(index)+1;\n end;\nend;\n\n", "meta": {"author": "benfulcher", "repo": "hctsa", "sha": "919f2aed7cc8e1a3a03304c1ade573fa664c73f8", "save_path": "github-repos/MATLAB/benfulcher-hctsa", "path": "github-repos/MATLAB/benfulcher-hctsa/hctsa-919f2aed7cc8e1a3a03304c1ade573fa664c73f8/Toolboxes/Rudy_Moddemeijer/RM_histogram.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.8807970873650401, "lm_q1q2_score": 0.8014434492987963}} {"text": "function ninv = norm_inv(x,mu,sigma)\n%NORM_INV Inverse of the normal cumulative distribution function (cdf).\n% Y = NORM_INV(X,MU,SIGMA) Returns inverse of the normal cdf with\n% mean, MU, and standard deviation, SIGMA, at the values in X.\n%\n% The size of X is the common size of the input arguments. A scalar input\n% functions as a constant matrix of the same size as the other inputs.\n%\n% Default values for MU and SIGMA are 0 and 1 respectively.\n%\n% Copyright (c) 1995-1997, 2005-2007 Kurt Hornik\n\n% This software is distributed under the GNU General Public\n% License (version 3 or later); please refer to the file\n% License.txt, included with the software, for details.\n\n\nif nargin < 3\n sigma = 1;\nend\nif nargin < 2\n mu = 0;\nend\n\nif (~isscalar(mu) || ~isscalar(sigma))\n if ~((size(x,1) == size(mu,1)) && (size(mu,1) == size(sigma,1)))\n error ('norm_inv: x, mu and sigma must be of common size or scalars');\n end\nend\n\n[n,nin] = size (x);\nninv = zeros (n,nin);\n\nif (isscalar (mu) && isscalar (sigma))\n if (find (isinf (mu) || isnan (mu) || (sigma < 0) || isinf(sigma)))\n ninv = NaN*ones(n,nin);\n else\n ninv = mu+sigma.*sqrt(2)*erfinv(2*x-1);\n end\nelse\n k = find(isinf(mu) || isnan(mu) || (sigma < 0) || isinf(sigma));\n if (any(k))\n ninv(k) = NaN;\n end\n \n k = find(~isinf(mu) && ~isnan(mu) && (sigma > 0) && (sigma < Inf));\n if (any (k))\n ninv(k) = mu(k)+sigma(k).*sqrt(2)*erfinv(2*x(k)-1);\n end\nend\n\nk = find ((sigma == 0) && (x > 0) && (x < 1));\nif (any(k))\n ninv(k) = mu(k);\nend\n\nninv((sigma == 0) & (x == 0)) = -Inf;\nninv((sigma == 0) & (x == 1)) = Inf;\n\nend", "meta": {"author": "gpstuff-dev", "repo": "gpstuff", "sha": "114937ec0a201306489a66cbba38283e722fb998", "save_path": "github-repos/MATLAB/gpstuff-dev-gpstuff", "path": "github-repos/MATLAB/gpstuff-dev-gpstuff/gpstuff-114937ec0a201306489a66cbba38283e722fb998/dist/norm_inv.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.8807970873650403, "lm_q1q2_score": 0.8014434363876369}} {"text": "function [Hr,w,theta] = AmpResp(h,FreqPoint,FreqRange,ShiftFreq)\n\n% AmpResp Calculate Amplitude Response of Symmetric FIR Filter\n%\n% Arguments:\n% h Symmetric impulse response:\n% Type I linear-phase FIR filter, L is odd\n% Type II lienar-phase FIR fitler, L is even\n% FreqPoint Range of amplitude response from 0 to 2pi or -pi to pi\n% FreqRange FreqRange = 1, frequency range is from 0 to 2pi\n% = 2, frequency range -pi to pi \n% ShiftFreq Freq shift of amplitude response with specified amount \n% Hr Amplitude (zero-phase) response (column vectors)\n%\n% by Kong A. Lee, Feb 2005\n\n% Check input argument values\n\nif nargin <4; ShiftFreq = 0; end\nif nargin <3; FreqRange = 1; end\nif nargin <2; FreqPoint = 4096; end\n \nh = h(:); % Make sure h is a column vector\nL = length(h); % Length of filter\n\n% Check selected frequency range\n\nif FreqRange ==1\n w = (0:FreqPoint-1)*2*pi/FreqPoint;\nelseif FreqRange ==2\n FreqPoint = FreqPoint/2;\n w = (-FreqPoint+1:1:FreqPoint-1)*pi/FreqPoint;\nend\n\nif mod(L,2)==1 % L is an odd number\n \n alpha = (L-1)/2;\n\ta = [h(alpha + 1); 2*h(alpha:-1:1)];\n\tn = 0:alpha;\n\tHr = cos((w + ShiftFreq)'*n)*a;\n \nend\n\nif mod(L,2)==0 % L is an even number\n \n alpha = L/2;\n b = 2*h(alpha:-1:1);\n n = (1:alpha) - 0.5;\n Hr = cos((w + ShiftFreq)'*n)*b;\n \nend\n \ntheta = -((L-1)/2)*w;", "meta": {"author": "CharlesThaCat", "repo": "acoustic-interference-cancellation", "sha": "edb394499ea6f9c96445a3e9613bd64a854c289e", "save_path": "github-repos/MATLAB/CharlesThaCat-acoustic-interference-cancellation", "path": "github-repos/MATLAB/CharlesThaCat-acoustic-interference-cancellation/acoustic-interference-cancellation-edb394499ea6f9c96445a3e9613bd64a854c289e/Subband processing/Common Code/AmpResp.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.947381040709679, "lm_q2_score": 0.8459424334245617, "lm_q1q2_score": 0.8014298229582395}} {"text": "function isBipartite=graphIsBipartite(A)\n%%GRAPHISBIPARTITE Given a nondirectional graph represented by a symmetric\n% adjacency matrix A, determine whether the graph is\n% bipartite.\n%\n%INPUTS: A An nXn symmetric adjacency matrix. If element i is adjacent to\n% element j, then A(i,j) is nonzero. Otherwise, it is zero.\n% Diagonal elements are typically zero (if not, then the graph is\n% not bipartite).\n%\n%OUTPUTS: isBipartite This is true if the graph is bipartite and false\n% otherwise.\n%\n%This function implements Algorithm B in Chapter 7 of [1], modified for an\n%adjacency matrix. When very large, space graphs are used, then the\n%adjacency matrix representation is not ideal.\n%\n%EXAMPLE:\n%We consider four graphs. Two are bipartite and two are not.\n%A1 and A2 are:\n%A1: A2:\n%1--2 1--2\n% \\/ \\/\n% /\\ /\\\n%3--4 3--6\n% \\/\n% 5\n%and graphs A3 and A4 are:\n%A3: A4:\n%1-----2 1-----2\n%|\\ /| |\\ /|\n%| 5-6 | | 5-6 |\n%| | | | | |\\| |\n%| 7-8 | | 7-8 |\n%|/ \\| |/ \\|\n%3-----4 3-----4\n% A1=[0,1,0,1;\n% 1,0,1,0;\n% 0,1,0,1;\n% 1,0,1,0];\n% A2=[0,1,0,1,0;\n% 1,0,1,0,0;\n% 0,1,0,1,1;\n% 1,0,1,0,1;\n% 0,0,1,1,0];\n% A3=[0,1,1,0,1,0,0,0;\n% 1,0,0,1,0,0,0,0;\n% 1,0,0,1,0,0,0,0;\n% 0,1,1,0,0,0,0,0;\n% 1,0,0,0,0,1,1,0;\n% 0,0,0,0,1,0,0,1;\n% 0,0,0,0,1,0,0,1;\n% 0,0,0,0,0,1,1,0];\n% A4=[0,1,1,0,1,0,0,0;\n% 1,0,0,1,0,0,0,0;\n% 1,0,0,1,0,0,0,0;\n% 0,1,1,0,0,0,0,0;\n% 1,0,0,0,0,1,1,1;\n% 0,0,0,0,1,0,0,1;\n% 0,0,0,0,1,0,0,1;\n% 0,0,0,0,1,1,1,0];\n% isBi1=graphIsBipartite(A1)\n% isBi2=graphIsBipartite(A2)\n% isBi3=graphIsBipartite(A3)\n% isBi4=graphIsBipartite(A4)\n%One will find that A1 and A3 are bipartite and A2 and A4 are not.\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\nn=size(A,1);\n\n%Allocate space.\nlink=zeros(n,1);\n\n%Step B1\ncolor=-1*ones(n,1);%In [1], it is indexed from 0, not 1; we index from 1.\nw=n+1;%Only need to consider the ones originating an edge.\n\nisBipartite=true;\nwhile(w~=1)\n w=w-1;\n \n %Step B3\n if(color(w)>=0)\n continue;\n end\n color(w)=0;\n link(w)=0;\n s=w;\n \n while(1)\n %Step B4\n u=s;\n s=link(s);\n\n aList=find(A(u,:));\n\n for a=1:length(aList)\n v=aList(a);\n\n if(color(v)<0)\n color(v)=1-color(u);\n link(v)=s;\n s=v;\n elseif(color(v)==color(u))\n isBipartite=false;\n return;\n end\n end\n if(s==0)\n break;\n end\n end\nend\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/Graph_Algorithms/graphIsBipartite.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.8872045862611166, "lm_q1q2_score": 0.8014067652404782}} {"text": "function [R] = Euler2RotMat(eul)\n% [R] = Euler2RotMat(theta_x, theta_y, theta_z)\n%\n% Stand-in for eul2rotm (built-in function MATLAB Robotics System Toolbox)\n% Converts Euler angles [rad] to 3x3 Rotation Matrix\n%\n% This implementation based on:\n% S.M.LaValle, Planning Algorithms, Cambridge University Press, 2006, p.98 \n% (PDF available here: http://planning.cs.uiuc.edu/ch3.pdf)\n% as cited in: http://nghiaho.com/?page_id=846 \n%\n% Inputs:\n% eul = [n x 3] - Euler Rotation Angles\n%\n% Outputs:\n% R = [3 x 3 x n] - rotation matrix. \n%\n% Written by Conrad McGreal @ 2019\nR = zeros(3,3,size(eul,1)) ; \n\nfor i=1:size(eul,1) \n theta_x = eul(i,1) ; \n theta_y = eul(i,2) ; \n theta_z = eul(i,3) ; \n\n X = [1 0 0\n 0 cos(theta_x) -sin(theta_x)\n 0 sin(theta_x) cos(theta_x)];\n\n Y = [cos(theta_y) 0 sin(theta_y)\n 0 1 0\n -sin(theta_y) 0 cos(theta_y)];\n\n Z = [cos(theta_z) -sin(theta_z) 0\n sin(theta_z) cos(theta_z) 0\n 0 0 1];\n\n R(:,:,i) = Z*Y*X;\nend", "meta": {"author": "MatthewPeterKelly", "repo": "OptimTraj", "sha": "c97b57fda511dacc6a6187f683428f0f3a1965f2", "save_path": "github-repos/MATLAB/MatthewPeterKelly-OptimTraj", "path": "github-repos/MATLAB/MatthewPeterKelly-OptimTraj/OptimTraj-c97b57fda511dacc6a6187f683428f0f3a1965f2/demo/quadRotor3d/utilities/Euler2RotMat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542864252023, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.8013576079923818}} {"text": "function y = msmoothboxlogpdf(x,a,b,sigma)\n%MSMOOTHBOXLOGPDF Multivariate smooth-box log probability density function.\n% Y = MSMOOTHBOXLOGPDF(X,A,B,SIGMA) returns the logarithm of the pdf of \n% the multivariate smooth-box distribution with pivots A and B and scale \n% SIGMA, evaluated at the values in X. The multivariate smooth-box pdf is\n% the product of univariate smooth-box pdfs in each dimension. \n%\n% For each dimension i, the univariate smooth-box pdf is defined as a\n% uniform distribution between pivots A(i), B(i) and Gaussian tails that\n% fall starting from p(A(i)) to the left (resp., p(B(i)) to the right) \n% with standard deviation SIGMA(i).\n% \n% X can be a matrix, where each row is a separate point and each column\n% is a different dimension. Similarly, A, B, and SIGMA can also be\n% matrices of the same size as X.\n%\n% The log pdf is typically preferred in numerical computations involving\n% probabilities, as it is more stable.\n%\n% See also MSMOOTHBOXPDF, MSMOOTHBOXRND.\n\n% Luigi Acerbi 2022\n\n[N,D] = size(x);\n\nif any(sigma(:) <= 0)\n error('msmoothboxpdf:NonPositiveSigma', ...\n 'All elements of SIGMA should be positive.'); \nend\n\nif D > 1\n if isscalar(a); a = a*ones(1,D); end\n if isscalar(b); b = b*ones(1,D); end\n if isscalar(sigma); sigma = sigma*ones(1,D); end\nend\n\nif size(a,2) ~= D || size(b,2) ~= D || size(sigma,2) ~= D\n error('msmoothboxpdf:SizeError', ...\n 'A, B, SIGMA should be scalars or have the same number of columns as X.');\nend\n\nif size(a,1) == 1; a = repmat(a,[N,1]); end\nif size(b,1) == 1; b = repmat(b,[N,1]); end\nif size(sigma,1) == 1; sigma = repmat(sigma,[N,1]); end\n\nif any(a(:) >= b(:))\n error('msmoothboxpdf:OrderError', ...\n 'For all elements of A and B, the order A < B should hold.');\nend\n\ny = -inf(size(x));\nlnf = log(1/sqrt(2*pi)./sigma) - log1p(1/sqrt(2*pi)./sigma.*(b - a));\n\nfor ii = 1:D\n idx = x(:,ii) < a(:,ii);\n y(idx,ii) = lnf(idx,ii) - 0.5*((x(idx,ii) - a(idx,ii))./sigma(idx,ii)).^2;\n\n idx = x(:,ii) >= a(:,ii) & x(:,ii) <= b(:,ii);\n y(idx,ii) = lnf(idx,ii);\n \n idx = x(:,ii) > b(:,ii);\n y(idx,ii) = lnf(idx,ii) - 0.5*((x(idx,ii) - b(idx,ii))./sigma(idx,ii)).^2; \nend\n\ny = sum(y,2);", "meta": {"author": "acerbilab", "repo": "vbmc", "sha": "54ba2cdd6c11d2595b9613557da14573abbb7b92", "save_path": "github-repos/MATLAB/acerbilab-vbmc", "path": "github-repos/MATLAB/acerbilab-vbmc/vbmc-54ba2cdd6c11d2595b9613557da14573abbb7b92/shared/msmoothboxlogpdf.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.8013205966566025}} {"text": "function [J, grad] = lrCostFunction(theta, X, y, lambda)\n%LRCOSTFUNCTION Compute cost and gradient for logistic regression with \n%regularization\n% J = LRCOSTFUNCTION(theta, X, y, lambda) computes the cost of using\n% theta as the parameter for regularized logistic regression and the\n% gradient of the cost w.r.t. to the parameters. \n\n% Initialize some useful values\nm = length(y); % number of training examples\n\n% You need to return the following variables correctly \nJ = 0;\ngrad = zeros(size(theta));\n\n% ====================== YOUR CODE HERE ======================\n% Instructions: Compute the cost of a particular choice of theta.\n% You should set J to the cost.\n% Compute the partial derivatives and set grad to the partial\n% derivatives of the cost w.r.t. each parameter in theta\n%\n% Hint: The computation of the cost function and gradients can be\n% efficiently vectorized. For example, consider the computation\n%\n% sigmoid(X * theta)\n%\n% Each row of the resulting matrix will contain the value of the\n% prediction for that example. You can make use of this to vectorize\n% the cost function and gradient computations. \n%\n% Hint: When computing the gradient of the regularized cost function, \n% there're many possible vectorized solutions, but one solution\n% looks like:\n% grad = (unregularized gradient for logistic regression)\n% temp = theta; \n% temp(1) = 0; % because we don't add anything for j = 0 \n% grad = grad + YOUR_CODE_HERE (using the temp variable)\n%\n\ntempTheta = theta;\ntempTheta(1) = 0;\n\nJ = (-1 / m) * sum(y.*log(sigmoid(X * theta)) + (1 - y).*log(1 - sigmoid(X * theta))) + (lambda / (2 * m))*sum(tempTheta.^2);\ntemp = sigmoid (X * theta);\nerror = temp - y;\ngrad = (1 / m) * (X' * error) + (lambda/m)*tempTheta;\n\n\n\n\n\n\n\n\n\n\n% =============================================================\n\ngrad = grad(:);\n\nend\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-ex3/ex3/lrCostFunction.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850021922959, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.8013205964569692}} {"text": "function dist = distancePoints3d(p1, p2, varargin)\n%DISTANCEPOINTS3D Compute euclidean distance between pairs of 3D Points\n%\n% D = distancePoints3d(P1, P2) return distance between points P1 and\n% P2, given as [X Y Z].\n% \n% If P1 and P2 are two arrays of points, result is a N1*N2 array\n% containing distance between each point of P1 and each point of P2. \n%\n%\n% D = distancePoints3d(P1, P2, NOR)\n% with NOR being 1, 2, or Inf, corresponfing to the norm used. Default is\n% 2 (euclidean norm). 1 correspond to manhattan (or taxi driver) distance\n% and Inf to maximum difference in each coordinate.\n%\n%\n% See also:\n% points3d, minDistancePoints, distancePoints\n%\n% ---------\n%\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 18/02/2005.\n%\n\n% HISTORY\n% 21/02/2005: add different norms\n% 28/08/2007: deprecate\n\nnorm = 2;\nif length(varargin)==1\n norm = varargin{1};\nend\n\n% compute difference of coordinate for each pair of points\nptsDiff = bsxfun(@minus, p2, p1);\n\n% Return dist based on the type of measurement requested\nswitch(norm)\n case 1\n dist = sum(abs(ptsDiff),2);\n case 2\n dist = vectorNorm3d(ptsDiff);\n case Inf\n dist = max(abs(ptsDiff), [], 2);\n otherwise\n dist = power(sum(power(ptsDiff, norm),2), 1/norm);\nend\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/distancePoints3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9518632329799585, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.8013028784210117}} {"text": "% Mathematics Q2199546\n% https://math.stackexchange.com/questions/2199546\n% Minimizing the Sum of Quadratic Form with Equality Constraint\n% References:\n% 1. aa\n% Remarks:\n% 1. sa\n% TODO:\n% \t1. ds\n% Release Notes\n% - 1.0.000 29/07/2017\n% * First release.\n\n\n%% General Parameters\n\nrun('InitScript.m');\n\nfigureIdx = 0; %\n%\n%Copyright (c) 2000 RICE UNIVERSITY. All rights reserved.\n%Created by Haitao Guo, Department of ECE, Rice University. \n%\n%This software is distributed and licensed to you on a non-exclusive \n%basis, free-of-charge. Redistribution and use in source and binary forms, \n%with or without modification, are permitted provided that the following \n%conditions are met:\n%\n%1. Redistribution of source code must retain the above copyright notice, \n% this list of conditions and the following disclaimer.\n%2. Redistribution in binary form must reproduce the above copyright notice, \n% this list of conditions and the following disclaimer in the \n% documentation and/or other materials provided with the distribution.\n%3. All advertising materials mentioning features or use of this software \n% must display the following acknowledgment: This product includes \n% software developed by Rice University, Houston, Texas and its contributors.\n%4. Neither the name of the University nor the names of its contributors \n% may be used to endorse or promote products derived from this software \n% without specific prior written permission.\n%\n%THIS SOFTWARE IS PROVIDED BY WILLIAM MARSH RICE UNIVERSITY, HOUSTON, TEXAS, \n%AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, \n%BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS \n%FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RICE UNIVERSITY \n%OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, \n%EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, \n%PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; \n%OR BUSINESS INTERRUPTIONS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \n%WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR \n%OTHERWISE), PRODUCT LIABILITY, OR OTHERWISE ARISING IN ANY WAY OUT OF THE \n%USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n%\n%For information on commercial licenses, contact Rice University's Office of \n%Technology Transfer at techtran@rice.edu or (713) 348-6173\n%\n%Change History:\n%\n\nx = abs(y);\nx = sign(y).*(x >= thld).*(x - thld); \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/utils/utils_WaveletRice/SoftTh.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802350995702, "lm_q2_score": 0.8723473730188543, "lm_q1q2_score": 0.8012338202588498}} {"text": "function centroid = polygon_centroid_2 ( n, v )\n\n%*****************************************************************************80\n%\n%% POLYGON_CENTROID_2 computes the centroid of a polygon.\n%\n% Discussion:\n%\n% The centroid is the area-weighted sum of the centroids of\n% disjoint triangles that make up the polygon.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 17 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(2,N), the coordinates of the vertices.\n%\n% Output, real CENTROID(2,1), the coordinates of the centroid.\n%\n area = 0.0;\n centroid(1:2,1) = 0.0;\n\n for i = 1 : n - 2\n\n area_triangle = triangle_area ( ...\n v(1,i), v(2,i), ...\n v(1,i+1), v(2,i+1), ...\n v(1,n), v(2,n) );\n\n area = area + area_triangle;\n\n centroid(1:2,1) = centroid(1:2,1) + area_triangle ...\n * ( v(1:2,i) + v(1:2,i+1) + v(1:2,n) ) / 3.0;\n\n end\n\n if ( area == 0.0 )\n centroid(1:2,1) = v(1:2,1);\n else\n centroid(1:2,1) = centroid(1:2,1) / area;\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/polygon_properties/polygon_centroid_2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294587, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.8011035450465768}} {"text": "function [ p, seed ] = triangle_sample ( t, n, seed )\n\n%*****************************************************************************80\n%\n%% TRIANGLE_SAMPLE returns random points in a triangle.\n%\n% Discussion:\n%\n% In order to compare the results of this program with the\n% C++ and FORTRAN90 versions, it is useful to use R8VEC_UNIFORM_01\n% to generate the random numbers. However, it is much faster\n% to rely on MATLAB's RAND routine to do this. So if speed\n% is a consideration, replace the calls to R8VEC_UNIFORM_01\n% as indicated.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 10 April 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real T(2,3), the triangle vertices.\n%\n% Input, integer N, the number of points to generate.\n%\n% Input, integer SEED, a seed for the random number generator.\n% Only needed if R8VEC_UNIFORM_01 is used.\n%\n% Output, real P(2,N), random points in the triangle.\n%\n% Output, integer SEED, a seed for the random number generator.\n%\n dim_num = 2;\n%\n% For fast execution, call RAND:\n%\n% alpha = rand ( 1, n );\n%\n% For comparison with F90 and C++, call R8VEC_UNIFORM:\n%\n [ alpha, seed ] = r8vec_uniform_01 ( n, seed );\n%\n% Interpret R as a percentage of the triangle's area.\n%\n% Imagine a line L, parallel to side 1, so that the area between\n% vertex 1 and line L is R percent of the full triangle's area.\n%\n% The line L will intersect sides 2 and 3 at a fraction\n% ALPHA = SQRT ( R ) of the distance from vertex 1 to vertices 2 and 3.\n%\n alpha(1:n) = sqrt ( alpha(1:n) );\n%\n% Determine the coordinates of the points on sides 2 and 3 intersected\n% by line L.\n%\n for dim = 1 : dim_num\n p12(dim,1:n) = ( 1.0 - alpha(1:n) ) * t(dim,1) ...\n + alpha(1:n) * t(dim,2);\n\n p13(dim,1:n) = ( 1.0 - alpha(1:n) ) * t(dim,1) ...\n + alpha(1:n) * t(dim,3);\n end\n%\n% Now choose, uniformly at random, a point on the line L.\n%\n% For fast execution, call RAND:\n%\n% alpha = rand ( 1, n );\n%\n% For comparison with F90 and C++, call R8VEC_UNIFORM:\n%\n [ alpha, seed ] = r8vec_uniform_01 ( n, seed );\n\n for dim = 1 : dim_num\n p(dim,1:n) = ( 1.0 - alpha(1:n) ) .* p12(dim,1:n) ...\n + alpha(1:n) .* p13(dim,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/quad_mesh/triangle_sample.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.8791467659263147, "lm_q1q2_score": 0.8010606994754669}} {"text": "function [ n_data, x, fx ] = shi_values ( n_data )\n\n%*****************************************************************************80\n%\n%% SHI_VALUES returns some values of the hyperbolic sine integral function.\n%\n% Discussion:\n%\n% SHI(X) = integral ( 0 <= T <= X ) sinh ( T ) / T dt\n%\n% In Mathematica, the function can be evaluated by:\n%\n% SinhIntegral[x]\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 11 June 2007\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% Stephen Wolfram,\n% The Mathematica Book,\n% Fourth Edition,\n% Cambridge University Press, 1999,\n% ISBN: 0-521-64314-7,\n% LC: QA76.95.W65.\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, real X, the argument of the function.\n%\n% Output, real FX, the value of the function.\n%\n n_max = 16;\n\n fx_vec = [ ...\n 0.5069967498196672, ...\n 0.6121303965633808, ...\n 0.7193380189288998, ...\n 0.8289965633789345, ...\n 0.9414978265114335, ...\n 1.057250875375729, ...\n 1.300250361022057, ...\n 1.561713388361002, ...\n 1.845814141358504, ...\n 2.157290343425901, ...\n 2.501567433354976, ...\n 3.549340406224435, ...\n 4.973440475859807, ...\n 6.966162067504942, ...\n 9.817326911233034, ...\n 13.96788504934715 ];\n\n x_vec = [ ...\n 0.5E+00, ...\n 0.6E+00, ...\n 0.7E+00, ...\n 0.8E+00, ...\n 0.9E+00, ...\n 1.0E+00, ...\n 1.2E+00, ...\n 1.4E+00, ...\n 1.6E+00, ...\n 1.8E+00, ...\n 2.0E+00, ...\n 2.5E+00, ...\n 3.0E+00, ...\n 3.5E+00, ...\n 4.0E+00, ...\n 4.5E+00 ];\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 x = 0.0;\n fx = 0.0;\n else\n x = x_vec(n_data);\n fx = fx_vec(n_data);\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/test_values/shi_values.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.8791467564270271, "lm_q1q2_score": 0.8010606844585634}} {"text": "\n% plot real and imaginary parts of various finite difference derivative operators\n% input: c = scalar multiplier \n% input: M = number of points on interval (excluding one end point)\n% input: dx = uniform grid point separation \n\nfunction plotmultiplies(c, M, dx)\n\nm=0:(M-1);\n\nthetam = 2*pi*m/M;\n\ndeltaR = c*(exp(i*thetam)-1)/dx;\ndeltaL = c*(1-exp(-i*thetam))/dx;\ndeltaC = i*c*sin(thetam)/dx;\ndeltaC4 = i*c*(8*sin(thetam)-sin(2*thetam))/(6*dx);\ndeltaC6 = i*c*sin(thetam).*(1+(2/3)*sin(thetam/2).^2 +(8/15)*sin(thetam/2).^4)/dx;\n\n% plot real part of eigenvalues\nsubplot(1,2,1); \nplot(thetam, real(deltaR), 'r-d');\nhold on; \nplot(thetam, real(deltaL), 'b-*');\nplot(thetam, real(deltaC), 'g-s');\nplot(thetam, real(deltaC4), 'k-o');\nhold off;\nxlabel('\\theta_m = 2\\pim/M', 'FontSize', 18);\ntitle('Real part of ODE multipliers', 'FontSize', 18);\nlegend('\\delta_+', '\\delta_-', '\\delta_0', '\\delta_0(1-(1/6)dx^2\\delta^2)');\n\n% plot imaginary part of eigenvalues \nsubplot(1,2,2); \nplot(thetam, imag(deltaR), 'r-d');\nhold on; \nplot(thetam, imag(deltaL), 'b-*');\nplot(thetam, imag(deltaC), 'g-s');\nplot(thetam, imag(deltaC4), 'k-o');\nplot(thetam, imag(deltaC6), 'm-h');\nplot([0 pi], [0 pi], 'k-', 'LineWidth', 2); % first part of correct phase relationship\nplot([pi 2*pi], [-pi 0], 'k-', 'LineWidth', 2); % second part\n\nhold off;\nxlabel('\\theta_m = 2\\pim/M', 'FontSize', 18);\ntitle('Imaginary part of ODE multipliers', 'FontSize', 18);\nlegend('\\delta_+', '\\delta_-', '\\delta_0', '\\delta_0(1-(1/6)dx^2\\delta^2)', '6th order central difference', 'Exact');\n\n\n\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/NumericalMethods/plotmultiplies.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.8688267830311354, "lm_q1q2_score": 0.80099038571094}} {"text": "function val=tanDerivVal(z,n)\n%%TANDERIVVAL Return the value of the nth derivative of tan(x) with respect\n% to x evaluated at x=z.\n%\n%INPUTS: z A matrix of real or complex values at which the nth derivative\n% of the tangent function is desired.\n% n The number of derivatives to take. n>=0.\n%\n%OUTPUTS: val The value of the nth derivative of the tangent function taken\n% at all of the points in z. val has the same dimensions as z.\n%\n%This function implements the algorithm of [1].\n%\n%REFERENCES:\n%[1] M. E. Hoffman, \"Derivative polynomials for tangent and secant,\" The\n% American Mathematical Monthly, vol. 102, no. 1, pp. 23-30, Jan. 1995.\n%\n%October 2016 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nnumEls=numel(z);\n\nval=zeros(size(z));\nfor curEl=1:numEls\n x=z(curEl);\n u=tan(x);\n\n P=zeros(n+1,1);\n P(1)=u;\n \n %The loop implements Equation 5.\n for k=1:n\n sumVal=0;\n for i=0:(k-1)\n sumVal=sumVal+binomial(k-1,i)*P(i+1)*P(k-1-i+1);\n end\n if(k==1)\n sumVal=sumVal+1;\n end\n P(k+1)=sumVal;\n end\n val(curEl)=P(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/Specific_Derivatives/tanDerivVal.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.9059898178450964, "lm_q1q2_score": 0.8009305823011283}} {"text": "% Spherical Harmonics basis of order lmax.\n% NB: the definition now matches the one in DIPY\nfunction Ylm = AMICO_CreateYlm( lmax, colatitude, longitude )\n\nYlm = zeros( size(longitude,1), (lmax+2)*(lmax+1)/2 );\nfor l = 0:2:lmax\n Pm = legendre(l,cos(colatitude'))';\n lconstant = sqrt((2*l + 1)/(4*pi));\n\n center = (l+1)*(l+2)/2 - l;\n Ylm(:,center) = lconstant*Pm(:,1);\n for m=1:l\n precoeff = lconstant * sqrt(factorial(l - m)/factorial(l + m));\n\n\t\tYlm(:, center - m) = sqrt(2)*precoeff*Pm(:,m+1).*cos(m*longitude);\n\t\tYlm(:, center + m) = sqrt(2)*precoeff*Pm(:,m+1).*sin(m*longitude);\n\tend\nend\n", "meta": {"author": "qMRLab", "repo": "qMRLab", "sha": "036ff20b47e939877f746940a969494b55911636", "save_path": "github-repos/MATLAB/qMRLab-qMRLab", "path": "github-repos/MATLAB/qMRLab-qMRLab/qMRLab-036ff20b47e939877f746940a969494b55911636/External/AMICO/AMICO_matlab/kernels/AMICO_CreateYlm.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9585377225508371, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.800842480994083}} {"text": "function [p,d]=berk2prob(b)\n%BERK2PROB convert Berksons to probability\n%\n% Inputs: B(M,N) matrix containing Berkson values\n%\n% Outputs: P(M,N) Corresponding probability values\n% D(M,N) Corresponding derivatives dP/dB\n%\n% Berksons, or log-odds, are a nonlinear scale for measuring\n% probability defined by B = log2(P./(1-P)).\n% When Berksons are used to measure probability, a logistic\n% psychometric function becomes linear.\n%\n% The inverse function is berk2prob()\n\n% Copyright (C) Mike Brookes 2014\n% Version: $Id: berk2prob.m 4501 2014-04-24 06:28:21Z 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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\np=1-1./(1+pow2(b));\nif nargout>1\n d=log(2)*p.*(1-p);\nend", "meta": {"author": "jtkim-kaist", "repo": "VAD", "sha": "a1e0b1299fcf22eb7654b2906a67184c73b37faa", "save_path": "github-repos/MATLAB/jtkim-kaist-VAD", "path": "github-repos/MATLAB/jtkim-kaist-VAD/VAD-a1e0b1299fcf22eb7654b2906a67184c73b37faa/lib/matlab/voicebox/berk2prob.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966762263736, "lm_q2_score": 0.8459424334245617, "lm_q1q2_score": 0.8007662957585404}} {"text": "function dx = not2dx ( x1, y1, x2, y2, x3, y3, x4, y4 )\n\n%*****************************************************************************80\n%\n%% NOT2DX evaluates a factor for serendipity basis functions.\n%\n% Discussion:\n%\n% not2(x1,y1,x2,y2,x3,y3,x4,y4) evaluates at the point (x1,y1), the basis \n% factor that is 0 at (x2,y2) and (x3,y3) and 1 at (x4,y4):\n%\n% ( ( x1 - x2 ) * ( y3 - y2 ) - ( x3 - x2 ) * ( y1 - y2 ) )\n% / ( ( x4 - x2 ) * ( y3 - y2 ) - ( x3 - x2 ) * ( y4 - y2 ) )\n%\n% not2dx returns the derivative of this function with respect to X1.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 28 June 2014\n%\n% Author:\n%\n% John Burkardt\n%\n% Parameters:\n%\n% Input, real X1, Y2, the evaluation point.\n%\n% Input, real X2, Y2, X3,Y3, values that define the factor.\n%\n% Output, real DX, the derivative of the basis function factor\n% with respect to X1.\n%\n dx = ( 1.0 * ( y3 - y2 ) + 0.0 ) ...\n / ( ( x4 - x2 ) * ( y3 - y2 ) - ( x3 - x2 ) * ( y4 - y2 ) );\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_bvp_serene/not2dx.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133515091156, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.8007618151921573}} {"text": "function E = ECGModelError(X,ECGmn,Phasemn,flag)\n% E = ECGModelError(X,ECGmn,Phasemn,flag)\n% Overview: Generate Synthetic ECG beat with parameters given in the variable X. Generate the artificial ECG\n% over phase given in Phasemn. Compute the ECGModelError as the difference between the synthetic\n% ECG beat and ECG beat stored in ECGmn. \n%\n% Inputs:\n% X - contains the amplitude (alphai), standard deviation (bi) and phase (tetai) for\n% each Gaussian function used for generating the synthetic ECG beat.\n%\n% ECGmn - Average ECG beat estimated from the ECG analysis\n% window. \n% \n% Phasemn - array contains the phase points over which the synthetic\n% ECG beat is generated.\n%\n% flag - set to 1 to return generated sythetic ECG beat. Set to 0 to\n% return the difference between generated synthetic ECG beat and average ECG beat for analysis window. \n%\n% Outputs:\n% E - synthetic ECG beat generated using Gaussian parameter estimates if flag set to 1.\n% difference between synthetic ECG beat and average ECG beat for analysis window if flag set to 0. \n%\n% Open Source ECG Toolbox, version 1.0, November 2006\n% Released under the GNU General Public License\n% Copyright (C) 2006 Reza Sameni\n% Sharif University of Technology, Tehran, Iran -- LIS-INPG, Grenoble, France\n% reza.sameni@gmail.com\n% last modified:\n% on 11/30/2020 by Ismail Sadiq\n%\n% This program is free software; you can redistribute it and/or modify it\n% under the terms of the GNU General Public License as published by the\n% Free Software Foundation; either version 2 of the License, or (at your\n% option) any later version.\n% This program is distributed in the hope that it will be useful, but\n% WITHOUT ANY WARRANTY; without even the implied warranty of\n% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General\n% Public License for more details. You should have received a copy of the\n% GNU General Public License along with this program; if not, write to the\n% Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,\n% MA 02110-1301, USA.\n\nL = (length(X)/3);\n\nalphai = X(1:L);\nbi = X(L+1:2*L);\ntetai = X(2*L+1:3*L);\n\nZ = zeros(size(ECGmn));\nfor j = 1:length(alphai),\n dtetai = rem(Phasemn - tetai(j) + pi,2*pi)-pi;\n Z = Z + alphai(j) .* exp(-dtetai .^2 ./ (2*bi(j) .^ 2));\nend\n\nif(flag==0)\n E = (Z-ECGmn);\nelseif(flag==1)\n E = Z;\nend", "meta": {"author": "cliffordlab", "repo": "PhysioNet-Cardiovascular-Signal-Toolbox", "sha": "eec46e75e0b95c379ecb68cb0ebee0c4c9f54605", "save_path": "github-repos/MATLAB/cliffordlab-PhysioNet-Cardiovascular-Signal-Toolbox", "path": "github-repos/MATLAB/cliffordlab-PhysioNet-Cardiovascular-Signal-Toolbox/PhysioNet-Cardiovascular-Signal-Toolbox-eec46e75e0b95c379ecb68cb0ebee0c4c9f54605/Tools/ECG_Analysis_Tools/MV/Tools/ECGBeatFitterAlgo/ECGModelError.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913343093499, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.8007618115555306}} {"text": "%-----------------------------------------\n% UNIVERSITY OF TENAGA NASIONAL\n% PROGRAMMER: MOHD ANUAR ABD AZIZ\n% STUDENT ID: ME071642\n% SUBJECT : COMPUTATIONAL FLUID DYNAMICS\n% ASSIGNMENT 1\n% MATLAB 6.5\n%16 Feb 2005\n% ------------------------------------------\nclc\nclear all\nN=200;\nL=2;\ndx=L/N;\nn2=25; \ntb=400+273.15;\nta=34+273.15;\nomega=1.78;\neps=1e-6; %minimum error being set\n\nglobal N omega eps L dx n2 tb ta \nwarning off\n%-----------------------------------------\n% GET NUMBER OF ITERATION FOR EVERY METHOD\n% ------------------------------------------\n[iter,T]=JACOBBI;\nfprintf('Jacobbi method\\t\\t: %d iteration \\n',iter);\n[iter,T]=GS;\nfprintf('Gauss-Seidel method\\t: %d iteration \\n',iter);\n[iter,T]=SOR;\nfprintf('SOR method\\t\\t\\t: %d iteration \\n',iter);\n%----------------------------------------------------\n% GENERATE ACTUAL/THEORETICAL TEMPERATURE DISTRIBUTION\n% ----------------------------------------------------\nx=mesh;\nfor i=1:N+2\n A=cosh(sqrt(n2)*(L-x(i)))/cosh(sqrt(n2)*L);\n T(i)=(tb-ta)*A+ta;\nend\nTa=T(101);\nplot(x,T,'b')\nhold\n%-----------------------------------------\n% GET RESULT AND ERROR FOR EVERY NUMBER OF\n% MESH AND PLOT THE GRAPH\n% ------------------------------------------\nN=25;\nx=mesh;\n[iter,T]=SOR;\nplot(x,T,'g')\n[y,i]=min(abs(ones(size(x))-x));\nerr(1)=abs(T(i)-ta)*100/ta;\nerrm(1)=N;\n\nN=50;\nx=mesh;\n[iter,T]=SOR;\nplot(x,T,'r')\n[y,i]=min(abs(ones(size(x))-x));\nerr(2)=abs(T(i)-ta)*100/ta;\nerrm(2)=N;\n\nN=75;\nx=mesh;\n[iter,T]=SOR;\nplot(x,T,'c')\n[y,i]=min(abs(ones(size(x))-x));\nerr(3)=abs(T(i)-ta)*100/ta;\nerrm(3)=N;\n\nN=100;\nx=mesh;\n[iter,T]=SOR;\nplot(x,T,'m')\n[y,i]=min(abs(ones(size(x))-x));\nerr(4)=abs(T(i)-ta)*100/ta;\nerrm(4)=N;\n\nN=200;\nx=mesh;\n[iter,T]=SOR;\nplot(x,T,'y')\n[y,i]=min(abs(ones(size(x))-x));\nerr(5)=abs(T(i)-ta)*100/ta;\nerrm(5)=N;\n\nlegend('Actual', '25 mesh','50 mesh','75 mesh','100 mesh','200 mesh');\nhold \nxlabel('Distance, X, in meter');\nylabel('Temperature, teta, in Kelvin');\ntitle('Temperature across fin from the base x=0');\ngrid\nfigure\nplot(errm,err)\nxlabel('Number of mesh, N');\nylabel('% difference/error');\ntitle('error vs number of mesh at x= 1.0 m');\ngrid\nfprintf('\\n\\nNote:-\\n\\tOptimum omega value is %g\\n\\tObtained from mfile optimum.m for N=200 mesh',omega);", "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/7004-jacobbi-gauss-seidel-sor-in-cfd/cfd1.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.8740772450055545, "lm_q1q2_score": 0.8007505631653848}} {"text": "function vn = normalizeVector(v)\n%NORMALIZEVECTOR Normalize a vector to have norm equal to 1\n%\n% V2 = normalizeVector(V);\n% Returns the normalization of vector V, such that ||V|| = 1. V can be\n% either a row or a column vector.\n%\n% When V is a MxN array, normalization is performed for each row of the\n% array.\n%\n% Example:\n% vn = normalizeVector([3 4])\n% vn =\n% 0.6000 0.8000\n% vectorNorm(vn)\n% ans =\n% 1\n%\n% See Also:\n% vectors2d, vectorNorm\n%\n%\n% ---------\n%\n% author : David Legland \n% INRA - TPV URPOI - BIA IMASTE\n% created the 29/11/2004.\n%\n\n% HISTORY\n% 2005-01-14 correct bug\n% 2009-05-22 rename as normalizeVector\n% 2011-01-20 use bsxfun\n\ndim = size(v);\n\nif dim(1)==1 || dim(2)==1\n % in case of one vector, the norm is a scalar\n vn = v / sqrt(sum(v.^2));\nelse\n % for several vectors, need to adapt size of norm\n vn = bsxfun(@rdivide, v, sqrt(sum(v.^2, 2)));\n %same as: vn = v./repmat(sqrt(sum(v.*v, 2)), [1 dim(2)]);\nend\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/geom2d/normalizeVector.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.916109606718245, "lm_q2_score": 0.8740772466456689, "lm_q1q2_score": 0.8007505626659301}} {"text": "function MDDot=rotMatSecondDeriv2D(theta,thetaDot,thetaDDot,isClockwise)\n%%ROTMATSECONDDERIV2D Given an initial angle of rotation, and the first and\n% second derivatives of the angle with respect to time, find the\n% derivative of the 2D rotation matrix. This is the second time\n% derivative of rotMat2D assuming that the rotation angle changes as a\n% function of time.\n%\n%INPUTS: theta The initial rotation angle radians about which the\n% time-varying 2D rotation matrix would rotate a 2X1 vector at\n% the current time.\n% thetaDot The derivative of theta with respect to time.\n% thetaDDot The second derivative of theta with respect to time.\n% isClockwise An optional boolean parameter indication whether the\n% rotation implied by theta is clockwise. The default if\n% omitted or an empty matrix is passed is false.\n%\n%OUTPUTS: MDDot The 2X2 second derivative of the rotation matrix (as one\n% could obtain using rotMat2D) with respect to time.\n%\n%EXAMPLE:\n%This example shows that this function is consistent with numeric\n%differentiation. The relative error of the finite differenced solution\n%typically implies for 6-8 digits of precision.\n% theta=2*pi*rand(1);\n% thetaDot=randn(1);\n% thetaDDot=randn(1);\n% thetaState=[theta;thetaDot;thetaDDot];\n% isClockwise=false;\n% MDDot=rotMatSecondDeriv2D(theta,thetaDot,thetaDDot,isClockwise);\n% \n% MDot=rotMatDeriv2D(theta,thetaDot,isClockwise);\n% %Propagate deltaT into the future for finite differencing. This is just a\n% %second order linear model applied to the thetaState.\n% deltaT=1e-8;\n% order=2;\n% F=FPolyKal(deltaT,3,order);\n% thetaStateDelta=F*thetaState;\n% MDotDelta=rotMatDeriv2D(thetaStateDelta(1),thetaStateDelta(2),isClockwise);\n% MDDotNumDiff=(MDotDelta-MDot)/deltaT;\n% RelErr=max(abs((MDDotNumDiff(:)-MDDot(:))./MDDot(:)))\n%\n%December 2022 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nif(nargin<4||isempty(isClockwise))\n isClockwise=false; \nend\n\nsinTheta=sin(theta);\ncosTheta=cos(theta);\n\nif(isClockwise)\n MDDot=[-cosTheta*thetaDot^2-sinTheta*thetaDDot,-sinTheta*thetaDot^2+cosTheta*thetaDDot;\n sinTheta*thetaDot^2-cosTheta*thetaDDot,-cosTheta*thetaDot^2-sinTheta*thetaDDot];\nelse\n MDDot=[-cosTheta*thetaDot^2-sinTheta*thetaDDot, sinTheta*thetaDot^2-cosTheta*thetaDDot;\n -sinTheta*thetaDot^2+cosTheta*thetaDDot,-cosTheta*thetaDot^2-sinTheta*thetaDDot];\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/Coordinate_Systems/Rotations/rotMatSecondDeriv2D.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.8007505586578111}} {"text": "function g = givens2(a,b)\n%GIVENS2 find a Givens rotation.\n% Example:\n% g = givens2(a,b)\n% See also: cs_demo\n\n% Copyright 2006-2007, Timothy A. Davis.\n% http://www.cise.ufl.edu/research/sparse\n\nif (b == 0)\n c = 1 ; s = 0 ;\nelseif (abs (b) > abs (a))\n tau = -a/b ; s = 1 / sqrt (1+tau^2) ; c = s*tau ;\nelse\n tau = -b/a ; c = 1 / sqrt (1+tau^2) ; s = c*tau ;\nend\ng = [c -s ; s c] ;\n", "meta": {"author": "fieldtrip", "repo": "fieldtrip", "sha": "c2039be598a02d86b39aae76bfa7aaa720f9801c", "save_path": "github-repos/MATLAB/fieldtrip-fieldtrip", "path": "github-repos/MATLAB/fieldtrip-fieldtrip/fieldtrip-c2039be598a02d86b39aae76bfa7aaa720f9801c/external/dmlt/external/gpstuff/SuiteSparse/CXSparse/MATLAB/Test/givens2.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.8007445489283248}} {"text": "% Sparse covariance estimation for Gaussian variables\n% Joëlle Skaf - 04/24/08 \n% (a figure is generated)\n% \n% Suppose y \\in\\reals^n is a Gaussian random variable with zero mean and \n% covariance matrix R = \\Expect(yy^T), with sparse inverse S = R^{-1} \n% (S_ij = 0 means that y_i and y_j are conditionally independent).\n% We want to estimate the covariance matrix R based on N independent \n% samples y1,...,yN drawn from the distribution, and using prior knowledge \n% that S is sparse\n% A good heuristic for estimating R is to solve the problem \n% maximize logdet(S) - tr(SY) - lambda*sum(sum(abs(S)))\n% subject to S >= 0\n% where Y is the sample covariance of y1,...,yN, and lambda is a sparsity\n% parameter to be chosen or tuned. \n% A figure showing the sparsity (number of nonzeros) of S versus lambda \n% is generated.\n\n% Input data \nrandn('state',0);\nn = 10; \nN = 100; \nStrue = sprandsym(n,0.5,0.01,1);\nnnz_true = sum(Strue(:)>1e-4);\nR = inv(full(Strue));\ny_sample = sqrtm(R)*randn(n,N); \nY = cov(y_sample'); \nNlambda = 20;\nlambda = logspace(-2, 3, Nlambda);\nnnz = zeros(1,Nlambda);\n\nfor i=1:Nlambda\n disp(['i = ' num2str(i) ', lambda(i) = ' num2str(lambda(i))]); \n % Maximum likelihood estimate of R^{-1}\n cvx_begin sdp quiet\n variable S(n,n) symmetric\n maximize log_det(S) - trace(S*Y) - lambda(i)*sum(sum(abs(S)))\n S >= 0\n cvx_end\n nnz(i) = sum(S(:)>1e-4);\nend\n\nfigure; \nsemilogx(lambda, nnz); \nhold on; \nsemilogx(lambda, nnz_true*ones(1,Nlambda),'r');\nxlabel('\\lambda');\nlegend('nonzeros in S', 'nonzeros in R^{-1}'); \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/log_exp/sparse_covariance_est_tradeoff.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422241476943, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.8006959241331054}} {"text": "function p = circle_imp_points_2d ( r, center, n )\n\n%*****************************************************************************80\n%\n%% CIRCLE_IMP_POINTS_2D returns N equally spaced points on an implicit circle in 2D.\n%\n% Discussion:\n%\n% The first point is always ( CENTER(1) + R, CENTER(2) ), and subsequent\n% points proceed counterclockwise around the circle.\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% 04 December 2010\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,1), the center of the circle.\n%\n% Input, integer N, the number of points desired. N must be at least 1.\n%\n% Output, real P(2,N), the coordinates of points\n% on the circle.\n%\n for i = 1 : n\n theta = ( 2.0 * pi * ( i - 1 ) ) / n;\n p(1,i) = center(1,1) + r * cos ( theta );\n p(2,i) = center(2,1) + r * sin ( theta );\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/circle_imp_points_2d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.8006776890657741}} {"text": "function sp = spdimcc(n, d)\n% SPDIMCC Compute number of sparse grid points, Clenshaw-Curtis grid\n% SP = SPDIMCC(N,D) Computes the number of sparse grid points\n%\t of the Clenshaw-Gurtis grid of dimension D and level N.\n% (Internal function)\n\n% The function uses the formulas for N <= 7 given in A. Schreiber:\n% Die Methode von Smoliak bei der multivariaten Interpolation,\n% (2000), p.35/36. \n\t\n% Author : Andreas Klimke, Universitaet Stuttgart\n% Version: 1.0\n% Date : August 5, 2003\n\n% ------------------------------------------------------------\n% Sparse Grid Interpolation Toolbox\n% Copyright (c) 2006 W. Andreas Klimke, Universitaet Stuttgart \n% Copyright (c) 2007-2008 W. A. Klimke. All Rights Reserved.\n% See LICENSE.txt for license. \n% email: klimkeas@ians.uni-stuttgart.de\n% web : http://www.ians.uni-stuttgart.de/spinterp\n% ------------------------------------------------------------\n\nswitch n\n case 0\n\tsp = 1;\n case 1\n\tsp = 2*d + 1;\n case 2\n\tsp = 2*d^2 + 2*d + 1;\n case 3\n\tsp = round((4*d^3 + 6*d^2 + 14*d)/3) + 1;\n case 4 \n\tsp = round((2*d^4 + 4*d^3 + 22*d^2 + 20*d)/3) + 1;\n case 5\n\tsp = round((4*d^5 + 10*d^4 + 100*d^3 + 170*d^2 + 196*d)/15) + 1;\n case 6\n\tsp = round((4*d^6 + 12*d^5 + 190*d^4 + 480*d^3 + 1246*d^2 + 948* ...\n\t\t\t\t\t\t\td)/45) + 1; \n case 7\n\tsp = round((8*d^7 + 28*d^6 + 644*d^5 + 2170*d^4 + 9632*d^3 + ...\n\t\t\t\t\t\t\t15442*d^2 + 12396*d)/315) + 1;\n otherwise\n\tsp = round((8*d^7 + 28*d^6 + 644*d^5 + 2170*d^4 + 9632*d^3 + ...\n\t\t\t\t\t\t\t15442*d^2 + 12396*d)/315) + 1;\n\tfor m = 8:n\n\t\tseq = spgetseq(m,d);\n\t\tfor k = 1:size(seq,1)\n\t\t\ttemp = 1;\n\t\t\tfor l = 1:d\n\t\t\t\tlval = seq(k,l);\n\t\t\t\tif lval == 0\n\t\t\t\telseif lval < 3\n\t\t\t\t\ttemp = temp * 2;\n\t\t\t\telse\n\t\t\t\t\ttemp = temp * 2^double(lval-1);\n\t\t\t\tend\n\t\t\tend\n\t\t\tsp = sp + temp;\n\t\tend\n\tend\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/spinterp/private/spdimcc.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632936392131, "lm_q2_score": 0.8633916011860785, "lm_q1q2_score": 0.8006776789763557}} {"text": "function [DAD,DInv]=equilibrateSymMat(A)\n%EQUILIBRATESYMMAT Equilibrate a symmetric matrix maintaining symmetry.\n% This finds a matrix D such that D*A*D is such that the largest\n% magnitude element in each row and in each column is 1. It is\n% assumed that there is no all-zero row in A.\n%\n%INPUTS: A An nXn symmetric matrix having no all-zero row.\n%\n%OUTPUTS: DAD The equilibrated matrix. That is A pre and post multiplied by\n% the diagonal matrix D.\n% DInv The inverse of the diagonal matrix D. Invert the diagonal to\n% get D.\n%\n%This function implements the algorithm of Sectioj 5 of [1].\n%\n%EXAMPLE 1:\n%Here, we create a symmetric matrix and equilibrate it. The equilibration \n%makes the largest magnitude values in each row and column equal 1.\n%However, it also worsens the condition number, as we shall show:\n% V=vander([1;2;3;4]);\n% A=V+V';\n% DAD=equilibrateSymMat(A);\n% \n% %The original maximum absolute value elements in the columns and rows.\n% max(abs(A),[],1)\n% max(abs(A),[],2)\n% \n% %After equilibration, the maximum mangitude elements in the columns and\n% %rows are all 1.\n% max(abs(DAD),[],1)\n% max(abs(DAD),[],2)\n% \n% %One can see that the condition number increased.\n% cond(A,Inf)\n% cond(DAD,Inf)\n%\n%EXAMPLE 2:\n%This is the example given in Section 7 of [1]. AGian, we can see that the\n%matrix has been equilibrated, but the condition number got worse.\n% A=[1,2;\n% 2,1];\n% DAD=equilibrateSymMat(A);\n% \n% %The original maximum absolute value elements in the columns and rows.\n% max(abs(A),[],1)\n% max(abs(A),[],2)\n% \n% %After equilibration, the maximum mangitude elements in the columns and\n% %rows are all 1.\n% max(abs(DAD),[],1)\n% max(abs(DAD),[],2)\n% \n% %One can see that the condition number increased.\n% cond(A,Inf)%The inital condition number is 3.\n% cond(DAD,Inf)%The equilibrated condition number is 16/3.\n%\n%REFERENCES:\n%[1] J. R. Bunch, \"Equilibration of symmetric matrices in the max-norm,\"\n% Journal of the Association for Computing Machinery, vol. 18, no. 4,\n% pp. 566-572, Oct. 1971.\n%\n%September 2019 David F. Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nn=size(A,1);\n\nd=zeros(n,1);\nfor i=1:n\n d(i)=sqrt(abs(A(i,i)));\n for j=1:(i-1)\n t=abs(A(i,j));\n d(i)=max(t,d(i));\n end\n if(d(i)~=0)\n for j=1:i\n A(i,j)=A(i,j)/d(i);\n end\n \n for j=i:n\n A(j,i)=A(j,i)/d(i);\n end\n end\nend\n\nfor i=1:n\n if(d(i)==0)\n for j=(i+1):n\n t=abs(A(j,i));\n d(i)=max(t,d(i));\n end\n \n if(d(i)==0)\n error('The matrix has an all-zero row.')\n end\n for j=(i+1):n\n A(j,i)=A(j,i)/d(i);\n end\n end\nend\n\nL=tril(A);\nDAD=L+L'-diag(diag(L));\n\nDInv=diag(d);\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/equilibrateSymMat.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.8774767986961401, "lm_q1q2_score": 0.8006415652886216}} {"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% FUNCTION: computes the angular displacements of a damped pendulum under\n% gravity\n%\n% PURPOSE: to illustrate that changing the damping parameter, b,\n% significantly affects the resulting dynamics of the pendulum system\n%\n% Author: N.A. Battista\n% Date: 12/13/2019\n% Institution: The College of New Jersey\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nfunction damped_pendulum_diff_b()\n\n%\n% Physical Parameters\n%\nm = 100; % Mass of Pendulum bob\ng=9.80665; % Gravitational Acceleration;\nL=0.2; % Length of Pendulum\n \n% \n% Radii of Bobs (here - all the same)\n%\nrVec = 100*0.005*ones(1,6);\n\n%\n% Damping Parameter (here - each case is different)\n%\nbVec = 100*[0 0.1 0.2 0.4 1.0 2.0];\n\n% \n% Temporal Parameters\n%\nt=0; % initial time\ntFinal = 8; % final-time\ndt = 1e-3; % time-step\nct=1; % counter\ntVec(ct)=t; % time vector storage\n\n%\n% Moment of Inertia\n% \nIVec = m*(0.5*rVec.^2+L^2); \n\n% \n% Initial Angular Displacement\n%\nang = -(pi/2-pi/5)*ones(1,6);\nphi = zeros( size( ang ) );\n\n\n%\n% Perform the time-stepping, e.g., solve the ODEs\n%\nwhile t<=tFinal\n \n % increment the storage counter\n ct = ct+1;\n\n % increment time\n t = t+dt;\n \n % save current time\n tVec(ct) = t;\n \n % solve 1st order ODE for angular displacement\n ang(ct,:) = ang(ct-1,:) + dt * ( phi(ct-1,:) );\n \n % solve 1st order ODE for angular velocity\n phi(ct,:) = phi(ct-1,:) + dt * ( -m*g*L ./IVec .* sin( ang(ct-1,:) ) - bVec.*phi(ct-1,:)./IVec );\n \nend\n\n%\n% Defining Colors for Plotting Data\n%\ncolor2 = [0.635 0.078 0.184]; % dark red\ncolor5 = [0.9 0.525 0.098]; % orange\ncolor6 = [0.929 0.840 0.1250]; % dark yellow\ncolor7 = [0.7 0.7 0]; % 'ugly' green\ncolor13 = [0 0.5 0.5]; % green\n\n\n%\n% Note discrepancy is a bit off due to small angle approximation: \n% sin(theta) ~ theta gives below period of oscillation\n%\nT1 = 2*pi*sqrt( IVec(1) / (m*g*L) );\n%\n% Actually computed value of period is:\nT1 = 1.93;\n\n%\n% Make Figure of Angular Displacement vs. Non-dimensional Time (# of oscillations of 'r' case)\n%\nlw=6;\nfs=18;\nplot(tVec/T1,ang(:,1),'k-','LineWidth',lw); hold on;\nplot(tVec/T1,ang(:,2),'b-','LineWidth',lw,'Color',color2); hold on;\nplot(tVec/T1,ang(:,3),'g-','LineWidth',lw,'Color',color5); hold on;\nplot(tVec/T1,ang(:,4),'r-','LineWidth',lw,'Color',color6); hold on;\nplot(tVec/T1,ang(:,5),'c-','LineWidth',lw,'Color',color7); hold on;\nplot(tVec/T1,ang(:,6),'c-','LineWidth',lw,'Color',color13); hold on;\nxlabel('Non-Dimensional Time (# periods of r-case)');\nylabel('Angular Displacement (Radians)');\naxis([0 4.1 -1 1.5]);\nleg=legend('b=0','b=10','b=20','b=40','b=100','b=200','Orientation','horizontal');\nset(gca,'FontSize',fs);\nset(leg,'FontSize',fs);\nleg.NumColumns=3;\n\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/Examples_Education/Pendulum/ODEs/damped_pendulum_diff_b.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.8774767906859264, "lm_q1q2_score": 0.8006415454436597}} {"text": "function PA=partialMatrixInverse(A,n)\n%%PARTIALMATRIXINVERSE Given an mXm possibly singular matrix A of a rank\n% >=n, where the first n columns are independent, obtain a matrix that is\n% akin to the inverse related to the first n columns. A normal matrix\n% inverse is such that A*inv(A)=eye(m,m). Here, consider A=Q*R, where Q\n% is an orthogonal matrix and R is a lower-triangular matrix (not the\n% standard QR decomposition). The inverse relation is Q*R*inv(A)=eye(m,m)\n% or R*inv(A)=Q'*eye(m,m). This function solves for the nXn upper-left\n% submatrix of inv(A). This function is useful for taking a singular\n% Fisher informationmatrix, where the first n rows are observable, but\n% the rest are not, and obtaining a Cramer-Rao lower bound for the\n% observable components. Typically, this might be obtaining a CRLB on\n% position components before velocity is fully observable.\n% \n%INPUTS: A An mXm matrix.\n% n A number n<=m that is <= the rank of A.\n%\n%OUTPUTS: PA The partial inverse matrix as described above. \n%\n%This function solves the problem by calling linEqSolveFirstnRows with A\n%and vectors [1;0;0;0;...], [0;1;0;0;...], etc. The solution coincides with\n%a submatrix of the pseudoinverse.\n%\n%EXAMPLE:\n%This example of the CRLB of a position estimate of a target given a single\n%range, direction cosine and range-rate measurement is considered. We show\n%that when this function is used, the position accuracy implied by the CRLB\n%is not affected by the accuracy of the range rate component (which one\n%would assume). However, using the ad-hoc method of taking the inverse of a\n%subset of the Fisher information matrix, one gets a different (wrong)\n%answer the more accurate the range rate component is. That is due to not\n%properly accounting for matrix cross terms.\n% %Sensor location near Maui.\n% llhRxTx=[deg2rad([20.888645;-156.022474]);0];\n% %Convert to Cartesian.\n% xRxTx=zeros(6,1);\n% %Fill in the position. The reciever will be stationary (0 velocities).\n% %Take the first one to be the transmitter.\n% xRxTx(1:3,:)=ellips2Cart(llhRxTx);\n% \n% %Sensor orientation.\n% elAboveLevel=deg2rad(15);%The radar point slightly up.\n% %Rotation matrices of the radar.\n% MRxTx=findRFTransParam(llhRxTx(:,1),pi/2,elAboveLevel);%Facing East\n% \n% %Construct a target state vector. \n% llhTar=[deg2rad([21.14146;-155.058839]);13e3];\n% tarLocCart=ellips2Cart(llhTar);\n% tarHeading=deg2rad(-140);%Radians East of North.\n% angUpFromLevel=0;%Level flight.\n% tarSpeed=300;%m/s\n% vECEFTar=geogHeading2uVec(llhTar,tarHeading,angUpFromLevel)*tarSpeed;\n% xTar=[tarLocCart;vECEFTar];\n% \n% %Measuremnet and noise parameters of the radar.\n% useHalfRange=false;\n% sigmaR=10;%Range standard deviation.\n% sigmaU=0.01;\n% sigmaV=0.01;\n% sigmaRR=1;%Range rate standard deviation, meters/ second.\n% sigmaRRMassive=1e5;%Effectively uninformative standard deviation.\n% %Lower-triangular square root measurement covariance matrix (No cross\n% %terms).\n% SR=diag([sigmaR;sigmaU;sigmaV;sigmaRR]);\n% RInv=inv(SR*SR');\n% %The same thing but with the range rate standard deviation so massive it is\n% %essentially uninformative.\n% SRMassive=diag([sigmaR;sigmaU;sigmaV;sigmaRRMassive]);\n% RInvMassive=inv(SRMassive*SRMassive');\n% \n% %Gradients for the Fisher information matrices.\n% H=calcRuvRRJacob(xTar,useHalfRange,xRxTx(:,1),xRxTx(:,1),MRxTx(:,:,1));\n% FIM=observedFisherInfo([],RInv,[],H);\n% %The position RMSE from the CRLB found correctly using this function.\n% RMSE=sqrt(sum(diag(partialMatrixInverse(FIM,3))))\n% %An ad-hoc (wrong) approach that one might be tempted to take:\n% RMSEWrong=sqrt(sum(diag(inv(FIM(1:3,1:3)))))\n% %One can see that the position RMSE is higher when done the correct way.\n% %However, a single range rate on its own doesn't inform on the position\n% %accuracy. If we do the same thing cranking up the standard deviation of\n% %the range rate so it is uninformative, we get:\n% FIM=observedFisherInfo([],RInvMassive,[],H);\n% RMSEUninfRR=sqrt(sum(diag(partialMatrixInverse(FIM,3))))\n% RMSEUninfRRWrong=sqrt(sum(diag(inv(FIM(1:3,1:3)))))\n% %In other words, the correct solution doesn't change, but in this case the\n% %wrong solution has become correct, because the cross terms that messed it\n% %up are essentially gone. \n%\n%February 2022 David F.Crouse, Naval Research Laboratory, Washington D.C.\n%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.\n\nm=size(A,1);\nPA=zeros(n,n);\n\nif(n>m)\n error('n cannot be > the length of A.')\nend\n\ne=zeros(m,1);\nfor k=1:n\n e(k)=1;\n PA(:,k)=linEqSolveFirstnRows(A,e,n);\n e(k)=0;\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/Basic_Matrix_Operations/partialMatrixInverse.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873764, "lm_q2_score": 0.8705972768020108, "lm_q1q2_score": 0.8006382909442943}} {"text": "function [ axis, angle ] = rotation_mat2axis_3d ( a )\n\n%*****************************************************************************80\n%\n%% ROTATION_MAT2AXIS_3D converts a rotation from matrix to axis format in 3D.\n%\n% Discussion:\n%\n% The computation is based on the fact that a rotation matrix must\n% have an eigenvector corresponding to the eigenvalue of 1, hence:\n%\n% ( A - I ) * v = 0.\n%\n% The eigenvector V is the axis of rotation.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 26 February 2005\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Jack Kuipers,\n% Quaternions and Rotation Sequences,\n% Princeton, 1998.\n%\n% Parameters:\n%\n% Input, real A(3,3), the rotation matrix.\n%\n% Output, real AXIS(3), the axis vector which remains\n% unchanged by the rotation.\n%\n% Output, real ANGLE, the angular measurement of the\n% rotation about the axis, in radians.\n%\n dim_num = 3;\n%\n% Compute the normalized axis of rotation.\n%\n axis(1) = a(3,2) - a(2,3);\n axis(2) = a(1,3) - a(3,1);\n axis(3) = a(2,1) - a(1,2);\n\n axis_norm = sqrt ( sum ( axis(1:dim_num).^2 ) );\n\n if ( axis_norm == 0.0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'ROTATION_MAT2AXIS_3D - Fatal error!\\n' );\n fprintf ( 1, ' A is not a rotation matrix,\\n' );\n fprintf ( 1, ' or there are multiple axes of rotation.\\n' );\n error ( 'ROTATION_MAT2AXIS_3D - Fatal error!' );\n end\n\n axis(1:dim_num) = axis(1:dim_num) / axis_norm;\n%\n% Find the angle.\n%\n angle = r8_acos ( 0.5 * ( a(1,1) + a(2,2) + a(3,3) - 1.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/rotation_mat2axis_3d.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777928, "lm_q2_score": 0.8705972801594706, "lm_q1q2_score": 0.8006382863623576}} {"text": "% 梯形公式的加速--外推技巧\nclear; clc; \nf = @(x) sqrt(x.^3);\na = 0; \nb = 1;\ntol = 1e-7;\nmaxit = 100; % 最大迭代步数\n\nT(1,1) = (b-a)/2 * (f(a) + f(b)); \nfprintf(' T(1,1)=%.8f \\n',T(1,1));\nk = 1; err = 1.0;\nfor k = 1 : maxit\n h = (b-a)/(2^(k-1));\n T(k+1,1) = T(k,1)/2 + (h/2) * sum(f(a+0.5*h+[0:2^(k-1)-1]*h));\n fprintf(' T(%d,1)=%.8f ',k+1,T(k+1,1));\n for j = 1 : k\n T(k+1,j+1) = (4^j * T(k+1,j) - T(k,j) )/(4^j-1);\n fprintf(' T(%d,%d)=%.8f ',k+1,j+1,T(k+1,j+1));\n err = abs(T(k+1,j+1)-T(k+1,j));\n if (err 1\n t = circ_confmean(alpha,0.05,w,[],dim);\n ul = mu + t;\n ll = mu - t;\nend", "meta": {"author": "buzsakilab", "repo": "buzcode", "sha": "2d700a38b3c2a860ad1333be90f14d7a37a72815", "save_path": "github-repos/MATLAB/buzsakilab-buzcode", "path": "github-repos/MATLAB/buzsakilab-buzcode/buzcode-2d700a38b3c2a860ad1333be90f14d7a37a72815/externalPackages/CircularStats/circ_mean.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768635777511, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.8006315330788429}} {"text": "function result = p00_rat_transform ( problem, order )\n\n%*****************************************************************************80\n%\n%% P00_RAT_TRANSFORM applies a rational transform and Gauss-Legendre rule.\n%\n% Discussion:\n%\n% To approximate:\n%\n% Integral ( alpha <= x < Infinity ) f(x) dx\n%\n% Transform:\n%\n% u = 1 / ( 1 + x )\n% du = - dx / ( 1 + x )^2\n%\n% x = ( 1 - u ) / u\n% dx = - du / u^2\n%\n% x = alpha => u = 1 / ( 1 + alpha )\n% x = Infinity => u = 0\n%\n% Transformed integral:\n%\n% Integral ( 0 < u <= 1 / ( 1 + alpha ) ) f ( ( 1 - u ) / u ) du / u^2\n%\n% We apply a Gauss-Legendre rule here, but we could easily use any rule\n% that avoids evaluation at U = 0.\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 30 July 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Arthur Stroud, Don Secrest,\n% Gaussian Quadrature Formulas,\n% Prentice Hall, 1966,\n% LC: QA299.4G3S7.\n%\n% Parameters:\n%\n% Input, integer PROBLEM, the index of the problem.\n%\n% Input, integer ORDER, the order of the Gauss-Legendre rule\n% to apply.\n%\n% Output, real RESULT, the approximate integral.\n%\n alpha = p00_alpha ( problem );\n%\n% Get the abscissas and weights for Gauss-Legendre quadrature.\n%\n [ u, weight ] = legendre_compute ( order );\n%\n% Modify the weights from [-1,1] to [0,1/(1+alpha)].\n%\n weight(1:order) = weight(1:order) / 2.0 / ( 1.0 + alpha );\n%\n% Linear transform of abscissas from [-1,1] to [0,1/(1+alpha)].\n%\n u(1:order) = ( ( 1.0 + u(1:order) ) / ( 1.0 + alpha ) ...\n + ( 1.0 - u(1:order) ) * 0.0 ) ...\n / ( 2.0 );\n%\n% Define U_RAT = ( 1 - U ) / U.\n%\n u_rat(1:order) = ( 1.0 - u(1:order) ) ./ u(1:order);\n%\n% Evaluate F ( (1-U)/U ).\n%\n f_vec = p00_fun ( problem, order, u_rat );\n%\n% The integrand is F ( (1-U)/U ) / U^2\n%\n f_vec(1:order) = f_vec(1:order) ./ u(1:order).^2;\n%\n% Sum.\n%\n result = weight(1:order) * f_vec(1:order)';\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/laguerre_test_int/p00_rat_transform.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465188527685, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.8005173909719753}} {"text": "function [ an, bn ] = lcrg_anbn ( a, b, c, n )\n\n%*****************************************************************************80\n%\n%% LCRG_ANBN computes the \"N-th power\" of a linear congruential generator.\n%\n% Discussion:\n%\n% We are considering a linear congruential random number generator.\n% The LCRG takes as input an integer value called SEED, and returns\n% an updated value of SEED,\n%\n% SEED(out) = ( a * SEED(in) + b ) mod c.\n%\n% and an associated pseudorandom real value\n%\n% U = SEED(out) / c.\n%\n% In most cases, a user is content to call the LCRG repeatedly, with\n% the updating of SEED being taken care of automatically.\n%\n% The purpose of this routine is to determine the values of AN and BN\n% that describe the LCRG that is equivalent to N applications of the\n% original LCRG.\n%\n% One use for such a facility would be to do random number computations\n% in parallel. If each of N processors is to compute many random values,\n% you can guarantee that they work with distinct random values\n% by starting with a single value of SEED, using the original LCRG to generate\n% the first N-1 \"iterates\" of SEED, so that you now have N \"seed\" values,\n% and from now on, applying the N-th power of the LCRG to the seeds.\n%\n% If the K-th processor starts from the K-th seed, it will essentially\n% be computing every N-th entry of the original random number sequence,\n% offset by K. Thus the individual processors will be using a random\n% number stream as good as the original one, and without repeating, and\n% without having to communicate.\n%\n% To evaluate the N-th value of SEED directly, we start by ignoring\n% the modular arithmetic, and working out the sequence of calculations\n% as follows:\n%\n% SEED(0) = SEED.\n% SEED(1) = a * SEED + b\n% SEED(2) = a * SEED(1) + b = a^2 * SEED + a * b + b\n% SEED(3) = a * SEED(2) + b = a^3 * SEED + a^2 * b + a * b + b\n% ...\n% SEED(N-1) = a * SEED(N-2) + b\n%\n% SEED(N) = a * SEED(N-1) + b = a^N * SEED\n% + ( a^(n-1) + a^(n-2) + ... + a + 1 ) * b\n%\n% or, using the geometric series,\n%\n% SEED(N) = a^N * SEED + ( a^N - 1) / ( a - 1 ) * b\n% = AN * SEED + BN\n%\n% Thus, from any SEED, we can determine the result of N applications of the\n% original LCRG directly if we can solve\n%\n% ( a - 1 ) * BN = ( a^N - 1 ) * b in modular arithmetic,\n%\n% and evaluate:\n%\n% AN = a^N\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 21 May 2008\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Barry Wilkinson, Michael Allen,\n% Parallel Programming:\n% Techniques and Applications Using Networked Workstations and Parallel Computers,\n% Prentice Hall,\n% ISBN: 0-13-140563-2,\n% LC: QA76.642.W54.\n%\n% Parameters:\n%\n% Input, integer A, the multiplier for the LCRG.\n%\n% Input, integer B, the added value for the LCRG.\n%\n% Input, integer C, the base for the modular arithmetic.\n% For 32 bit arithmetic, this is often 2^31 - 1, or 2147483647. It is\n% required that 0 < C.\n%\n% Input, integer N, the \"index\", or number of times that the\n% LCRG is to be applied. It is required that 0 <= N.\n%\n% Output, integer AN, BN, the multiplier and added value for\n% the LCRG that represent N applications of the original LCRG.\n%\n if ( n < 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LCRG_ANBN - Fatal error!\\n' );\n fprintf ( 1, ' Illegal input value of N = %d\\n', n );\n error ( 'LCRG_ANBN - Fatal error!' );\n end\n\n if ( c <= 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LCRG_ANBN - Fatal error!\\n' );\n fprintf ( 1, ' Illegal input value of C = %d\\n', c );\n error ( 'LCRG_ANBN - Fatal error!' );\n end\n\n if ( n == 0 )\n an = 1;\n bn = 0;\n elseif ( n == 1 )\n an = a;\n bn = b;\n else\n%\n% Compute A^N.\n%\n an = power_mod ( a, n, c );\n%\n% Solve\n% ( a - 1 ) * BN = ( a^N - 1 ) mod B\n% for BN.\n%\n am1 = a - 1;\n anm1tb = ( an - 1 ) * b;\n\n [ bn, ierror ] = congruence ( am1, c, anm1tb );\n\n if ( ierror ~= 0 )\n fprintf ( 1, '\\n' );\n fprintf ( 1, 'LCRG_ANBN - Fatal error!\\n' );\n fprintf ( 1, ' An error occurred in the CONGRUENCE routine.\\n' );\n fprintf ( 1, ' The error code was IERROR = %d\\n', ierror );\n error ( 'LCRG_ANGN - Fatal error!' );\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/uniform/lcrg_anbn.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762114, "lm_q2_score": 0.8902942217558213, "lm_q1q2_score": 0.8004825716537356}} {"text": "function a = identity ( m, n )\n\n%*****************************************************************************80\n%\n%% IDENTITY returns the IDENTITY matrix.\n%\n% Formula:\n%\n% if ( I = J )\n% A(I,J) = 1\n% else\n% A(I,J) = 0\n%\n% Example:\n%\n% M = 4, N = 5\n%\n% 1 0 0 0 0\n% 0 1 0 0 0\n% 0 0 1 0 0\n% 0 0 0 1 0\n%\n% Rectangular properties:\n%\n% A is integral: int ( A ) = A.\n%\n% A is a zero/one matrix.\n%\n% Square Properties:\n%\n% A is nonsingular.\n%\n% A is involutional: A * A = I.\n%\n% A is diagonal.\n%\n% Because A is diagonal, it has property A.\n%\n% A is symmetric: A' = A.\n%\n% A is a circulant matrix: each row is shifted once to get the next row.\n%\n% Because A is symmetric, it is normal.\n%\n% Because A is normal, it is diagonalizable.\n%\n% LAMBDA(1:N) = 1\n%\n% The matrix of eigenvectors of A is A.\n%\n% det ( A ) = 1.\n%\n% A is unimodular.\n%\n% For any vector v, A*v = v.\n%\n% For any matrix B, A*B = B*A=B.\n%\n% A is persymmetric: A(I,J) = A(N+1-J,N+1-I).\n%\n% A is centrosymmetric: A(I,J) = A(N+1-I,N+1-J).\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% 12 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 \n% 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 if ( i == j )\n a(i,j) = 1.0;\n else\n a(i,j) = 0.0;\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/test_mat/identity.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.9005297847831082, "lm_q1q2_score": 0.8003537544143773}} {"text": "function value = p08_f ( dim_num, point_num, x )\n\n%*****************************************************************************80\n%\n%% P08_F evaluates the integrand for problem 08.\n%\n% Dimension:\n%\n% DIM_NUM arbitrary.\n%\n% Region:\n%\n% 0 <= X(1:DIM_NUM) <= 1\n%\n% Integrand:\n%\n% ( sin ( (pi/4) * sum ( x(1:dim_num) ) ) )**2\n%\n% Exact Integral:\n%\n% 1/2 - sqrt ( 2**(3*DIM_NUM) ) * cos ( DIM_NUM * pi / 4 ) ) / ( 2 * pi**DIM_NUM )\n%\n% Licensing:\n%\n% This code is distributed under the GNU LGPL license.\n%\n% Modified:\n%\n% 02 June 2007\n%\n% Author:\n%\n% John Burkardt\n%\n% Reference:\n%\n% Richard Crandall,\n% Projects in Scientific Computing,\n% Springer, 2000,\n% ISBN: 0387950095,\n% LC: Q183.9.C733.\n%\n% Parameters:\n%\n% Input, integer DIM_NUM, the dimension of the argument.\n%\n% Input, integer POINT_NUM, the number of points.\n%\n% Input, real X(DIM_NUM,POINT_NUM), the evaluation points.\n%\n% Output, real VALUE(POINT_NUM), the integrand values.\n%\n value(1:point_num) = 0.0;\n\n for point = 1 : point_num\n value(point) = ( sin ( pi * sum ( x(1:dim_num,point) ) / 4.0 ) )^2;\n end\n\n p08_i4 ( 'I', '#', point_num );\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/quadrature_test/p08_f.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.8670357683915538, "lm_q1q2_score": 0.8003079637354106}} {"text": "function [ out ] = proj_Euclidean_ball( x,c,r )\n%PROJ_EUCLIDEAN_BALL computes the orthogonal projection onto the Euclidean ball {x:||x-c||<=r}\n%\n% Usage: \n% out = PROJ_EUCLIDEAN_BALL(x,[c],[r])\n% ===========================================\n% Input:\n% x - point to be projected (vector/matrix)\n% c - center of the ball (vector/matrix) [default: c=0]\n% r - positive radius (a positive scalar) [default: r=1]\n% ===========================================\n% Assumptions:\n% l2 or Frobenius norm\n% ===========================================\n% Output:\n% out - projection vector\n\n% This file is part of the FOM package - a collection of first order methods for solving convex optimization problems\n% Copyright (C) 2017 Amir and Nili Beck\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%reading the user x and setting defalut values when required.\nif (nargin < 1)\n error ('usage: proj_Euclidean_ball(input,[c],[r])') ;\nend\n\nif (nargin < 3)\n %setting default value of r to 1\n r = 1;\nend\n\nif ((nargin < 2) || (isempty (c)))\n %setting default value of c to zeros\n c = zeros(size(x)) ;\nend\n\nout= c+r *(x-c) / max(norm(x-c,'fro'),r) ; \nend\n\n", "meta": {"author": "hiroyuki-kasai", "repo": "SGDLibrary", "sha": "d19a12559c79c3726683243885b15f982f4bec3d", "save_path": "github-repos/MATLAB/hiroyuki-kasai-SGDLibrary", "path": "github-repos/MATLAB/hiroyuki-kasai-SGDLibrary/SGDLibrary-d19a12559c79c3726683243885b15f982f4bec3d/tool/FOM_prox functions/proj_Euclidean_ball.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.8723473663814338, "lm_q1q2_score": 0.8002065612364553}} {"text": "% Simple algorithm to calculate the deflection, bending moment, shear force in a\n% cantilever beam.\n% load = loading distribution\n\n% Example,\n% 1.Uniform loading of 10 N/m: load=repmat(10,1,1001), l=20, dl=0.02\n% 2.Point loading with P=400 N, load=[repmat(0,1,999) 10000 10000], l=20, dl=0.02\n\n% length(load)=(l/dl)\n\nfunction deflection=beam_deflection(load,ei,l,dl)\nif length(load)~=(l/dl+1)\n error('Check inputs')\nend\ny=0:dl:l;\nm=sum((y.*load))*dl;\nv=sum(load)*dl;\nu_4=load/ei;\nu_3=v/ei;\nfor i=2:length(load)\n u_3(i)=u_3(i-1)-u_4(i-1)*dl;\nend\nu_2=m/ei;\nfor i=2:length(load)\n u_2(i)=u_2(i-1)-u_3(i-1)*dl;\nend\nu_1=0;\nfor i=2:length(load)\n u_1(i)=u_1(i-1)+u_2(i-1)*dl;\nend\nu=0;\nfor i=2:length(load)\n u(i)=u(i-1)+u_1(i-1)*dl;\nend\ndeflection=u;\nplot(y,u_2*ei)\nhold on\nplot(y,u_3*ei,'r')\nlegend('bending moment','shear force')\nxlabel('length along the beam')\nylabel(' bending moment and shear force (SI units)')\ngrid\nhold off\nfigure,plot(y,u,'r')\nxlabel('length along the beam')\nylabel('deflection')\ngrid\ntitle('Deflection')\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/31112-deflection-of-a-cantilever-beam/beam deflection/beam_deflection.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9678992914310605, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.8001737555662953}} {"text": "function [II,DA] = inv_3x3(AA)\n%INV_3X3 calc. the inverses for a block of 3-by-3 matrices.\n% [IA,DA] = INV_3X3(AA) returns a set of 'inverses' IA and\n% an array of determinants DA for the set of 3-by-3 linear\n% systems in AA. SIZE(AA), SIZE(IA) = [3,3,N], where N is\n% the number of linear systems. DA is an N-by-1 array of\n% determinant values. Note that each IA(:,:,K) is an 'inc-\n% omplete inverse DET(A(:,:,K)) * A(:,:,K)^(-1) to improve\n% numerical robustness. To solve a linear system, A*X = B,\n% compute (I*B)./D, given D is non-zero.\n%\n% See also INV_2X2\n\n% Darren Engwirda : 2018 --\n% Email : de2363@columbia.edu\n% Last updated : 13/02/2020\n\n%---------------------------------------------- basic checks\n if ( ~isnumeric(AA))\n error('inv_3x3:incorrectInputClass' , ...\n 'Incorrect input class.') ;\n end\n\n%---------------------------------------------- basic checks\n if (ndims(AA) > +3 )\n error('inv_3x3:incorrectDimensions' , ...\n 'Incorrect input dimensions.');\n end\n if (size(AA,1)~= +3 || ...\n size(AA,2)~= +3 )\n error('inv_3x3:incorrectDimensions' , ...\n 'Incorrect input dimensions.');\n end\n\n%---------------------------------------------- build inv(A)\n II = zeros(size (AA)) ;\n\n DA = det_3x3(AA) ;\n\n II(1,1,:) = ...\n AA(3,3,:) .* AA(2,2,:) ...\n - AA(3,2,:) .* AA(2,3,:) ;\n\n II(1,2,:) = ...\n AA(3,2,:) .* AA(1,3,:) ...\n - AA(3,3,:) .* AA(1,2,:) ;\n\n II(1,3,:) = ...\n AA(2,3,:) .* AA(1,2,:) ...\n - AA(2,2,:) .* AA(1,3,:) ;\n\n II(2,1,:) = ...\n AA(3,1,:) .* AA(2,3,:) ...\n - AA(3,3,:) .* AA(2,1,:) ;\n\n II(2,2,:) = ...\n AA(3,3,:) .* AA(1,1,:) ...\n - AA(3,1,:) .* AA(1,3,:) ;\n\n II(2,3,:) = ...\n AA(2,1,:) .* AA(1,3,:) ...\n - AA(2,3,:) .* AA(1,1,:) ;\n\n II(3,1,:) = ...\n AA(3,2,:) .* AA(2,1,:) ...\n - AA(3,1,:) .* AA(2,2,:) ;\n\n II(3,2,:) = ...\n AA(3,1,:) .* AA(1,2,:) ...\n - AA(3,2,:) .* AA(1,1,:) ;\n\n II(3,3,:) = ...\n AA(2,2,:) .* AA(1,1,:) ...\n - AA(2,1,:) .* AA(1,2,:) ;\n\nend\n\nfunction [DA] = det_3x3(AA)\n\n DA = ...\n AA(1,1,:) .* ( ...\n\tAA(2,2,:) .* AA(3,3,:) ...\n - AA(2,3,:) .* AA(3,2,:) ...\n\t ) - ...\n AA(1,2,:) .* ( ...\n\tAA(2,1,:) .* AA(3,3,:) ...\n - AA(2,3,:) .* AA(3,1,:) ...\n\t ) + ...\n\tAA(1,3,:) .* ( ...\n\tAA(2,1,:) .* AA(3,2,:) ...\n - AA(2,2,:) .* AA(3,1,:) ...\n\t ) ;\n\nend\n\n\n\n", "meta": {"author": "dengwirda", "repo": "mesh2d", "sha": "749a81073facc8b5db02e4f7bb0b10c9783cebd3", "save_path": "github-repos/MATLAB/dengwirda-mesh2d", "path": "github-repos/MATLAB/dengwirda-mesh2d/mesh2d-749a81073facc8b5db02e4f7bb0b10c9783cebd3/mesh-ball/inv_3x3.m", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731158685838, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.80011907164074}}