Having a problem with MATLAB reconising variables

I have two MATLAB files in my diretory, one is a list of variables, the other is an fsolve script which uses the variables from the previous script. I execute the the list of variables files so that the list of variables is in the workspace, but when I try and run my function file MATLAB says that the variables are undefined. Can anybody help?

1 comentario

You forgot to post your error message. Please post ALL the red text, exactly as it appears. Don't snip or paraphrase.

Respuestas (1)

José-Luis
José-Luis el 15 de En. de 2014
Editada: José-Luis el 15 de En. de 2014
Your function has no idea of what's in your workspace. You need to pass these variables to the function if you want it to be able to see them. For that you could simply run the script inside your function:
function [bla] = your_fun(something)
myscript.m %Tada!!!
do your thing
end
For the sake of completeness, I should say that you could also declare them as globals. But that's always a terrible idea.

1 comentario

Benjamin
Benjamin el 15 de En. de 2014
Editada: Benjamin el 15 de En. de 2014
Thank you for answering, I tried that but I'm still having problems, I will show you my script
function F=myfun(x)
%Angular velocity of WT (rad/s)
CapOm=0.733;
%Angular Velocity of Blade (rad/s)
Om=1460.735;
%Freestream (m/s)
Uinf=14.6;
%Cylinder radius (m)
rc=0.05;
%Coefficients of lift and drag
CL=3.4;
CD=0.27;
%Radius of WT
R=0.75;
%Elemental length
r=0.15;
%Number of blades
B=6;
%Velocity ratio
alpha=2.5;
%%%%%%%%%%
lambdar=(r*CapOm)/Uinf;
p=(B/((Uinf)^2))*((2*rc)/R);
q=(Om*rc)/2;
n=(4*pi)/(R*Uinf);
s=2*CapOm;
t=Om*rc;
u=(8*pi)/R;
v=1/(4*(Uinf^2));
w=Uinf^2;
[x(1)-atan((1-x(2))/(lambdar+((1-x(2))/lambdar)));
((w*(x(2)^2-2*x(2)+1)+(((1+x(3))*r*CapOm)-q)^2)*(p*(CL*sin(x(1))-CD*cos(x(1)))))-((n*r)*(1-x(2))*((s*r)*x(3)-t));
(((w*(x(2)^2-2*x(2)+1)+(((1+x(3))*r*CapOm)-q)^2))*(p*(CL*cos(x(1))+CD*sin(x(1)))))-((u*r)*((x(2)*(1-x(2)))+v*((((s*r)*x(3))-t)^2)));];
end
end
and I use
x0=[0.2 0.1 0.1];
fsolve(@myfun, x0)
to execute it

La pregunta está cerrada.

Preguntada:

el 15 de En. de 2014

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by