Using Newton Raphson for Root Finding and Parameters' Estimation

2 Ansichten (letzte 30 Tage)
Isa Isa
Isa Isa am 25 Jun. 2014
Beantwortet: arushi am 3 Sep. 2024
Goood Day,
I have a cubic root equation. I use newton-raphson for finding the roots. I want to do parameter estimation (tuning of the equation parameters to be able to give better prediction) using experiment data. Can anyone help me on how to do this?
Thanks for your anticipated help Regards, Isa

Antworten (1)

arushi
arushi am 3 Sep. 2024
Hi Isa,
Below is a complete MATLAB script that performs parameter estimation for a cubic root equation using experimental data. It uses the fminsearch function to minimize the sum of squared errors between the experimental data and the model predictions.
% Define the objective function
function error = objectiveFunction(params, X, Y)
a = params(1);
b = params(2);
c = params(3);
% Predicted values
Y_pred = a * nthroot(X - b, 3) + c;
% Sum of squared errors
error = sum((Y - Y_pred).^2);
end
% Main script
% Experimental data (replace with your actual data)
X = [1, 2, 3, 4, 5]; % Example input values
Y = [2.5, 3.1, 3.8, 4.6, 5.5]; % Example observed outputs
% Initial guess for parameters [a, b, c]
initialParams = [1, 0, 0];
% Perform optimization using fminsearch
options = optimset('Display', 'iter'); % Show iteration details
optimizedParams = fminsearch(@(params) objectiveFunction(params, X, Y), initialParams, options);
Iteration Func-count f(x) Procedure 0 1 34.6349 1 4 32.812 initial simplex 2 5 32.812 reflect 3 7 31.6138 expand 4 9 28.7511 expand 5 11 26.5558 expand 6 13 21.9337 expand 7 15 15.679 expand 8 17 9.54283 expand 9 19 2.41587 expand 10 21 1.45351 reflect 11 23 1.14722 reflect 12 25 1.14722 contract outside 13 27 1.14722 contract inside 14 29 0.927037 contract inside 15 31 0.927037 contract inside 16 33 0.886597 contract inside 17 35 0.886597 contract inside 18 37 0.87412 contract inside 19 39 0.866634 contract inside 20 41 0.866634 contract inside 21 43 0.861225 contract inside 22 45 0.860257 contract inside 23 47 0.85832 contract inside 24 49 0.85832 contract inside 25 51 0.857801 contract inside 26 53 0.857674 contract inside 27 55 0.857482 contract inside 28 57 0.857383 contract inside 29 59 0.857289 contract inside 30 61 0.857277 contract inside 31 63 0.857237 contract inside 32 65 0.857233 contract inside 33 67 0.857213 contract inside 34 69 0.857213 contract inside 35 71 0.857204 contract inside 36 73 0.857204 contract inside 37 75 0.857203 contract inside 38 77 0.857203 contract inside 39 79 0.857202 contract inside 40 81 0.857201 contract inside 41 83 0.857201 contract inside 42 85 0.857201 contract inside 43 87 0.857201 contract inside 44 89 0.8572 reflect 45 90 0.8572 reflect 46 92 0.8572 contract inside 47 94 0.8572 reflect 48 96 0.857199 expand 49 97 0.857199 reflect 50 99 0.857199 reflect 51 101 0.857198 reflect 52 102 0.857198 reflect 53 104 0.857196 expand 54 106 0.857195 expand 55 107 0.857195 reflect 56 109 0.85719 expand 57 110 0.85719 reflect 58 112 0.857186 expand 59 114 0.857177 expand 60 115 0.857177 reflect 61 117 0.857167 expand 62 118 0.857167 reflect 63 120 0.857142 expand 64 121 0.857142 reflect 65 123 0.857116 expand 66 125 0.857066 expand 67 126 0.857066 reflect 68 128 0.856976 expand 69 130 0.856889 expand 70 132 0.856772 expand 71 134 0.856514 expand 72 136 0.85621 expand 73 138 0.855703 expand 74 140 0.854966 expand 75 142 0.853806 expand 76 144 0.852064 expand 77 146 0.849809 expand 78 148 0.845648 expand 79 150 0.840966 expand 80 152 0.834387 expand 81 154 0.823047 expand 82 155 0.823047 reflect 83 157 0.810982 expand 84 159 0.805072 expand 85 161 0.797987 expand 86 163 0.797987 contract inside 87 165 0.79494 expand 88 167 0.79494 contract inside 89 169 0.783492 expand 90 171 0.783492 contract inside 91 173 0.778369 expand 92 175 0.759858 expand 93 176 0.759858 reflect 94 178 0.743513 expand 95 180 0.716019 expand 96 182 0.67517 expand 97 183 0.67517 reflect 98 185 0.618405 expand 99 187 0.595904 expand 100 189 0.491588 expand 101 191 0.491588 contract inside 102 192 0.491588 reflect 103 193 0.491588 reflect 104 195 0.437306 expand 105 196 0.437306 reflect 106 198 0.436449 reflect 107 200 0.436449 contract inside 108 202 0.434228 contract inside 109 204 0.427912 contract inside 110 206 0.427236 contract inside 111 208 0.427236 contract inside 112 210 0.427236 contract outside 113 212 0.426875 contract inside 114 214 0.426079 contract inside 115 215 0.426079 reflect 116 217 0.426079 contract inside 117 218 0.426079 reflect 118 219 0.426079 reflect 119 221 0.426032 contract inside 120 223 0.426027 contract inside 121 225 0.426013 contract outside 122 227 0.425992 contract inside 123 228 0.425992 reflect 124 229 0.425992 reflect 125 231 0.425987 contract inside 126 233 0.425987 contract inside 127 235 0.425985 contract outside 128 237 0.425984 contract inside 129 239 0.425983 contract inside 130 241 0.425983 contract outside 131 243 0.425983 contract inside 132 245 0.425983 contract inside 133 247 0.425983 reflect 134 249 0.425983 contract inside 135 251 0.425983 reflect 136 252 0.425983 reflect 137 254 0.425983 contract inside 138 256 0.425983 contract inside 139 258 0.425983 expand 140 260 0.425983 contract inside 141 262 0.425982 expand 142 264 0.425982 contract inside 143 266 0.425982 expand 144 268 0.425982 expand 145 269 0.425982 reflect 146 271 0.425981 expand 147 272 0.425981 reflect 148 274 0.425981 expand 149 276 0.42598 expand 150 278 0.425979 expand 151 280 0.425976 expand 152 282 0.425974 expand 153 284 0.42597 expand 154 286 0.42596 expand 155 287 0.42596 reflect 156 289 0.425946 expand 157 291 0.425928 expand 158 293 0.425908 expand 159 295 0.425872 expand 160 297 0.425807 expand 161 299 0.425747 expand 162 301 0.425665 expand 163 303 0.425448 expand 164 304 0.425448 reflect 165 306 0.425366 expand 166 308 0.425073 expand 167 310 0.424909 expand 168 312 0.424909 contract outside 169 314 0.424737 expand 170 316 0.424122 expand 171 317 0.424122 reflect 172 319 0.423983 expand 173 321 0.422271 expand 174 322 0.422271 reflect 175 323 0.422271 reflect 176 325 0.419439 expand 177 326 0.419439 reflect 178 328 0.418158 expand 179 330 0.416935 expand 180 332 0.410423 expand 181 333 0.410423 reflect 182 334 0.410423 reflect 183 336 0.402328 expand 184 337 0.402328 reflect 185 339 0.394195 expand 186 341 0.386898 expand 187 343 0.372116 expand 188 345 0.36647 expand 189 346 0.36647 reflect 190 348 0.350771 expand 191 350 0.350771 contract outside 192 352 0.350771 contract inside 193 354 0.349407 reflect 194 356 0.332236 expand 195 357 0.332236 reflect 196 359 0.323389 expand 197 361 0.310069 expand 198 363 0.278243 expand 199 364 0.278243 reflect 200 366 0.257232 expand 201 368 0.209255 expand 202 370 0.205459 reflect 203 372 0.205459 contract inside 204 373 0.205459 reflect 205 375 0.157042 expand 206 376 0.157042 reflect 207 377 0.157042 reflect 208 378 0.157042 reflect 209 380 0.156259 contract outside 210 382 0.14583 contract inside 211 384 0.144667 reflect 212 386 0.144392 reflect 213 388 0.141008 contract inside 214 390 0.137357 reflect 215 392 0.136178 reflect 216 393 0.136178 reflect 217 395 0.132736 reflect 218 397 0.132736 contract inside 219 399 0.132736 contract inside 220 401 0.130838 reflect 221 403 0.127491 expand 222 405 0.127491 contract inside 223 406 0.127491 reflect 224 408 0.127491 contract inside 225 410 0.121959 expand 226 411 0.121959 reflect 227 413 0.120787 expand 228 415 0.114089 expand 229 417 0.114089 contract inside 230 418 0.114089 reflect 231 420 0.10772 expand 232 422 0.10772 contract inside 233 423 0.10772 reflect 234 424 0.10772 reflect 235 426 0.1067 reflect 236 428 0.10641 contract outside 237 430 0.104693 reflect 238 431 0.104693 reflect 239 433 0.104246 reflect 240 434 0.104246 reflect 241 436 0.103472 reflect 242 438 0.103472 contract inside 243 440 0.10274 reflect 244 441 0.10274 reflect 245 442 0.10274 reflect 246 444 0.100604 expand 247 446 0.100604 contract inside 248 447 0.100604 reflect 249 449 0.0997758 expand 250 450 0.0997758 reflect 251 452 0.0961137 expand 252 453 0.0961137 reflect 253 454 0.0961137 reflect 254 456 0.0911475 expand 255 457 0.0911475 reflect 256 458 0.0911475 reflect 257 460 0.0911475 contract inside 258 462 0.0906349 reflect 259 464 0.0892931 reflect 260 465 0.0892931 reflect 261 467 0.0887065 reflect 262 469 0.0858854 expand 263 471 0.0858854 contract inside 264 472 0.0858854 reflect 265 474 0.0837238 expand 266 475 0.0837238 reflect 267 477 0.0837238 contract inside 268 479 0.0821131 reflect 269 480 0.0821131 reflect 270 481 0.0821131 reflect 271 483 0.0821131 contract inside 272 485 0.0798292 expand 273 486 0.0798292 reflect 274 487 0.0798292 reflect 275 489 0.0769528 expand 276 491 0.0769528 contract inside 277 492 0.0769528 reflect 278 493 0.0769528 reflect 279 495 0.0740687 expand 280 496 0.0740687 reflect 281 498 0.0740687 contract inside 282 500 0.0718254 expand 283 502 0.0718254 contract inside 284 503 0.0718254 reflect 285 505 0.0706921 expand 286 506 0.0706921 reflect 287 508 0.0706921 contract inside 288 510 0.0706921 contract outside 289 512 0.0701974 reflect 290 514 0.0694689 reflect 291 516 0.0694689 contract inside 292 518 0.0694689 contract inside 293 520 0.0694689 contract inside 294 522 0.0694689 contract outside 295 524 0.0689662 expand 296 526 0.0689662 contract inside 297 528 0.0688645 expand 298 529 0.0688645 reflect 299 530 0.0688645 reflect 300 532 0.0686329 reflect 301 534 0.0686329 contract inside 302 536 0.0685804 reflect 303 538 0.0684887 reflect 304 540 0.0683618 reflect 305 542 0.0683314 reflect 306 544 0.0683314 contract inside 307 546 0.0681331 expand 308 548 0.0678161 expand 309 549 0.0678161 reflect 310 551 0.0673082 expand 311 552 0.0673082 reflect 312 554 0.0670407 reflect 313 556 0.0663312 expand 314 558 0.0655098 expand 315 559 0.0655098 reflect 316 561 0.0647683 expand 317 563 0.0641757 reflect 318 565 0.0638014 expand 319 566 0.0638014 reflect 320 568 0.0638014 contract inside 321 570 0.0635514 contract inside 322 572 0.0635514 contract inside 323 574 0.0630582 reflect 324 576 0.0630582 contract inside 325 577 0.0630582 reflect 326 579 0.0625529 expand 327 580 0.0625529 reflect 328 582 0.0619015 expand 329 584 0.0610881 expand 330 585 0.0610881 reflect 331 587 0.0605771 reflect 332 589 0.0605022 reflect 333 591 0.0605022 contract inside 334 593 0.0602891 reflect 335 595 0.0602891 contract inside 336 597 0.0595331 expand 337 599 0.0595331 contract inside 338 600 0.0595331 reflect Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 0.059533
% Display results
disp('Optimized Parameters:');
Optimized Parameters:
disp(optimizedParams);
14.5506 -13.5564 -33.1501
% Calculate predicted values with optimized parameters
Y_pred_optimized = optimizedParams(1) * nthroot(X - optimizedParams(2), 3) + optimizedParams(3);
% Plot the results
figure;
plot(X, Y, 'o', 'DisplayName', 'Experimental Data');
hold on;
plot(X, Y_pred_optimized, '-', 'DisplayName', 'Fitted Curve');
legend show;
xlabel('X');
ylabel('Y');
title('Parameter Estimation');
Hope this helps.

Community Treasure Hunt

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

Start Hunting!

Translated by