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 8931229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:04:17+00:00 2026-06-15T09:04:17+00:00

I want to do a multi-branch fit with gnuplot. I defined two functions z1(x)

  • 0

I want to do a multi-branch fit with gnuplot. I defined two functions z1(x) and z2(x) and I want that z1(x) is fitted with all data up to line 49 and starting from line 50 it should fit to z2(x). This is what I do in the fitting part:

z(x,y) = (y < 50) ? z1(x) : z2(x)

fit z(x,y) 'data.txt' using  1:-1:2  via a, b

But gnuplot completly ignores the z2(x) part. I can even comment out the defintion of z2(x), it gives not even an error nor a warning. It never reaches the case where y >= 50, but the data.txt file has 100 lines.

Also, if I plot z1(x) and z2(x) afterwards, they are just constant zero (z1 = z2 = 0), but the fit parameters a and b are roughly (not fully, because 2nd branch is ignored) in the right order.

Am I doing something wrong here? Is there a good example somehwere (the official gnuplot fit demo didn’t help)?

  • 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-15T09:04:18+00:00Added an answer on June 15, 2026 at 9:04 am

    Provided that your line number in the ‘data.txt’ file is the x variable for your function z(x), you can make it simpler (this is necessary for this to work, actually!!!). Your function z(x,y) is in reality just single variable function z(x) defined separately on two intervals. I re-created your problem with a sample data file, where the ranges for z1(x) and z2(x) break at the 10th point of my data file (you want 49 or 50 there).

    The following code does what you want; defines the function z(x) differently for the first 10 data points and the rest (this is where the x HAS to be equal to line number),

    z1(x) = a*x + b
    a = 1.2
    b = 1.2
    z2(x) = a + b
    z(x) = x < 10 ? z1(x) : z2(x)
    

    then fit the data file using the data point line number (column(0)) as x and the value on the respective line (1) as y, varying parameters a and b

     fit z(x) 'data.txt' using (column(0)):1 via a,b
    

    and plot to see how we do

     plot 'data.txt' using (column(0)):1, z(x)
    

    If this doesn’t work, you may look into the index option for plotting data files. This would require separating the data ranges (first 50 points) in your data file by one blank line (or two, can’t remember) and modify the script accordingly.

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

Sidebar

Related Questions

I want to indent multi-line in 'vim/gvim', is there any shortcut in the vim/gvim?
I have this application that I want to support multi languages. I thought the
I want to develop a multi-server clustered framework that will work similarly to the
I want to create a multi-tenant application that uses the hostname to determine the
I want to use a variable-sized multi-dimensional array in my app to save data.
i want to write a function that prints multi-dimensional objects which are text (or
I want to search multi vars that could be true in WHERE condition or
guys I want to input multi-line text into a DataGridTextColumn, I can use enter
I have an empty data base. I want to add multi records into data
I want multi-line strings in java, so I seek a simple preprocessor to convert

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.