42 views (last 30 days)
Show older comments
Prabhath Manuranga on 21 May 2024 at 6:00
-
-
Link
Direct link to this question
https://in.mathworks.com/matlabcentral/answers/2120831-need-to-solve-the-following-equation-with-three-knowns-and-2-unknowns
Commented: Torsten on 21 May 2024 at 11:46
Open in MATLAB Online
W0 = Wi + (1 - L)*Hi*gi
W0 and L is an unknowns.
Wi, Hi, and gi are the knowns with 172 values per each.
I want to find W0 and L and their standard deviations as well.
I want to get each values comes for W0 and L when the program runs.
But when this code runs i got 0 for standard deviation of both W10 and L. Is this code is right? Can anyone help me to solve this?
The following code was written.
Wi = Wi;
Unrecognized function or variable 'Wi'.
Hi = H_BM;
gi = g_mean;
% Define the objective function
fun = @(x) norm(Wi + (1 - x(1))*Hi.*gi - x(2));
% Set initial guess for L and W0
x0 = [0, 0];
% Solve the optimization problem
x = fminsearch(fun, x0);
% Extract the values of L and W0
L = x(1);
L
W0 = x(2);
W0
% Calculate standard deviation of W0 and L
std_W0 = std(W0);
std_W0
std_L = std(L);
std_L
4 Comments Show 2 older commentsHide 2 older comments
Show 2 older commentsHide 2 older comments
Rik on 21 May 2024 at 6:53
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/2120831-need-to-solve-the-following-equation-with-three-knowns-and-2-unknowns#comment_3167036
You are calculating the standard deviation of a single value, not of the fit. fminsearch does not return the goodness of fit parameters with this syntax.
Prabhath Manuranga on 21 May 2024 at 7:49
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/2120831-need-to-solve-the-following-equation-with-three-knowns-and-2-unknowns#comment_3167096
Could you please tell me how to fix it?
Rik on 21 May 2024 at 8:40
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/2120831-need-to-solve-the-following-equation-with-three-knowns-and-2-unknowns#comment_3167136
Since you didn't post any data I can't show you what to do. You might want to try the fit function, since that will report the goodness of fit as the second output argument.
Prabhath Manuranga on 21 May 2024 at 9:07
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/2120831-need-to-solve-the-following-equation-with-three-knowns-and-2-unknowns#comment_3167201
- data123.xlsx
Please find the attached excel file for Wi, H_BM, and g_mean values.
Sign in to comment.
Sign in to answer this question.
Answers (1)
Torsten on 21 May 2024 at 8:51
Open in MATLAB Online
H_BM = rand(100,1);
g_mean = rand(100,1);
Wi = rand(100,1);
Hi = H_BM;
gi = g_mean;
x = Hi.*gi;
y = Wi + Hi.*gi;
fitlm(x,y)
ans =
Linear regression model: y ~ 1 + x1Estimated Coefficients: Estimate SE tStat pValue ________ ________ ______ __________ (Intercept) 0.41233 0.043102 9.5664 1.0575e-15 x1 1.2316 0.15371 8.013 2.3796e-12Number of observations: 100, Error degrees of freedom: 98Root Mean Squared Error: 0.294R-squared: 0.396, Adjusted R-Squared: 0.39F-statistic vs. constant model: 64.2, p-value = 2.38e-12
5 Comments Show 3 older commentsHide 3 older comments
Show 3 older commentsHide 3 older comments
Prabhath Manuranga on 21 May 2024 at 9:29
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/2120831-need-to-solve-the-following-equation-with-three-knowns-and-2-unknowns#comment_3167246
Edited: Prabhath Manuranga on 21 May 2024 at 9:30
Dear Mr. Torsten,
y= Wi + Hi.*gi; or y = Wi + (1-L)*Hi.*gi;
how to get two unknowns W0 and L, and their standard deviations here?
Torsten on 21 May 2024 at 9:33
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/2120831-need-to-solve-the-following-equation-with-three-knowns-and-2-unknowns#comment_3167261
W0 = Estimate intercept
L = Estimate x1
SE = standard errors of the estimated parameters
For further details, consult the documentation of "fitlm".
Prabhath Manuranga on 21 May 2024 at 10:55
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/2120831-need-to-solve-the-following-equation-with-three-knowns-and-2-unknowns#comment_3167391
Edited: Prabhath Manuranga on 21 May 2024 at 10:56
Dear Mr. Torsten,
For this equation can i use the same method you mentioned above. Above equation there is no any Pi (because Pi = 1). but here i need to use Pi weight for the calculation.
Torsten on 21 May 2024 at 11:26
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/2120831-need-to-solve-the-following-equation-with-three-knowns-and-2-unknowns#comment_3167451
Open in MATLAB Online
You have a linear regression equation
W0 + (L - 1)*Hi*gi = Wi
because if you set
W0 = a, L - 1 = b, Hi*gi = xi, Wi = yi
, your equation reads
a + b*x = y
You want to estimate a and b to make
sum_{i=1}^{i=172} (yi-(a+b*xi))^2
minimal.
This can be done via "fitlm" as I posted.
There are easier methods to get the coefficient a and b, but you wrote you also want statistical information about reliability etc.
Torsten on 21 May 2024 at 11:46
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/2120831-need-to-solve-the-following-equation-with-three-knowns-and-2-unknowns#comment_3167506
Open in MATLAB Online
- data123.xlsx
format long
M = readmatrix("data123.xlsx")
M = 10x3
1.0e+07 * 6.263682480329910 0.000000205900000 0.097810856393885 6.263657062323940 0.000002802300000 0.097812165123015 6.263669605757160 0.000001524500000 0.097811320851740 6.263624373910401 0.000006129800000 0.097810680733666 6.263620997894920 0.000006478400000 0.097810156445693 6.263650330102171 0.000003480200000 0.097811560786981 6.263682602864220 0.000000192100000 0.097810613817760 6.263680818837160 0.000000373000000 0.097808759764806 6.263617228951360 0.000006862700000 0.097809507129465 6.263661105500140 0.000002381500000 0.097808297704551
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Wi = M(:,1);
H_BM = M(:,2);
g_mean = M(:,3);
Hi = H_BM;
gi = g_mean;
x = Hi.*gi;
y = Wi;
fitlm(x,y)
ans =
Linear regression model: y ~ 1 + x1Estimated Coefficients: Estimate SE tStat pValue _____________________ __ _____ ______ (Intercept) 62636844.9371338 0 Inf 0 x1 -1.00231759363032e-05 0 -Inf 0 Number of observations: 10, Error degrees of freedom: 8R-squared: 1, Adjusted R-Squared: 1F-statistic vs. constant model: 4.65e+06, p-value = 2.4e-24
n = numel(Wi);
Mat = [ones(n,1),x];
rhs = y;
sol = Mat\rhs;
W0 = sol(1)
W0 =
6.263684493713374e+07
L = 1 + sol(2)
L =
0.999989976824064
Sign in to comment.
Sign in to answer this question.
See Also
Categories
IndustriesBiotech and PharmaceuticalGenomics and Next Generation Sequencing
Find more on Genomics and Next Generation Sequencing in Help Center and File Exchange
Tags
- equation
- unknowns
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.
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
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
- 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)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office