if statment.. why i am not getting correct answer of hmin near to 3.800113e-6
Show older comments
Hi all plz help me.I don't understand why following code is not working..Take hmin=[0:0.001e-6:8e-6] and " error <= ±0.001 " and display first value of hmin where error <= ±0.001 .... here i had find the value of hmin for 3.800113e-6 by hand calculation which i want to reflect in MATLAB display by taking range of hmin from 0 to 8e-6.
if true
% code
end
clc
clear all
close all
N=7;
b=0.003;
R=2;
hmin=[3e-6:0.1e-6:4e-6];
Pe=2e5;
x=linspace(-b/2, b/2, N);
delta_x= x(2)-x(1);
for I=1:N
H(I)=hmin(I)+(x(I)^2)/(2*R);
end
for I=2:N-1
Z(I)=(((H(I+1)+H(I))*0.5)^3)+(((H(I)+H(I-1))*0.5)^3);
A(I)=1;
B(I)=-((((H(I)+H(I-1))*0.5)^3)/(Z(I)));
C(I)=-((((H(I+1)+H(I))*0.5)^3)/(Z(I)));
D(I)=-(2.6527e-4*(H(I+1)-H(I-1)))/(Z(I));
end
A2=[A(2:N-1)];
B2=[B(3:N-1)];
C2=[C(2:N-2)];
X=diag(A2)+diag(C2,1)+diag(B2,-1);
P1=4e6;
P2=0;
Force_E=(b*Pe)+(b*((P1+P2)*0.5));
display(Force_E);
D2=[D(3:N-2)];
Y=[D(2)-(B(2)*P1) D2 D(N-1)-(C(N-1)*P2)];
y=Y';
Z=(inv(X))*y;
p=Z';
P=[P1 p P2];
P=[P(1:N)];
x2=[x(P<=0)];
P(P<=0)=0;
P2=[P(1:N)];
P2(N+1)=0;
P3=P(1)/2 + sum(P(2:N));
Force_P=P3*delta_x;
display(Force_P);
error=Force_P-Force_E;
if abs(error) <= 0.01
break
end
display(hmin(abs(error) <= 0.01));
3 Comments
Geoff Hayes
on 4 May 2015
Priya - please don't duplicate your questions. Instead of reposting, elaborate on the problem in your original question. You mention an "if statement" in your question header - what does this correspond to in your code?
Image Analyst
on 4 May 2015
Edited: Image Analyst
on 4 May 2015
I reopened it - there have been some changes since the earlier version. I'm going to go back and delete that older one since there wasn't really any good answers there and this is her updated code. And I was in the middle of answering it when it got closed. Though I agree she should stick to just one thread even if it needs to be updated.
Priya Varma
on 4 May 2015
Accepted Answer
More Answers (0)
Categories
Find more on Code Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!