I Need Help Obtaining The Values C1,c2.c3 From A Least Squares Fit Of ...

Skip to content
  • MATLAB Answers
  • File Exchange
  • Cody
  • AI Chat Playground
  • Discussions
  • Contests
  • Blogs
  • More
    • Communities
    • Treasure Hunt
    • Community Advisors
    • Virtual Badges
    • About
  • More

You are now following this question

  • You will see updates in your followed content feed.
  • You may receive emails, depending on your communication preferences.
I need help obtaining the values c1,c2.c3 from a least squares fit of the data. Follow 7 views (last 30 days) Show older comments Lovie Reid Lovie Reid on 29 Jul 2020
  • Vote0
  • Link

    https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data

    Cancel Copy to Clipboard
  • Vote0
  • Link

    https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data

    Cancel Copy to Clipboard
Edited: James Tursa on 30 Jul 2020 I need help obtaining the values c1,c2.c3 from a least squares fit of the data.
2 Comments Show NoneHide None
James Tursa James Tursa on 29 Jul 2020

https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data#comment_954493

Cancel Copy to Clipboard
  • Link

    https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data#comment_954493

    Cancel Copy to Clipboard
What have you done so far? What specific problems are you having with your code? Lovie Reid Lovie Reid on 29 Jul 2020

https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data#comment_954592

Cancel Copy to Clipboard
  • Link

    https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data#comment_954592

    Cancel Copy to Clipboard
Ive plug inK = [76.5 80.4 83.3 85.7 88.1 90.2 92.0 93.6 95.1 96.5 98.9];MPa = [0.08 0.12 0.16 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.60];y=log(MPa/3.77);beyond this im confused as how to properly write out z

Sign in to comment.

Sign in to answer this question.

Answers (1)

James Tursa James Tursa on 29 Jul 2020
  • Vote0
  • Link

    https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data#answer_472693

    Cancel Copy to Clipboard
  • Vote0
  • Link

    https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data#answer_472693

    Cancel Copy to Clipboard
Edited: James Tursa on 29 Jul 2020 Open in MATLAB Online It appears to me that your equation is linear in c1, c2, c3. Just make a matrix equation out of this and then apply your least squares technique to the matrix. That is, you know everything in that equation except the c1, c2, c3. So just calculate all the values for each set of data and that will give you a matrix equation of the form:b = A*cwhere each elemet of b is calculated from your data (the ln(Psat/Pc) values) each row of A is calculated from your data corresponding to the element of b (the x, x^2, ln(Tsat/Tc) values) c is simply the unknown column vector [c1;c2;c3]Then use your least squares technique to solve for c.
4 Comments Show 2 older commentsHide 2 older comments
Lovie Reid Lovie Reid on 29 Jul 2020

https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data#comment_954622

Cancel Copy to Clipboard
  • Link

    https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data#comment_954622

    Cancel Copy to Clipboard
okay so far I've plugged in K = [76.5 80.4 83.3 85.7 88.1 90.2 92.0 93.6 95.1 96.5 98.9 101 103 106.3 109.2 111.8 114.2 116.4 118.4 122.9 127.0];MPa = [0.08 0.12 0.16 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.60 0.70 0.80 1.00 1.20 1.40 1.60 1.80 2.00 2.50 3.00];y = log(MPa./3.77);x = (1./132.5 - 1./K);z = [x x.^2 log(K./132.5) ones(size(x))];Am I on the right track with this? James Tursa James Tursa on 29 Jul 2020

https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data#comment_954625

Cancel Copy to Clipboard
  • Link

    https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data#comment_954625

    Cancel Copy to Clipboard
Edited: James Tursa on 30 Jul 2020 Open in MATLAB Online Make K and MPa column vectors instead of row vectors.And good programming practice is to avoid "magic" numbers in your code like the 3.77 and the 132.5 values. Instead, use named variables with comments. E.g.,Pc = 3.77; % Critical Pressure (MPa)Tc = 132.5; % Critical Temperature (K)Then use Pc and Tc downstream in your code. It seems a simple thing, but it really helps with the readability and maintainability of your code. And put comments with description and units on every line that has values.What is the ones(size(x)) for? James Tursa James Tursa on 30 Jul 2020

https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data#comment_955438

Cancel Copy to Clipboard
  • Link

    https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data#comment_955438

    Cancel Copy to Clipboard
Lovie Reid Answer moved here:I've removed the ones(size(x)) I was just using other examples to help, but would this be right for the least squaresa = polyfit(x,y,2); James Tursa James Tursa on 30 Jul 2020

https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data#comment_955450

Cancel Copy to Clipboard
  • Link

    https://www.mathworks.com/matlabcentral/answers/572479-i-need-help-obtaining-the-values-c1-c2-c3-from-a-least-squares-fit-of-the-data#comment_955450

    Cancel Copy to Clipboard
Edited: James Tursa on 30 Jul 2020 Open in MATLAB Online polyfit(x,y,2) would be used if you had a set of x,y coordinates and you wanted to fit that with a 2nd degree polynomial. But you don't have that situation. You have a linear matrix equation with three variables that you are trying to fit. It is linear in the c1,c2,c3 terms. Using your variable names, you have this matrix equation (assuming you make y and x column vectors as I suggested):y = z * cYou have three unknowns, the c = [c1;c2;c3], and 21 equations. An overdetermined linear system of equations where you know y and z. You are being asked to produce the least squares solution for c.

Sign in to comment.

Sign in to answer this question.

See Also

Categories

AI and Statistics Statistics and Machine Learning Toolbox Probability Distributions Resampling Techniques Find more on Resampling Techniques in Help Center and File Exchange

Tags

  • least square fit
  • homework

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Close MathWorks - Domain Selector

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

  • (English)
  • (Deutsch)
  • (Français)
  • (简体中文)
  • (English)

You can also select a web site from the following list

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文Chinese
    • English
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

Từ khóa » C=c1+c2+c3