Getting different results between Matlab integration and Maple?

5 Ansichten (letzte 30 Tage)
Hello everyone,
I am having trouble getting the same results for the same equation when using Matlab and Maple. Basically as the value for beta changes, Q should change as well hence its integral, hence T. When putting the same equation in Mable I get values for T that are close to 1 but that decrease as beta increases, however the values I get in Matlab are exactly 1 and do not change by changing beta. Is there something wrong with the level of precision in Matlab? Or a problem with the integration?
length_shaft = 0.4
% Determining 4 values of beta
f = 'cos(x)*cosh(x)-1';
roots = [fzero(f,4.0) fzero(f,7.0) fzero(f,10.0) fzero(f,14.0)];
beta = roots./length_shaft;
% Determining Constant (T) (a value for each beta)
syms y
Q = ((cos(beta.*y) + cosh(beta.*y)) - (((cos(beta.*length_shaft) - ...
cosh(beta.*length_shaft))./(sin(beta.*length_shaft) - ...
sinh(beta.*length_shaft))).*(sin(beta.*y) + sinh(beta.*y)))).^2;
B = int(Q,y,0, length_shaft);
T = (B.*2.5).^(-0.5);
B = double(B)
T = double(T)

Akzeptierte Antwort

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 16 Mai 2019
Hi Zeyad,
Here is an alternative function quad() with its set tolerance to compute integration that changes the solutution a bit.
clearvars
length_shaft = 0.4;
% Determining 4 values of beta
f = 'cos(x)*cosh(x)-1';
OPTs = optimset('tolX',1e-17);
Roots = [fzero(f,4.0, OPTs) fzero(f,7.0, OPTs) fzero(f,10.0, OPTs) fzero(f,14.0, OPTs)];
beta = Roots./length_shaft;
% Determining Constant (T) (a value for each beta)
for ii=1:numel(beta)
B(ii) = quad(@(y) ((cos(beta(ii)*y) + cosh(beta(ii)*y)) - (((cos(beta(ii)*length_shaft) - ...
cosh(beta(ii)*length_shaft))/(sin(beta(ii)*length_shaft) - ...
sinh(beta(ii)*length_shaft)))*(sin(beta(ii)*y) + sinh(beta(ii)*y)))).^2, 0, length_shaft, 1e-16);
T(ii) = (B(ii)*2.5)^(-0.5);
end
format long
B = double(B)
T = double(T)
An alternative way would be for the integration part to write your own code based on Simpson's rule that gives much higher accuracy.
Good luck.

Weitere Antworten (0)

Kategorien

Mehr zu Downloads finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by