How can i find a parameter in a formula when i have three series od data and wanna to find best answer for fourth parameter?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
I have three series od data for x,y and z I wanna find the fourth parameter m(like the best fit for it)in a Maxwell relaxation formula which that is:
z=2*m*x*y
and the series of other parameters are:
z=[0.0892 .158 0.890 1.26 2.47 3.64 6.71 11.6 18.1 27.7 42.0 65.4 97.5 141.0 196.0 283.0 440.0 661.0 863];
x=[0.05 0.628 0.0791 0.0995 0.125 0.158 0.199 0.25 0.315 0.396 0.5 0.628 0.79 0.995 1.25 1.58 1.99 2.5 3.15];
y=[1.42 1.78 2.25 2.83 3.56 4.49 5.65 7.08 8.79 11.01 13.87 17.46 21.8 27.16 33.75 42.34 53.53 67.03 84.11];
I will be grateful for helping me on this case.
Accepted Answer
Star Strider
on 25 Oct 2014
This works:
z=[0.0892 .158 0.890 1.26 2.47 3.64 6.71 11.6 18.1 27.7 42.0 65.4 97.5 141.0 196.0 283.0 440.0 661.0 863];
x=[0.05 0.628 0.0791 0.0995 0.125 0.158 0.199 0.25 0.315 0.396 0.5 0.628 0.79 0.995 1.25 1.58 1.99 2.5 3.15];
y=[1.42 1.78 2.25 2.83 3.56 4.49 5.65 7.08 8.79 11.01 13.87 17.46 21.8 27.16 33.75 42.34 53.53 67.03 84.11];
xy = [x; y];
fz= @(m,xy) 2.*m.*xy(1,:).*xy(2,:);
CF = @(m) sum((z - fz(m,xy)).^2);
m = fminsearch(CF, 1);
ze = fz(m, xy);
figure(1)
plot3(x, y, z, '+b')
hold on
plot3(x, y, ze, '-r')
hold off
grid on
view([30 40])
It estimates: m = 1.794 and seems visually to give a good fit.
8 Comments
amir
on 25 Oct 2014
tanx for this solution but I have one more question and that is: how do u find 'm' ? cause it just give the figurative of them but no answer
My pleasure!
If you run the code in my Answer to calculate ‘m’.
You find ‘m’ as the output of the fminsearch function in this line:
m = fminsearch(CF, 1);
When I ran your data, I got: m = 1.794.
I thought this could be a ‘prototype’ Question for a more complicated problem so I used fminsearch. Your problem as stated is actually a linear problem and can be solved for ‘m’ using the mldivide function:
m = [2*x'.*y']\z';
giving the same answer for ‘m’.
amir
on 25 Oct 2014
sorry for asking so many questions but the reason I ask this question is that I wanna fit the answer on log-log scale figure in matlab...
No problem on the questions.
You are going to plot in three dimensions with plot3, so you will have to specify the log or linear scale you want on the separate x, y, and z axes. The 2-dimensional loglog plot will not work with your 3-dimensional data. I can help you with the axis scaling, but you will have to tell me what you want, and what version of MATLAB you are using (since some plotting commands have changed in R2014b).
I apologise for the delay in replying. Microsoft decided today that I absolutely had to upgrade to Windows 8.1, and that took nearly 4 hours to complete.
amir
on 25 Oct 2014
u must sorry me to bothering u so much
I actually use matlab 2013a and I want to plot those data in log-log-log scale and 3D dimensional then find the best fit for that formula I had given before to estimate the value of n(calculating of m on log-log-log scale).
because on your advise when I change the lineat axes to log scales it doesn't affect on the value of m and it does estimate base on linear axes.
Questions are welcome.
If I solve your problem, I will appreciate it if you Accept my answer.
This code does what you want:
z=[0.0892 .158 0.890 1.26 2.47 3.64 6.71 11.6 18.1 27.7 42.0 65.4 97.5 141.0 196.0 283.0 440.0 661.0 863];
x=[0.05 0.628 0.0791 0.0995 0.125 0.158 0.199 0.25 0.315 0.396 0.5 0.628 0.79 0.995 1.25 1.58 1.99 2.5 3.15];
y=[1.42 1.78 2.25 2.83 3.56 4.49 5.65 7.08 8.79 11.01 13.87 17.46 21.8 27.16 33.75 42.34 53.53 67.03 84.11];
xy = [x; y];
fz= @(m,xy) 2.*m.*xy(1,:).*xy(2,:);
CF = @(m) sum((z - fz(m,xy)).^2);
m = fminsearch(CF, 1);
ze = fz(m, xy);
figure(1)
plot3(x, y, z, '+b')
hold on
plot3(x, y, ze, '-r')
hold off
grid on
view([30 40])
legend('Data', 'Fitted Regression', 'Location', 'SE')
text(0.2, 30, 800, sprintf('\\itz\\rm = %6.3f\\bullet\\itx\\rm\\bullet\\ity', m))
xlabel('X')
ylabel('Y')
zlabel('Z')
set(gca,'XScale','log')
set(gca,'YScale','log')
set(gca,'ZScale','log')
producing this plot:
<<www-mathworks-com-matlabcentral-answers-uploaded_files-19985-How-20can-20i-20find-20a-20parameter-20in-20a-20formula-20when-20i-20have-20three-20series-20od-20data-20and-20wanna-20to-20find-20best-20answer-20for-20fourth-20parameter-20--202014-2010-2025.png>>
We have already estimated your ‘m’ parameter, and the fit is quite good, so you need do nothing other than what is in my code.
amir
on 26 Oct 2014
Thank you very much....
My pleasure!
More Answers (0)
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!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: .
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
- United Kingdom (English)