Using fsolve to solve a system of multi-variable equations

12 vues (au cours des 30 derniers jours)
Alex Wylie
Alex Wylie le 16 Fév 2017
I am trying to solve a system of 4 equations which are summations of Eigenseries. There are 4 variables. The functions/governing equations are actually determine using several inputs which are pre-determined constants using a function. It seems that when I'm trying to use the function handle (@ funk) I am not allowed to put any inputs other than 'x', a vector that contains 4 the variables, into funk. How am I supposed to go around this? I need the equations to be inputs into the function or to somehow use fsolve on 4 equations direction without using a function.
Thank you for your time, Alex.

Réponses (2)

Torsten
Torsten le 16 Fév 2017
https://de.mathworks.com/help/optim/ug/passing-extra-parameters.html
Best wishes
Torsten.
  5 commentaires
Alex Wylie
Alex Wylie le 16 Fév 2017
I think I may have fixed it but I have a different error now. I used the code
x = [a_i, b_i, c_i, d_i];
fun = @(x) funk(a_inc, x, Cn, kf, kr, nf, nr, B, w, n, t);
x0 = double([a_inc*0.3, a_inc*0.7, a_inc*0.1, a_inc*0.6]);
x = fsolve(fun, x0);
Where the function funk is
function fun = funk(a_inc, x, Cn, kf, kr, nf, nr, B, w, n, t)
EQ_1 = dphi1(a_inc, x(1), Cn, kf, nf, -B/2, B, w, t, n) - dphi2(x(2), x(3), Cn, kr, nr, -B/2, B, w, t, n);
EQ_2 = phi1(a_inc, x(1), Cn, kf, nf, -B/2, B, w, t, n) - phi2(x(2), x(3), Cn, kr, nr, -B/2, B, w, t, n);
EQ_3 = dphi2(x(2), x(3), Cn, kr, nr, B/2, B, w, t, n) - dphi3(x(4), Cn, kf, nf, B/2, B, w, t, n);
EQ_4 = phi2(x(2), x(3), Cn, kr, nr, B/2, B, w, t, n) - phi3(x(4), Cn, kf, nf, B/2, B, w, t, n);
fun = [EQ_1, EQ_2, EQ_3, EQ_4];
end
However now I get the error: "Error using fsolve (line 269) FSOLVE requires all values returned by functions to be of data type double." Once again I tried to convert each of the inputs excluding 'x' into double but the function double didn't let me. Any ideas ? Thanks so much
Torsten
Torsten le 16 Fév 2017
fsolve doesn't work with symbolic variables - EQ_1, EQ_2, EQ_3 and EQ_4 must be of type double.
Best wishes
Torsten.

Connectez-vous pour commenter.


Abdullaziz Al-Farqani
Abdullaziz Al-Farqani le 6 Avr 2019
try to define the 4 variables as vectors (x(1),x(2),...) instead of syms: a_i, b_i, c_i and d_i. See if it works

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by