if statment.. why i am not getting correct answer of hmin near to 3.800113e-6

2 views (last 30 days)
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
Image Analyst
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
Priya Varma on 4 May 2015
sorry but i am very new in MATLAB and also have not worked on it.. totally new here..so not know how to represent..please guide me to solve out this problem.. i only want the various value of error in vector form for every different value of hmin range...also want to display the minimum value of hmin where error is less than 0.001..if possible than please try to make correction in my code.. for this code value will be nearer to 3.800113e-6

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 4 May 2015
Don't call it error - that is the name of a truly essential built-in function. Of all functions you could destroy, you definitely don't want to overwrite that one.
Anyway, your line where you calculate the error is not even inside a loop. And "theError" is just one single scalar value. Even if it were less than 0.01, there is no way to break because you're not inside a loop.
Here's a tip: You can type control-a and control-i. This will indent everything properly and you can see what's in a loop and what is not.
  1 Comment
Priya Varma
Priya Varma on 4 May 2015
that is the problem sir...that i want to say ... where i put the loop such that all values do not change.. so how i can modify it ??????? if possible than make some modification in this code... please do some help to come out from this problem...

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!