fsolve question ('undefined function or variable')
Mostrar comentarios más antiguos
Hi, i'm trying to solve this code:
function g=llamada
x0=[0.1 0.03]
[dfinal]=fsolve(@(d) febrerodosmilcatorce2(q,d),x0)
function f=febrerodosmilcatorce2(q,d)
L1=10;
D=0.02;
L2=1.5;
L3=0.3;
C1=10;
C2=4000;
G=9.81;
L=0.03;
A=8/(pi^2*G*D^4);
AD=8/(pi^2*G*d^4);
f=[-L*L1*A*q^2/D+C1-C2*q^2-L*L2*A*q^2/(9*D)-L*L3*A*q^2/(9*D)-A*q^2;-L*L1*A*q^2/D+C1-C2*q^2-4*L*L3*AD*q^2/(9*d)-L*L2*AD*q^2/(9*d)-4*L*L3*AD*q^2/(9*d)-A*q^2];
I want that the first function calls the second one giving it two inputs (q and d) and that one returns me the final value of d.¿Can anyone help me?
Thanks
Respuestas (2)
Alan Weiss
el 24 de En. de 2017
It could be that the reason you want to run this complicated syntax is that you have not understood that MATLAB optimization functions optimize a single variable, usually called x. So if you want to solve for two variables, q and d, you can put them into a single vector x along the following lines:
function F = theObjective(x)
q = x(1);
d = x(2);
L1=10;
D=0.02;
L2=1.5;
L3=0.3;
C1=10;
C2=4000;
G=9.81;
L=0.03;
A=8/(pi^2*G*D^4);
AD=8/(pi^2*G*d^4);
F = [-L*L1*A*q^2/D+C1-C2*q^2-L*L2*A*q^2/(9*D)-L*L3*A*q^2/(9*D)-A*q^2;...
-L*L1*A*q^2/D+C1-C2*q^2-4*L*L3*AD*q^2/(9*d)-L*L2*AD*q^2/(9*d)-4*L*L3*AD*q^2/(9*d)-A*q^2];
Call the solver like this:
x0 = [0.1 0.03]
x = fsolve(@theObjective,x0)
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
1 comentario
alvaro laguna
el 24 de En. de 2017
Geoff Hayes
el 24 de En. de 2017
alvaro - what is the full error message? fsolve is part of the Optimization Toolbox, so you will need it in order to have access to this function. If you don't have this toolbox, then you are most likely seeing the
Undefined function 'fsolve' for input arguments of type 'function_handle'.
error.
From the command line, type ver to see which toolboxes you have installed. If you have this toolbox then type
which fsolve -all
to see if you may have a conflicting function.
1 comentario
alvaro laguna
el 24 de En. de 2017
Categorías
Más información sobre Choose a Solver en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!