Finding a variable in a very complicated equation

8 visualizzazioni (ultimi 30 giorni)
There are two equations:
y=P*exp(-alfa*x)*cos(alfa*x)/(2*alfa^3*EI)
alfa=(k/(4*EI))^(1/4)
x, y, P, EI are known, I need to find k using these equations, accuracy of 0,0001 is enough
I think that the only way to find k is to use the trial and error (iteration) method, unfortunately I can't manage to write a good script to calculate that
Thank You for all Your help in advance

Risposta accettata

Star Strider
Star Strider il 24 Apr 2021
It would be nice if the constants were supplied. Using random numbers for them —
x = rand;
y = rand;
P = rand;
EI = rand;
alfa = @(k,EI) (k./(4*EI)).^(1/4);
yfcn = @(x,y,P,EI,k) P.*exp(-alfa(k,EI).*x).*cos(alfa(k,EI).*x)./(2*alfa(k,EI).^3.*EI) - y;
[k_est,fv] = fsolve(@(k)yfcn(x,y,P,EI,k), 1)
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
k_est = 2.1218
fv = 4.1983e-06
.
  8 Commenti
Nikodem Podlaszewski
Nikodem Podlaszewski il 2 Mag 2021
I have an another problem. After inputting the code to MatLab and hitting "Run and Time" the results don't show anywhere. Instead, I see Profiler and a warning that says "The variable "k_est" appears to change size on every loop iteration (within a script). Consider preallocating for speed" The same appears for the variable "fv". I've read a lot about it and it appears to be just warnings but I can't see the results (nothing is being showed in Command Windows nor the output Array2table. Could you help me to get the results from that?
Star Strider
Star Strider il 2 Mag 2021
Apparently, there is more to your code than what you posted.
If you are using a for loop, it is relatively straightforward to preallocate ‘k_est’ and fv’
x = rand;
y = rand;
P = rand;
EI = rand;
alfa = @(k,EI) (k./(4*EI)).^(1/4);
yfcn = @(x,y,P,EI,k) P.*exp(-alfa(k,EI).*x).*cos(alfa(k,EI).*x)./(2*alfa(k,EI).^3.*EI) - y;
num_iter = 10; % Use The Appropriate Value
k_est = zeros(num_iter,1); % Preallocate Vector
fv = zeros(num_iter,1); % Preallocate Vector
for k1 = 1:num_iter
[k_est(k1),fv(k1)] = fsolve(@(k)yfcn(x,y,P,EI,k), 10);
end
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient. Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
Output = table(k_est,fv)
Output = 10×2 table
k_est fv ________ __________ 0.077417 1.1087e-08 0.077417 1.1087e-08 0.077417 1.1087e-08 0.077417 1.1087e-08 0.077417 1.1087e-08 0.077417 1.1087e-08 0.077417 1.1087e-08 0.077417 1.1087e-08 0.077417 1.1087e-08 0.077417 1.1087e-08
If you are using a while loop, preallocate the vectors to be greater than what you will likely require, then after the looop finishes (since you will have used a counter to create the ‘k1’ values) re-define —
k_est = k_est(1:k1);
fv = fv(1:k1);
This discards the rest of the vector, saving memory.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by