필터 지우기
필터 지우기

FSOLVE requires all values returned by user functions to be of data type double

조회 수: 4 (최근 30일)
syms x;
for i=1:8
xe=[0.07142
0.10701
0.14246
0.1778
0.21306
0.24857
0.28524
0.32688];
p1xe(i,1)=2.*asin(2.*xe(i,1))+4.*xe(i,1).*sqrt(1-(4.*xe(i,1).^2));
p1xc(i,1)=2.*asin(2.*x)+4.*x.*sqrt(1-(4.*x.^2));
p2xc(i,1)=sqrt(1-(4.*x.^2));
b(i,1)=1/(2.*x.*(1+(p1xc(i,1)/(16.*x.*p2xc(i,1))))); %b(i,1) haman R/H mib(i,1)ashad.
a0(i,1)=1;
a1(i,1)=(1/2).*b(i,1);
a2(i,1)=(1/8).*((b(i,1).^2)+4);
a3(i,1)=(1/16).*((b(i,1).^3)-(4.*b(i,1)));
a4(i,1)=(5/128).*((b(i,1).^4)-(8/5).*b(i,1).^2+(16/5));
a5(i,1)=(7/256).*(b(i,1).^5-(8/7).*b(i,1).^3-(16/7).*b(i,1));
a6(i,1)=(21/1024).*((b(i,1).^6)-(20/21).*b(i,1).^4-(16/21).*b(i,1).^2+(64/21));
a7(i,1)=(231/14336).*((b(i,1).^7)-(28/33).*b(i,1).^5-(112/231).*b(i,1).^3-(448/231).*b(i,1));
p3xc(i,1)=((a0(i,1).*x)-(a1(i,1).*(x.^2))-((4/3).*a2(i,1).*(x.^3))-((8/4).*a3(i,1).*(x.^4))...
-((16/5).*a4(i,1).*(x.^5))-((32/6).*a5(i,1).*(x.^6))-((64/7).*a6(i,1).*(x.^7))-((128/8).*a7(i,1).*(x.^8)));
%Function handle:
f=@(x)(p1xc(i,1).^(5/2)/(32.*p2xc(i,1).^(1/2).*p3xc(i,1))).*(x+(p1xc(i,1)/(16.*p2xc(i,1)))).^(-0.5)-p1xe(i,1);
xc(i,1) = fsolve(f,0.07)
i get this error: FSOLVE requires all values returned by user functions to be of data type double.
.how can i solve it?

채택된 답변

Matt J
Matt J 2020년 7월 5일
편집: Matt J 2020년 7월 5일
The result I get from this is,
xc =
0.1000
0.1500
0.2000
0.2500
0.3000
0.3500
0.4000
0.4500
Seems like a bit of a simple progression for such a complicated compilation of equations...
function xc=runit
xc=nan(8,1); %pre-allocate
for i=1:8
xc(i) = fsolve(@myfunction,0.07);
end
function f=myfunction(x) %NESTED FUNCTION
xe=[0.07142
0.10701
0.14246
0.1778
0.21306
0.24857
0.28524
0.32688];
p1xe(i,1)=2.*asin(2.*xe(i,1))+4.*xe(i,1).*sqrt(1-(4.*xe(i,1).^2));
p1xc(i,1)=2.*asin(2.*x)+4.*x.*sqrt(1-(4.*x.^2));
p2xc(i,1)=sqrt(1-(4.*x.^2));
b(i,1)=1/(2.*x.*(1+(p1xc(i,1)/(16.*x.*p2xc(i,1))))); %b(i,1) haman R/H mib(i,1)ashad.
a0(i,1)=1;
a1(i,1)=(1/2).*b(i,1);
a2(i,1)=(1/8).*((b(i,1).^2)+4);
a3(i,1)=(1/16).*((b(i,1).^3)-(4.*b(i,1)));
a4(i,1)=(5/128).*((b(i,1).^4)-(8/5).*b(i,1).^2+(16/5));
a5(i,1)=(7/256).*(b(i,1).^5-(8/7).*b(i,1).^3-(16/7).*b(i,1));
a6(i,1)=(21/1024).*((b(i,1).^6)-(20/21).*b(i,1).^4-(16/21).*b(i,1).^2+(64/21));
a7(i,1)=(231/14336).*((b(i,1).^7)-(28/33).*b(i,1).^5-(112/231).*b(i,1).^3-(448/231).*b(i,1));
p3xc(i,1)=((a0(i,1).*x)-(a1(i,1).*(x.^2))-((4/3).*a2(i,1).*(x.^3))-((8/4).*a3(i,1).*(x.^4))...
-((16/5).*a4(i,1).*(x.^5))-((32/6).*a5(i,1).*(x.^6))-((64/7).*a6(i,1).*(x.^7))-((128/8).*a7(i,1).*(x.^8)));
%Function handle:
f=(p1xc(i,1).^(5/2)/(32.*p2xc(i,1).^(1/2).*p3xc(i,1))).*(x+(p1xc(i,1)/(16.*p2xc(i,1)))).^(-0.5)-p1xe(i,1);
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by