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

  • SEARCH
  • Home
  • 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 8430581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:37:45+00:00 2026-06-10T05:37:45+00:00

I’ve written some code to implement an algorithm that takes as input a vector

  • 0

I’ve written some code to implement an algorithm that takes as input a vector q of real numbers, and returns as an output a complex matrix R. The Matlab code below produces a plot showing the input vector q and the output matrix R.

Given only the complex matrix output R, I would like to obtain the input vector q. Can I do this using least-squares optimization? Since there is a recursive running sum in the code (rs_r and rs_i), the calculation for a column of the output matrix is dependent on the calculation of the previous column.

Perhaps a non-linear optimization can be set up to recompose the input vector q from the output matrix R?

Looking at this in another way, I’ve used an algorithm to compute a matrix R. I want to run the algorithm “in reverse,” to get the input vector q from the output matrix R.

If there is no way to recompose the starting values from the output, thereby treating the problem as a “black box,” then perhaps the mathematics of the model itself can be used in the optimization? The program evaluates the following equation:

Equations

The Utilde(tau, omega) is the output matrix R. The tau (time) variable comprises the columns of the response matrix R, whereas the omega (frequency) variable comprises the rows of the response matrix R. The integration is performed as a recursive running sum from tau = 0 up to the current tau timestep.

Here are the plots created by the program posted below:

q value input
matrix output

Here is the full program code:

N = 1001;
q = zeros(N, 1); % here is the input
q(1:200) = 55;
q(201:300) = 120;
q(301:400) = 70;
q(401:600) = 40;
q(601:800) = 100;
q(801:1001) = 70;
dt = 0.0042;
fs = 1 / dt;
wSize = 101;
Glim = 20;
ginv = 0;
R = get_response(N, q, dt, wSize, Glim, ginv); % R is output matrix
rows = wSize; 
cols = N;

figure; plot(q); title('q value input as vector'); 
ylim([0 200]); xlim([0 1001])

figure; imagesc(abs(R)); title('Matrix output of algorithm')
colorbar

Here is the function that performs the calculation:

function response = get_response(N, Q, dt, wSize, Glim, ginv)

fs = 1 / dt; 
Npad = wSize - 1; 
N1 = wSize + Npad;
N2 = floor(N1 / 2 + 1);
f = (fs/2)*linspace(0,1,N2);
omega = 2 * pi .* f';
omegah = 2 * pi * f(end);
sigma2 = exp(-(0.23*Glim + 1.63));

sign = 1;
if(ginv == 1)
    sign = -1;
end

ratio = omega ./ omegah;
rs_r = zeros(N2, 1);  
rs_i = zeros(N2, 1);   
termr = zeros(N2, 1);
termi = zeros(N2, 1);
termr_sub1 = zeros(N2, 1);
termi_sub1 = zeros(N2, 1);
response = zeros(N2, N);

 % cycle over cols of matrix
for ti = 1:N               

    term0 = omega ./ (2 .* Q(ti));
    gamma = 1 / (pi * Q(ti));

    % calculate for the real part
    if(ti == 1)
        Lambda = ones(N2, 1);
        termr_sub1(1) = 0;  
        termr_sub1(2:end) = term0(2:end) .* (ratio(2:end).^-gamma);  
    else
        termr(1) = 0; 
        termr(2:end) = term0(2:end) .* (ratio(2:end).^-gamma); 
        rs_r = rs_r - dt.*(termr + termr_sub1);
        termr_sub1 = termr;
        Beta = exp( -1 .* -0.5 .* rs_r );

        Lambda = (Beta + sigma2) ./ (Beta.^2 + sigma2);  % vector
    end 

    % calculate for the complex part  
    if(ginv == 1)  
        termi(1) = 0;
        termi(2:end) = (ratio(2:end).^(sign .* gamma) - 1) .* omega(2:end);
    else
        termi = (ratio.^(sign .* gamma) - 1) .* omega;
    end
    rs_i = rs_i - dt.*(termi + termi_sub1);
    termi_sub1 = termi;
    integrand = exp( 1i .* -0.5 .* rs_i );

    if(ginv == 1) 
        response(:,ti) = Lambda .* integrand;
    else        
        response(:,ti) = (1 ./ Lambda) .* integrand;
    end  
end % ti loop
  • 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-10T05:37:46+00:00Added an answer on June 10, 2026 at 5:37 am

    It turns out that by using the mathematics of the model, the input can be estimated. This is not true in general, but for my problem it seems to work. The cumulative integral is eliminated by a partial derivative.

    N = 1001;
    q = zeros(N, 1);
    q(1:200) = 55;
    q(201:300) = 120;
    q(301:400) = 70;
    q(401:600) = 40;
    q(601:800) = 100;
    q(801:1001) = 70;
    dt = 0.0042;
    fs = 1 / dt;
    wSize = 101;
    Glim = 20;
    ginv = 0;
    R = get_response(N, q, dt, wSize, Glim, ginv);
    rows = wSize; 
    cols = N;
    cut_val = 200;
    
    imagLogR = imag(log(R));
    
    Mderiv = zeros(rows, cols-2);
    for k = 1:rows
       val = deriv_3pt(imagLogR(k,:), dt);
       val(val > cut_val) = 0;
       Mderiv(k,:) = val(1:end-1);
    end
    
    disp('Running iteration');
    q0 = 10;
    q1 = 500;
    NN = cols - 2;
    qout = zeros(NN, 1);
    for k = 1:NN
        data = Mderiv(:,k); 
        qout(k) = fminbnd(@(q) curve_fit_to_get_q(q, dt, rows, data),q0,q1);
    end
    
    figure; plot(q); title('q value input as vector'); 
    ylim([0 200]); xlim([0 1001])
    
    figure;
    plot(qout); title('Reconstructed q')
    ylim([0 200]); xlim([0 1001])
    

    Here are the supporting functions:

    function output = deriv_3pt(x, dt)
    
    % Function to compute dx/dt using the 3pt symmetrical rule
    % dt is the timestep
    
    N = length(x);
    N0 = N - 1;
    output = zeros(N0, 1);
    denom = 2 * dt;
    
    for k = 2:N0 
       output(k - 1) = (x(k+1) - x(k-1)) / denom;  
    end
    
    
    function sse = curve_fit_to_get_q(q, dt, rows, data)
    
    fs = 1 / dt;
    N2 = rows;
    f = (fs/2)*linspace(0,1,N2);  % vector for frequency along cols
    omega = 2 * pi .* f';
    omegah = 2 * pi * f(end);
    ratio = omega ./ omegah;
    
    gamma = 1 / (pi * q);
    
    termi = ((ratio.^(gamma)) - 1) .* omega;
    
    Error_Vector =  termi - data;
    sse = sum(Error_Vector.^2);
    

    Original
    Estimated

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.