Need to solve the code?

1 view (last 30 days)
POTTA SATEESH
POTTA SATEESH on 3 May 2021
Commented: POTTA SATEESH on 4 May 2021
u1 = 0.32;
v1 = 0.032;
u2 = 1400000;
v2 = 70000;
u3 = 100;
v3 = 40;
a1 = -0.5;
a2 = -0.5;
a3 = 0.707;
A1 =0;
A2 = 0;
A3 = 0;
U3 = 0;
V3 = 0;
S = 1;
K = 0;
B1 = 5;
delta = 0.001;
LM = (u3^2)/(sqrt((u3^2)+(v3^2)));
LS = sqrt(log(1+((v3^2)/(u3^2))));
X1 = @(z1,u1,v1) (u1+(v1*z1));
X2 = @(z2,u2,v2) (u2+(v2*z2));
X3 = @(z3,U,V) (U+(V*z3));
f = @(X1,X2,X3,z1,u1,v1,z2,u2,v2,z3,U,V) ((X1(z1,u1,v1)*X2(z2,u2,v2))-(2000*X3(z3,U,V)));
while (abs(A1-a1)>0.01 && abs(A2-a2)>0.01 && abs(A3-a3)>0.01 && abs(U3-u3)>0.01 && abs(V3-v3)>0.01)
if S~=1
a1 = A1;
a2 = A2;
a3 = A3;
u3 = U3;
v3 = V3;
end
U = u3;
V = v3;
% B1 = (-((44800*a1)+(22400*a2)-(2000*V*a3))+sqrt(((44800*a1)+(22400*a2)-(2000*V*a3))^2-(4*(2240*a1*a2)*(-2000*U))))/(2*2240*a1*a2);
% B2 = (-((44800*a1)+(22400*a2)-(2000*v*a3))-sqrt(((44800*a1)+(22400*a2)-(2000*v*a3))^2-(4*(2240*a1*a2)*(-2000*u))))/(2*2240*a1*a2);
z1 = a1*B1;
z2 = a2*B1;
z3 = a3*B1;
A1 = (f(X1,X2,X3,z1+delta,u1,v1,z2,u2,v2,z3,U,V)-f(X1,X2,X3,z1,u1,v1,z2,u2,v2,z3,U,V))/(delta);
A2 = (f(X1,X2,X3,z1,u1,v1,z2+delta,u2,v2,z3,U,V)-f(X1,X2,X3,z1,u1,v1,z2,u2,v2,z3,U,V))/(delta);
A3 = (f(X1,X2,X3,z1,u1,v1,z2,u2,v2,z3+delta,U,V)-f(X1,X2,X3,z1,u1,v1,z2,u2,v2,z3,U,V))/(delta);
K = (sqrt((A1)^2+(A2)^2+(A3)^2));
A1 = -(A1)/K;
A2 = -(A2)/K;
A3 = -(A3)/K;
X3 = U+(A3*B1*V);
V3 = (X3*LS);
U3 = X3*(1-log(X3)+log(LM));
S = S+1;
end
error:
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in newtrail_1>@(X1,X2,X3,z1,u1,v1,z2,u2,v2,z3,U,V)((X1(z1,u1,v1)*X2(z2,u2,v2))-(2000*X3(z3,U,V))) (line 24)
f = @(X1,X2,X3,z1,u1,v1,z2,u2,v2,z3,U,V) ((X1(z1,u1,v1)*X2(z2,u2,v2))-(2000*X3(z3,U,V)));
Error in newtrail_1 (line 40)
A1 = (f(X1,X2,X3,z1+delta,u1,v1,z2,u2,v2,z3,U,V)-f(X1,X2,X3,z1,u1,v1,z2,u2,v2,z3,U,V))/(delta);

Accepted Answer

Walter Roberson
Walter Roberson on 3 May 2021
X3 = @(z3,U,V) (U+(V*z3));
So X3 is a function handle.
X3 = U+(A3*B1*V);
So X3 is a numeric variable now.
But you are inside a loop, and when you go back, X3 is still a numeric value but will be expected to be a function handle.
  3 Comments
Walter Roberson
Walter Roberson on 4 May 2021
u1 = 0.32;
v1 = 0.032;
u2 = 1400000;
v2 = 70000;
u3 = 100;
v3 = 40;
a1 = -0.5;
a2 = -0.5;
a3 = 0.707;
A1 =0;
A2 = 0;
A3 = 0;
U3 = 0;
V3 = 0;
S = 1;
K = 0;
B1 = 5;
delta = 0.001;
LM = (u3^2)/(sqrt((u3^2)+(v3^2)));
LS = sqrt(log(1+((v3^2)/(u3^2))));
X1 = @(z1,u1,v1) (u1+(v1*z1));
X2 = @(z2,u2,v2) (u2+(v2*z2));
X3 = @(z3,U,V) (U+(V*z3));
f = @(X1,X2,X3,z1,u1,v1,z2,u2,v2,z3,U,V) ((X1(z1,u1,v1)*X2(z2,u2,v2))-(2000*X3(z3,U,V)));
while (abs(A1-a1)>0.01 && abs(A2-a2)>0.01 && abs(A3-a3)>0.01 && abs(U3-u3)>0.01 && abs(V3-v3)>0.01)
if S~=1
a1 = A1;
a2 = A2;
a3 = A3;
u3 = U3;
v3 = V3;
end
U = u3;
V = v3;
% B1 = (-((44800*a1)+(22400*a2)-(2000*V*a3))+sqrt(((44800*a1)+(22400*a2)-(2000*V*a3))^2-(4*(2240*a1*a2)*(-2000*U))))/(2*2240*a1*a2);
% B2 = (-((44800*a1)+(22400*a2)-(2000*v*a3))-sqrt(((44800*a1)+(22400*a2)-(2000*v*a3))^2-(4*(2240*a1*a2)*(-2000*u))))/(2*2240*a1*a2);
z1 = a1*B1;
z2 = a2*B1;
z3 = a3*B1;
A1 = (f(X1,X2,X3,z1+delta,u1,v1,z2,u2,v2,z3,U,V)-f(X1,X2,X3,z1,u1,v1,z2,u2,v2,z3,U,V))/(delta);
A2 = (f(X1,X2,X3,z1,u1,v1,z2+delta,u2,v2,z3,U,V)-f(X1,X2,X3,z1,u1,v1,z2,u2,v2,z3,U,V))/(delta);
A3 = (f(X1,X2,X3,z1,u1,v1,z2,u2,v2,z3+delta,U,V)-f(X1,X2,X3,z1,u1,v1,z2,u2,v2,z3,U,V))/(delta);
K = (sqrt((A1)^2+(A2)^2+(A3)^2));
A1 = -(A1)/K;
A2 = -(A2)/K;
A3 = -(A3)/K;
X3_var = U+(A3*B1*V);
V3 = (X3_var*LS);
U3 = X3_var*(1-log(X3_var)+log(LM));
S = S+1;
end
However, if you need X3 to be a function that is changing in time, then you would need different code.
POTTA SATEESH
POTTA SATEESH on 4 May 2021
thank you sir for your reply

Sign in to comment.

More Answers (0)

Categories

Find more on Install Products 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!