| New Reply |
Functions close to zero in MATLAB |
Share Thread | Thread Tools |
| Nov8-12, 07:00 AM | #1 |
|
|
Functions close to zero in MATLAB
Hi all,
I need to find where a collection of curves are all approximately equal to zero (given some tolerance level) and was wondering if anyone could help me? I'm running the following script in MATLAB: dF2=0.001; dG2=0.001; initF2=0.522; initG2=-0.603; K=zeros(2); etaspan=[0 20]; H=[1;1]; options=odeset('AbsTol',1e-7,'RelTol',1e-4); while max(abs(H))>1e-8 [eta,X]=ode45(@nN,etaspan,[0;initF2+dF2;1;initG2;0],options); n=size(eta,1); X2=[X(n,1);X(n,3)]; [eta,X]=ode45(@nN,etaspan,[0;initF2;1;initG2+dG2;0],options); n=size(eta,1); X3=[X(n,1);X(n,3)]; [eta,X]=ode45(@nN,etaspan,[0;initF2;1;initG2;0],options); n=size(eta,1); X1=[X(n,1);X(n,3)]; K(1,1)=(X2(1)-X1(1))/dF2; K(2,1)=(X2(2)-X1(2))/dF2; K(1,2)=(X3(1)-X1(1))/dG2; K(2,2)=(X3(1)-X1(2))/dG2; H=K\-X1; initF2=initF2+H(1); initG2=initG2+H(2); end figure; hold all; plot(eta,X(:,1)); plot(eta,X(:,3)); plot(eta,(-1)*X(:,5)); plot(eta,X(:,2)); plot(eta,X(:,4)); hold off; xlabel('\eta') hleg = legend('F','G','-H','F\prime','G\prime','Location','SouthEast'); disp('Value of F''(0)') a = X(1,2); disp(a) disp('Value of G''(0)') b = X(1,4); disp(b) disp('Value of H(20)') c = X(end,5); disp(c) Calling the function: function Y=nN(x,X) n=1.3; dF1deta=X(2); dF2deta=n^(-1)*((X(2)^(2)+X(4)^(2))^((n-1)/2))^(-1)*((X(1)^(2)-X(3)^(2)+(X(5)+((1-n)/(n+1))*X(1)*x)*X(2))*(1+(n-1)*(X(2)^(2)+X(4)^2)^(-1)*X(4)^(2))-(n-1)*X(2)*X(4)*(X(2)^(2)+X(4)^(2))^(-1)*(2*X(1)*X(3)+(X(5)+((1-n)/(n+1))*X(1)*x)*X(4))); dG1deta=X(4); dG2deta=n^(-1)*((X(2)^(2)+X(4)^(2))^((n-1)/2))^(-1)*((2*X(1)*X(3)+(X(5)+((1-n)/(n+1))*X(1)*x)*X(4))*(1+(n-1)*(X(2)^(2)+X(4)^2)^(-1)*X(2)^(2))-(n-1)*X(2)*X(4)*(X(2)^(2)+X(4)^(2))^(-1)*(X(1)^(2)-X(3)^(2)+(X(5)+((1-n)/(n+1))*X(1)*x)*X(2))); dH1deta=-2*X(1)-(1-n)/(n+1)*x*X(2); Y = [dF1deta; dF2deta; dG1deta; dG2deta; dH1deta]; From the plot that is produced I would like to find where the curves for F, F', G and G' are approximately equal to zero given a tolerance of 1e-6. Simply from looking at the plot I can see that this is around eta~5.7 but I would like to be able to print out this value of eta. Is this possible? Any help would be greatly appreciated. |
| New Reply |
| Tags |
| matlab |
| Thread Tools | |
Similar Threads for: Functions close to zero in MATLAB
|
||||
| Thread | Forum | Replies | ||
| matlab functions | Math & Science Software | 0 | ||
| MatLab Warning: Matrix is singular, close to singular or badly scaled | Engineering, Comp Sci, & Technology Homework | 1 | ||
| MATLAB help! defining functions | Math & Science Software | 3 | ||
| Matlab can't recognize my functions | Math & Science Software | 1 | ||
| Matlab transfer functions | Mechanical Engineering | 1 | ||