fsolve with symbolic variables
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone,
I am solving a nonlinear system of 4 equations with fsolve. out of the four results, i want to use one as input for another system of equation.
i can do it manually in 2 scripts, but i would like to combine then
I tried to define a global symbolic variable
syms y_pivot;
global y_pivot;
then i calculatd y_pivot, and substituted it
subs(y_pivot,x(4));
then i called the function, inside the function i defined the global symbolic variable as well
function F = constraintequation_vollhub(x)
syms y_pivot;
global y_pivot;
%
F = [cos(x(1))* 18.144 - sin(x(2))*(19.667+10.5) - 14.070 + x(3);
sin(x(1))* 18.144 - cos(x(2))*(19.667+10.5) + x(4) - 15;
cos(x(1))* 18.144 + cos(pi+x(1)-3.2217382) * 19.789 + x(3) - y_pivot * sin(0.296705972) - 14.070
sin(x(1))* 18.144 + sin(pi+x(1)-3.2217382) * 19.789 - 15 - y_pivot * cos(0.296705972) + x(4) + 36.769];
then i tried to solve it with
x0_voll = [0; 0; 0; 0]; % Make a starting guess at the solution
[x_voll,fval] = fsolve(@constraintequation_vollhub,x0_voll) % Call solver
i get the error
??? Undefined function or method 'isfinite' for input arguments of type 'sym'.
Error in ==> trustnleqn at 27
if any(~isfinite(Fvec))
Error in ==> fsolve at 366
[x,FVAL,JACOB,EXITFLAG,OUTPUT,msgData]=...
when i replace the symbolic variable manually, everthing works fine, so i guess it is only the symbolic variable in the function
i tried to find solutions in the forum, but i am not that used to matlab and i couldnt find anything suiting, so i am sorry if the topic is already around..
Thank you in advance
0 commentaires
Réponses (1)
Star Strider
le 7 Juin 2014
You need to use either the Symbolic Toolbox solve function or matlabFuncton to convert your expression into a form fsolve can use.
0 commentaires
Voir également
Catégories
En savoir plus sur Equation Solving dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!