how can we increase a value until we get answer

4 visualizzazioni (ultimi 30 giorni)
clc
clear all
% -------------------------------------data input-----------------------------------
alpha = [510; 310; 78; 120; 350; 490; 53; 150; 170; 149];
beta = [7.20; 7.85; 7.98; 7.10; 7.30; 6.90; 8.01; 7.30; 7.42; 7.16];
gamma = [0.00142; 0.00194; 0.00482; 0.00321; 0.00210; 0.00178; 0.00212; 0.00350; 0.00267; 0.00390];
delta = [0.0000001; 0.0000002; 0.0000003; 0.0000001; 0.0000002; 0.0000003; 0.0000001; 0.0000002; 0.0000003; 0.0000001];
% Pmin =[150; 100; 50; 50; 100; 100; 100; 100; 100; 100];
% Pmax =[600; 400; 200; 200; 350; 500; 300; 300; 300; 300];
n = 10;
Pr = 2500;
L = 8.6;
%--------------------------------------Program start here--------------------------------
while eps >= 0.001
L =
syms P
% P = sym('P');
% L = sym('L');
F = sym('F');
Lambda = sym('Lambda');
% n = length(alpha);
for i = 1:n
F(i) = alpha(i) + beta(i).*P + gamma(i).*P.^2 + delta(i).*P.^3;
disp(F(i))
Lambda = diff(F(i),P) - L == 0;
disp(Lambda);
S = solve(Lambda, P);
disp(S)
S1 = max(S)
% disp(S1)
X(i) = S1
% W = vpa(X(i),6)
double(X)
end
Pt = sum(X)
disp(Pt)
double(Pt)
eps = 2500 - double(Pt)
double(eps)
end
i want to increase L until i get eps >=0.01
for example i wanna increase L 0.01.....l=8.01,8.02,8.03
  1 Commento
Image Analyst
Image Analyst il 28 Dic 2021
eps is a built-in function that gives the smallest number that can be represented. It's value depends on the value of the variable. Like eps around 2 is different than eps around 10^30. That is why eps() can take a input number.
You should not use eps as the name of your own custom variable because it is a built-in function.

Accedi per commentare.

Risposta accettata

