Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8852525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:25:27+00:00 2026-06-14T13:25:27+00:00

My main script contains following code: %# Grid and model parameters nModel=50; nModel_want=1; nI_grid1=5;

  • 0

My main script contains following code:

%# Grid and model parameters
nModel=50;
nModel_want=1;
nI_grid1=5;
Nth=1;
nRow.Scale1=5;
nCol.Scale1=5;
nRow.Scale2=5^2;
nCol.Scale2=5^2;

theta = 90; % degrees
a_minor = 2; % range along minor direction
a_major = 5; % range along major direction
sill = var(reshape(Deff_matrix_NthModel,nCell.Scale1,1)); % variance of the coarse data matrix of size nRow.Scale1 X nCol.Scale1

%#  Covariance computation

% Scale 1
for ihRow = 1:nRow.Scale1
    for ihCol = 1:nCol.Scale1
        [cov.Scale1(ihRow,ihCol),heff.Scale1(ihRow,ihCol)] = general_CovModel(theta, ihCol, ihRow, a_minor, a_major, sill, 'Exp');
    end
end

% Scale 2
for ihRow = 1:nRow.Scale2
    for ihCol = 1:nCol.Scale2
        [cov.Scale2(ihRow,ihCol),heff.Scale2(ihRow,ihCol)] = general_CovModel(theta, ihCol/(nCol.Scale2/nCol.Scale1), ihRow/(nRow.Scale2/nRow.Scale1), a_minor, a_major, sill/(nRow.Scale2*nCol.Scale2), 'Exp');
    end
end


%# Scale-up of fine scale values by averaging
[covAvg.Scale2,var_covAvg.Scale2,varNorm_covAvg.Scale2] = general_AverageProperty(nRow.Scale2/nRow.Scale1,nCol.Scale2/nCol.Scale1,1,nRow.Scale1,nCol.Scale1,1,cov.Scale2,1);

I am using two functions, general_CovModel() and general_AverageProperty(), in my main script which are given as following:

function [cov,h_eff] = general_CovModel(theta, hx, hy, a_minor, a_major, sill, mod_type)
% mod_type should be in strings

angle_rad = theta*(pi/180); % theta in degrees, angle_rad in radians
R_theta = [sin(angle_rad) cos(angle_rad); -cos(angle_rad) sin(angle_rad)];
h = [hx; hy];
lambda = a_minor/a_major;
D_lambda = [lambda 0; 0 1];
h_2prime = D_lambda*R_theta*h;
h_eff = sqrt((h_2prime(1)^2)+(h_2prime(2)^2));

if strcmp(mod_type,'Sph')==1 || strcmp(mod_type,'sph') ==1
    if h_eff<=a
        cov = sill - sill.*(1.5*(h_eff/a_minor)-0.5*((h_eff/a_minor)^3));
    else
        cov = sill;
    end
elseif strcmp(mod_type,'Exp')==1 || strcmp(mod_type,'exp') ==1
    cov = sill-(sill.*(1-exp(-(3*h_eff)/a_minor)));
elseif strcmp(mod_type,'Gauss')==1 || strcmp(mod_type,'gauss') ==1
    cov = sill-(sill.*(1-exp(-((3*h_eff)^2/(a_minor^2)))));
end

and

function [PropertyAvg,variance_PropertyAvg,NormVariance_PropertyAvg]=...
    general_AverageProperty(blocksize_row,blocksize_col,blocksize_t,...
    nUpscaledRow,nUpscaledCol,nUpscaledT,PropertyArray,omega)
% This function computes average of a property and variance of that averaged
% property using power averaging

PropertyAvg=zeros(nUpscaledRow,nUpscaledCol,nUpscaledT);

%# Average of property
for k=1:nUpscaledT,
    for j=1:nUpscaledCol,
        for i=1:nUpscaledRow,
            sum=0;
            for a=1:blocksize_row,
                for b=1:blocksize_col,
                    for c=1:blocksize_t,
                        sum=sum+(PropertyArray((i-1)*blocksize_row+a,(j-1)*blocksize_col+b,(k-1)*blocksize_t+c).^omega); % add all the property values in 'blocksize_x','blocksize_y','blocksize_t' to one variable
                    end
                end
            end
            PropertyAvg(i,j,k)=(sum/(blocksize_row*blocksize_col*blocksize_t)).^(1/omega); % take average of the summed property
        end
    end
end

%# Variance of averageed property
variance_PropertyAvg=var(reshape(PropertyAvg,...
    nUpscaledRow*nUpscaledCol*nUpscaledT,1),1,1); 

%# Normalized variance of averageed property
NormVariance_PropertyAvg=variance_PropertyAvg./(var(reshape(...
    PropertyArray,numel(PropertyArray),1),1,1)); 

Question: Using Matlab, I would like to optimize covAvg.Scale2 such that it matches closely with cov.Scale1 by perturbing/varying any (or all) of the following variables

1) a_minor

2) a_major

3) theta

I am aware I can use fminsearch, however, how I am not able to perturb the variables I want to while using this fminsearch.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:25:29+00:00Added an answer on June 14, 2026 at 1:25 pm

    I won’t pretend to understand everything that you are doing. But it sounds like a typical minimization problem. What you want to do is to come up with a single function that takes a_minor, a_major and theta as arguments, and returns the square of the difference between covAvg.Scale2 and cov.Scale1. Something like this:

    function diff = minimize_me(a_minor, a_major, theta)
        ... your script goes here
        diff = (covAvg.Scale2 - cov.Scale1)^2;
    end
    

    Then you need matlab to minimize this function. There’s more than one option here. Since you only have three variables to minimize over, fminsearch is a good place to start. You would call it something like this:

    opts = optimset('display', 'iter');
    x = fminsearch( @(x) minimize_me(x(1), x(2), x(3)), [a_minor_start a_major_start theta_start], opts)
    

    The first argument to fminsearch is the function you want to optimize. It must take a single argument: a vector of the variables that will be perturbed in order to find the minimum value. Here I use an anonymous function to extract the values from this vector and pass them into minimize_me. The second argument to fminsearch is a vector containing the values to start searching at. The third argument are options that affect the search; it’s a good idea to set display to iter when you first start optimizing, so that you can get an idea of well the optimizer is converging.

    If your parameters have restricted domains (e.g. they must all be positive) take a look at fminsearchbnd on the file exchange.

    If I have misunderstood your problem, and this doesn’t help at all, try posting code that we can run to reproduce the problem ourselves.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My main HTML file dynamically loads in content with; <html> <head> <script src=http://code.jquery.com/jquery-1.7.1.min.js></script> </head>
say an HTML page (Page.htm) contains the following... <script type=text/javascript> var vara = 'varA';
The following code does not have any errors when run script.py -f filename but
In my main script, I am doing some archive manipulation. Once I have completed
Let's assume I have a main script, main.py, that imports another python file with
I have a vm.py in the same directory as the main() script ( getdata.py
Problem: $ clang++ -L../lib/osx/ -I../include/ -o test Script.cpp Main.cpp Verbose.cpp -llua -lUnitTest++ Undefined symbols
This script saves the files as /home/name/main/all my files and stuff . I want
The main problem is square-space builds their forms with java-script (YUI). They have are
Say I have a PHP script, //main.php -> PID = 1002 <?php exec('ProcessOne'); exec('ProcessTwo');

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.