save all value array in loop for

1 次查看(过去 30 天)
Can you help me how to save all value under array form in for loop.. with @myfun is function 2 variable, and I put variable_1 = X(1) ; variable_2 = X(2)
So result of X showed: for example 2.123 5.245
Mycode below:
N=10;
valueOfX = zeros(1,N);
for i=1:N
Pnet= 100+50*i;
x0=[10,10];
options=optimoptions('fsolve','Display','iter');
X=fsolve(@myfun,x0,options);
valueOfX(i)=X;
disp(valueOfX(i)/0.3048);
end
  2 个评论
Cris LaPierre
Cris LaPierre 2020-3-31
It would be helpful if you could also share your function myfun
Nhu Y Ha
Nhu Y Ha 2020-4-1
Hi Cris: this is function 'myfun' : thank you
function F = myfun(X)
syms Pnet
dhu=X(1);
dhd=X(2);
Pi=3.14;
psi = 6.894757 *10 ^3;
ft = 0.3048 ;
lbmpft3 = 16.01846;
inch = 0.0254 ;
psisqin = psi *sqrt(inch);
grav = 9.81;
Kictop= 1000 *psisqin ;
Kicbot = 1000*psisqin;
hpef = 50 *ft ;
rho = 62.4*lbmpft3;
dentau = 750*psi;
dentad = 750*psi;
denta = 0;
yd = -1 + 2*dhd /(hpef + dhd + dhu);
yu = 1 - 2*dhu/(hpef + dhd + dhu);
cOO = Pnet + rho* grav *(dhd - dhu)/2;
c1 = -rho*grav*(hpef + dhd + dhu)/2 ;
fd=@(y,cO,c1) ((1 - y)/(1 + y))^(1/2)*(cO - c1 + ((2*cO - c1)*y)/2 + (c1*y^2)/2) - (2*cO - c1)* atan(y*((1- y)/(1 + y))^(1/2)/(-1 + y))/2;
fu=@(y,cO,c1) ((-1 - y)/(-1 + y))^(1/2)*(-cO-c1 + ((2*cO + c1)*y)/2 + (c1*y^2)/2) + (2*cO + c1)* atan(y*((-1 - y)/(-1 + y))^(1/2)/(1 + y))/2;
fup1=@(cO,c1) Pi/4*(2*cO + c1);
fum1=@(cO,c1) Pi/4*(-2*cO - c1);
fdp1=@(cO,c1) Pi/4*(2*cO - c1);
fdm1=@(cO,c1) Pi/4*(-2*cO + c1);
Ku = -Kictop+ sqrt((hpef+dhu+dhd)/(2*Pi))*(fu(yd,cOO-dentad,c1)-fum1(cOO-dentad,c1)+fu(yu,cOO-denta,c1)-fu(yd,cOO-denta,c1)+fup1(cOO-dentau,c1)-fu(yu,cOO-dentau,c1));
Kd = -Kicbot+sqrt((hpef+dhd+dhu)/(2*Pi))*(fd(yd,cOO-dentad,c1)-fdm1(cOO-dentad,c1)+fd(yu,cOO-denta,c1)-fd(yd,cOO-denta,c1)+fdp1(cOO-dentau,c1)-fd(yu,cOO-dentau,c1));
F = [Ku;Kd];
end

请先登录,再进行评论。

采纳的回答

Cris LaPierre
Cris LaPierre 2020-3-31

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by