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
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

댓글을 달려면 로그인하십시오.

 채택된 답변

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2020년 3월 31일

댓글:

2020년 4월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by