Finding a variable in a very complicated equation
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
채택된 답변
Star Strider
2021년 4월 24일
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
Thanks for very much for your answer
The values are:
E=210000 % [N/mm^2]
I=25*3^3/12 % [mm^4]
EI=E*I % [Nmm^2]
P=19.62 % [N]
x [mm] and y [mm] are formed into 60 pairs and create a matrix
a part of the matrix is
x y
400 -0.01
300 -0.09
200 -0.11
100 0.14
0 0.87
400 -0.02
300 -0.09
200 -0.10
100 0.12
0 0.80
Could you modify the script to calculate the value of k for each of the pairs? Thank you in advance
Sure!
xy = [400 -0.01
300 -0.09
200 -0.11
100 0.14
0 0.87
400 -0.02
300 -0.09
200 -0.10
100 0.12
0 0.80];
E=210000; % [N/mm^2]
I=25*3^3/12; % [mm^4]
EI=E*I; % [Nmm^2]
P=19.62; % [N]
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;
for kk = 1:size(xy,1)
[k_est(kk,:),fv(kk,:)] = fsolve(@(k)yfcn(xy(kk,1),xy(kk,2),P,EI,k), 1);
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.
No solution found.
fsolve stopped because the problem appears regular as measured by the gradient,
but the vector of function values is not near zero as measured by the
value of the function tolerance.
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.
No solution found.
fsolve stopped because the problem appears regular as measured by the gradient,
but the vector of function values is not near zero as measured by the
value of the function tolerance.
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.
Out = array2table([xy k_est, fv], 'VariableNames',{'x','y','k_est','fv'})
Out = 10×4 table
x y k_est fv
___ _____ _______ ___________
400 -0.01 0.47147 -5.6502e-06
300 -0.09 0.23986 -3.4322e-08
200 -0.11 0.42319 0.062807
100 0.14 0.53096 1.0563e-06
0 0.87 0.4441 7.7512e-08
400 -0.02 0.36061 -5.5235e-06
300 -0.09 0.23986 -3.4322e-08
200 -0.1 0.42319 0.052807
100 0.12 0.59015 1.3671e-07
0 0.8 0.49665 3.0442e-11
figure
stem3(Out.x, Out.y, Out.k_est, 'filled')
grid on
xlabel('x')
ylabel('y')
zlabel('k_{est}')

It would have been nice to have all that information at the outset.
Thank you very much! That's exactly what I needed. Could you also tell me what fv means? And what does @ do, for example in @(k, EI)?
As always, my pleasure!
The ‘fv’ variable is the function value of ‘yfcn’ at the convergence. The fsolve function is a root-finder, so ‘fv’ should be close to 0. The ‘fv’ value tells how close it actually is. Also, it is optional, however I usually get it so I can determine how close fsolve got to solving it.
The ‘@’ sign denotes a function handle that MATLAB uses to define functions or to refer to them. See the documentation on What Is a Function Handle? for more information.
Also, in your outcome appeared lines such as
"No solution found.
fsolve stopped because the problem appears regular as measured by the gradient,
but the vector of function values is not near zero as measured by the
value of the function tolerance."
What does it mean? In the Out 10x4 table there are solutions for all pairs so I don't get why there is no solution found.
The fsolve function is a root (zero) finder, so if it cannot find a solution (zero-crossing) within its accepted tolerances (the function value at convergence is greater than the tolerance, so greater than zero), it reports that as a minimum, however not a solution.
It is quite possible that the function has no real solution for those specific values. If you give it a complex initial estimate, perhaps 1+1i instead of 1, fsolve will search the complex space in that region for a complex solution.
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?
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.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
