Skocz do zawartości

Matlab układy równań nieliniowych


Pomocna odpowiedź

Napisano

Witam.

Potrzebuje rozwiązać układ dwóch równań nieliniowych w matlabie. A, że słabo znam ten program to proszę o pomoc.

Równania maja taką postać:

100*cos(f1) + 200*cos(f1 + f2)*0,766 + 90=282.45

10 - 200*sin(f1 + f2)*0.766 - 100*sin(f1)=161.5668

Czy znacie jakąś funkcję, za pomocą której mógłbym wyznaczyć f1 i f2?

Nie mam matlaba, ale do rozwiązania takiego układu potrzebny jest moduł Optimalization.

Następnie używasz

fsolve() - spójrz na przykład nr 1. Gotowego kodu Ci nie wklejam, bo nie chciałbym napisać czegoś niedziałającego, a nie będę matlaba instalować aby sprawdzić czy to co skleciłem działa. No ale patrząc na przykład, powinieneś metodą kilku prób i błędów zrobić to poprawnie.

  • Pomogłeś! 1
Example 1

This example solves the system of two equations and two unknowns:

Rewrite the equations in the form F(x) = 0:

Start your search for a solution at x0 = [-5 -5].

First, write a file that computes F, the values of the equations at x.

function F = myfun(x)
F = [2*x(1) - x(2) - exp(-x(1));
     -x(1) + 2*x(2) - exp(-x(2))];

Save this function file as myfun.m somewhere on your MATLAB path. Next, set up the initial point and options and call fsolve:

x0 = [-5; -5];           % Make a starting guess at the solution
options=optimset('Display','iter');   % Option to display output
[x,fval] = fsolve(@myfun,x0,options)  % Call solver

gdzie plik myfun.m wygląda tak:

function F = myfun(x)
F = [100*cos(x(1)) + 200*cos(x(1) + x(2))*0.766 + 90 - 282.45;
10 - 200*sin(x(1) + x(2))*0.766 - 100*sin(x(1)) - 161.5668 
];

potem wywołujesz:

x0 = [-5; -5];           % Make a starting guess at the solution
options=optimset('Display','iter');   % Option to display output
[x,fval] = fsolve(@myfun,x0,options)  % Call solver

i masz wynik:

Norm of First-order Trust-region

Iteration Func-count f(x) step optimality radius

0 3 195063 1.93e+004 1

1 6 139833 1 2.12e+004 1

2 9 97046.4 2.5 2.14e+004 2.5

3 10 97046.4 2.5 2.14e+004 2.5

4 13 65516.6 0.625 2.82e+004 0.625

5 16 29199.8 1.5625 2.26e+004 1.56

6 19 14840.8 1.5625 1.95e+004 1.56

7 22 2315.17 0.58531 7.99e+003 1.56

8 25 119.108 0.647662 1.78e+003 1.56

9 28 1.11356 0.199165 22.9 1.62

10 31 0.000866739 0.0373982 1.53 1.62

11 34 6.43671e-010 0.00108313 0.00117 1.62

12 37 3.10597e-022 9.41564e-007 5.31e-010 1.62

Equation solved.

fsolve completed because the vector of function values is near zero

as measured by the default value of the function tolerance, and

the problem appears regular as measured by the gradient.

x =

-7.2682

-5.7599

fval =

1.0e-010 *

-0.1393

-0.1080[/code

Czyli dokładnie tak jak napisał MatManiak;)

  • Lubię! 1

Bądź aktywny - zaloguj się lub utwórz konto!

Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony

Utwórz konto w ~20 sekund!

Zarejestruj nowe konto, to proste!

Zarejestruj się »

Zaloguj się

Posiadasz własne konto? Użyj go!

Zaloguj się »
×
×
  • Utwórz nowe...