Newton-Raphson iteration method in Matrices
4 次查看(过去 30 天)
显示 更早的评论
PLease help. The the following MATLAB code is meant to implement the Newton Raphson iteration method to but it is not running.
% Change here for different loads
sigma=input('Enter solidity ratio= ');
0.1
lamda=input('Enter tip-speed ratio= ');
3
kappa=input('Enter angle of curvature: ');
0
delta=input('Enter pitch angle: ');
-2
theta=thetak';
phai=atan(sin(theta)./(lamda.+cos(theta)));
alpha=phai.-delta;
ct=(1.1*2*pi).*alpha;
geo=0.25*inv(pi)*sigma*sec(kappa).*ct;
Tol=input('Allowed tolerance value ');
0.05
dev=[Tol.*ones(N,2)];
nitermax=input('Number of maximum iterations = ');
100
wn=input('Enter initial value of the horizontal perturbation component: ');
-0.5
w_x=wn.*ones(N,1);
w_y=((sin(theta).*(1.+w_x).-cos(theta).*tan(phai).* (1.+w_x).-lamda.*tan(phai))./(sin(theta).*tan(phai).+cos(theta)));
v=[w_x,w_y];
w_x=v(:,1);
w_y=v(:,2);
F=(cos(theta).+w_x.*cos(theta).+w_y.*sin(theta).+lamda).^2;
f=geo.*(X*F).-sqrt(w_x.^2.+w_y.^2);
dFx=cos(theta).^2.*(2.*w_x.+2).+ 2.*lamda.* cos(theta).+w_y.*sin(2.*theta);
dFy=2.*w_y.*sin(theta).^2.+sin(2.*theta).+w_x.*sin(2.*theta).+2.*lamda.*sin(theta);
dF=[dFx,dFy];
J=geo.*(X*dF).-ones(N,2);
if J==0
disp('Error: (Division by zero, try another initial point) ')
return; %prompts back to the keyboard
elseif J~=0
wi=v.-(J./f);
errxi=abs(wi(:,1).-v(:,1))./abs(v(:,1));
erryi=abs(wi(:,2).-v(:,2))./abs(v(:,2));
err=[errxi,erryi];
endif;
i=0;
while (err>=dev & 0<=abs(wi)<1 & i<=nitermax)
i=i+1
v=wi;
wi=v.-(J./f);
w_x=wi(:,1);
w_y=wi(:,2);
F=(cos(theta).+w_x.*cos(theta).+w_y.*sin(theta).+lamda).^2;
f=geo.*(X*F).-sqrt(w_x.^2.+w_y.^2);
dFx=cos(theta).^2.*(2.*w_x.+2).+ 2*lamda.* cos(theta).+w_y.*sin(2.*theta);
dFy=2.*w_y.*sin(theta).^2.+sin(2.*theta).+w_x.*sin(2.*theta).+2*lamda.*sin(theta);
dF=[dFx,dFy];
J=geo.*(X*dF).-ones(N,2);
wi=v.-(J./f);
errxi=abs(wi(:,1).-v(:,1))./abs(v(:,1));
erryi=abs(wi(:,2).-v(:,2))./abs(v(:,2));
err=[errxi,erryi];
if err<=dev
fprintf('Iteration complete at i= #%d\n', i)
else
i=i+1;
endif;
endwhile;
end;
% 1. %both -1<[w_x,w_y]<1, that is the modulus is less than one as a condition.
% 2. The code is not iterating
0 个评论
采纳的回答
Hiro Yoshino
2020-2-19
I had a quick look though ... you are having lots of errors.
MATLAB has a fantastic bug finder as you can see.
The areas highlighted with colors (not sure how they look in your environment) represent your potential errors.
You can also count on the bar on the right hand side - it tells you where there are your errors.
This is worth taking a look at. Good luck!
2 个评论
Hiro Yoshino
2020-2-19
Octave is not fully compatible with MATLAB. It would not be a big issue unless you try something complex.
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!