DGM
DGM il 28 Dic 2021
Modificato: DGM il 28 Dic 2021
This can be simplified, but let's start with the given approach.
format long
alpha = [510; 310; 78; 120; 350; 490; 53; 150; 170; 149];
beta = [7.20; 7.85; 7.98; 7.10; 7.30; 6.90; 8.01; 7.30; 7.42; 7.16];
gamma = [0.00142; 0.00194; 0.00482; 0.00321; 0.00210; 0.00178; 0.00212; 0.00350; 0.00267; 0.00390];
delta = [0.0000001; 0.0000002; 0.0000003; 0.0000001; 0.0000002; 0.0000003; 0.0000001; 0.0000002; 0.0000003; 0.0000001];
n = 10;
Pr = 2500;
L = 8.6;
dL = 0.01;
maxep = 0.001;
syms P
F = sym('F',[1 n]);
X = sym('X',[1 n]);
ep = 1; % eps() is a built-in function; avoid overloading it
while ep >= maxep
for k = 1:n
F(k) = alpha(k) + beta(k).*P + gamma(k).*P.^2 + delta(k).*P.^3;
Lambda = diff(F(k),P) - L == 0;
S = solve(Lambda, P);
X(k) = max(S);
end
Pt = sum(X);
ep = 2500 - double(Pt)
L = L+dL;
end
ep =
1.025620698183243e+02
ep =
83.166759617834032
ep =
63.781164518970400
ep =
44.405265975430211
ep =
25.039045507277024
ep =
5.682484700585064
ep =
-13.664434792915927
I doubt that negative eps is intended, so if not, you'll have to adjust the step size accordingly. Also, it should suffice to solve for P first instead of doing it every time. The following is an example of both.
% note that the solution doesn't depend on alpha
beta = [7.20; 7.85; 7.98; 7.10; 7.30; 6.90; 8.01; 7.30; 7.42; 7.16];
gamma = [0.00142; 0.00194; 0.00482; 0.00321; 0.00210; 0.00178; 0.00212; 0.00350; 0.00267; 0.00390];
delta = [0.0000001; 0.0000002; 0.0000003; 0.0000001; 0.0000002; 0.0000003; 0.0000001; 0.0000002; 0.0000003; 0.0000001];
n = 10;
Pr = 2500;
L = 8.6;
dL = 0.01;
maxep = 0.001;
ep = 1; % eps() is a built-in function; avoid overloading it
while ep >= maxep
X1 = (sqrt(gamma.^2 + 3*L*delta - 3*beta.*delta) - gamma)./(3*delta);
X2 = -(sqrt(gamma.^2 + 3*L*delta - 3*beta.*delta) + gamma)./(3*delta);
ep = 2500 - double(sum(max(X1,X2)));
if ep < 0
L = L-dL;
dL = dL/2;
L = L+dL;
ep = 1; % reset to dummy value
elseif ep > maxep
L = L+dL;
end
disp([dL L ep])
end
1.0e+02 * 0.000100000000000 0.086100000000000 1.025620698183266 0.010000000000000 8.619999999999999 83.166759617837670 0.010000000000000 8.629999999999999 63.781164518971764 0.010000000000000 8.639999999999999 44.405265975432485 0.010000000000000 8.649999999999999 25.039045507278843 0.010000000000000 8.659999999999998 5.682484700587793 0.005000000000000 8.654999999999999 1.000000000000000 0.002500000000000 8.652499999999998 1.000000000000000 0.002500000000000 8.654999999999998 0.844851669389300 0.001250000000000 8.653749999999999 1.000000000000000 0.000625000000000 8.653124999999998 1.000000000000000 0.000312500000000 8.652812499999998 1.000000000000000 0.000312500000000 8.653124999999998 0.240189895270305 0.000156250000000 8.652968749999998 1.000000000000000 0.000078125000000 8.652890624999998 1.000000000000000 0.000078125000000 8.652968749999998 0.089025922124165 0.000039062500000 8.652929687499999 1.000000000000000 0.000039062500000 8.652968749999999 0.013444156101286 0.000019531250000 8.652949218749999 1.000000000000000 0.000009765625000 8.652939453124999 1.000000000000000 0.000004882812500 8.652934570312498 1.000000000000000 0.000004882812500 8.652939453124997 0.003996445692792 0.000002441406250 8.652937011718748 1.000000000000000 0.000001220703125 8.652935791015622 1.000000000000000 0.000001220703125 8.652937011718747 0.001634518447190 0.000000610351563 8.652936401367185 1.000000000000000 0.000000610351563 8.652936401367185 0.000453554875094
This can be simplified further using the available numerical solvers.
% note that the solution doesn't depend on alpha
beta = [7.20; 7.85; 7.98; 7.10; 7.30; 6.90; 8.01; 7.30; 7.42; 7.16];
gamma = [0.00142; 0.00194; 0.00482; 0.00321; 0.00210; 0.00178; 0.00212; 0.00350; 0.00267; 0.00390];
delta = [0.0000001; 0.0000002; 0.0000003; 0.0000001; 0.0000002; 0.0000003; 0.0000001; 0.0000002; 0.0000003; 0.0000001];
n = 10;
Pr = 2500;
L = 8.6;
eptarget = 0.0005; % some specific value instead of a maximum
Ltarget = fzero(@(L) findep(beta,gamma,delta,L)-eptarget,L) % find L
Ltarget =
8.652936377363181
findep(beta,gamma,delta,Ltarget) % test L
ans =
5.000000014661055e-04
function ep = findep(beta,gamma,delta,L)
X1 = (sqrt(gamma.^2 + 3*L*delta - 3*beta.*delta) - gamma)./(3*delta);
X2 = -(sqrt(gamma.^2 + 3*L*delta - 3*beta.*delta) + gamma)./(3*delta);
ep = 2500 - double(sum(max(X1,X2)));
end
  4 Commenti
DGM
DGM il 29 Dic 2021
If you feel that the question has been satisfactorily answered, you can click Accept. That way the question is moved to the "answered" queue where it may be more attractive to other people searching for similar information in the future.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Matrix Computations in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by