Looking to solve this integral with variable bounds

%variables
F = .00024; %kg
E = 10^6; %mPa
I = 6.1*10^-9; %kg m^2
L = .01; %m
%solve for Theta sub 0
func = @(OO) L/sqrt((E*I)/(2*F)) - integral(@(theta)1./sqrt(cos(OO)-cos(theta)),OO,pi/2);
g = fzero(func,0);
OS = fsolve(func,.5);
ideally wanted to use fzero but not sure how to do it, the like below, OS = ... kinda works but I keep getting pi/2 and not sure why. Im using this is the follwing equation:
aa = linspace(pi/2*.99, 0, 49);
aa=aa';
%shape of rod given
xi = sqrt((2*E*I)/F)*(sqrt(cos(OS))-sqrt(cos(OS)-cos(aa)));
and not getting the values i am hoping for. any help appreciated

12 Comments

I am not certain what you want to do.
In any event, to understand the function, plot it —
F = .00024; %kg
E = 10^6; %mPa
I = 6.1*10^-9; %kg m^2
L = .01; %m
%solve for Theta sub 0
func = @(OO) L/sqrt((E*I)/(2*F)) - integral(@(theta)1./sqrt(cos(OO)-cos(theta)),OO,pi/2);
a = linspace(0, 2*pi, 250);
plotfunc = arrayfun(func, a);
Warning: Inf or NaN value encountered.
Warning: Minimum step size reached near x = 3.12898. There may be a singularity, or the tolerances may be too tight for this problem.
Warning: Minimum step size reached near x = 3.10374. There may be a singularity, or the tolerances may be too tight for this problem.
Warning: Inf or NaN value encountered.
figure
plot(a, real(plotfunc), a, imag(plotfunc))
grid
legend('Real','Imag', 'Location','best')
.
essentially I would like to solve for "OO" in "func" and then use that valuie of OOin my equation for xi.
Up to what you write, you only have to solve for OO once and then insert aa in the equation.
%variables
F = .00024; %kg
E = 10^6; %mPa
I = 6.1*10^-9; %kg m^2
L = .01; %m
%solve for Theta sub 0
func = @(OO) L/sqrt((E*I)/(2*F)) - integral(@(theta)1./sqrt(cos(OO)-cos(theta)),OO,pi/2);
OS = fsolve(func,.5)
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.
OS = 1.5708
aa = linspace(0,pi/2*.99, 49);
aa=aa';
%shape of rod given
xi = sqrt((2*E*I)/F)*(sqrt(cos(OS))-sqrt(cos(OS)-cos(aa)));
plot(aa,abs(xi))
The two functions you are using for that are root finding algorithms, and the integral function never crosses zero, except at approximately π, as can be seen in the plot.
ok so i edited it and ff1 should cross zero now but still does not seem to work
format long
F = .00024; %kg
E = 10^6; %mPa
I = 6.1*10^-9; %kg m^2
L = .01; %m
ep = 10^-8;
z(1) = 0;
for n = 2:10001
z(n) = z(n-1) + ((pi/2)/10000);
ff1(n) = L/sqrt((E*I)/(2*F)) - (2*(ep)^.5)/ (sin(z(n)))^.5 - integral(@(theta) 1./sqrt(cos(z(n))-cos(theta)),z(n)+ep,pi/2);
end
Warning: Minimum step size reached near x = 1.5708. There may be a singularity, or the tolerances may be too tight for this problem.
%figure(5)
plot(z,real(ff1))
func = @(OO) L/sqrt((E*I)/(2*F)) - (2*(ep)^.5)/ (sin(OO))^.5 - integral(@(theta)1./sqrt(cos(OO)-cos(theta)),OO,pi/2);
%OS = fzero(func,.5);
OS = fsolve(func,0.5)
Equation solved, inaccuracy possible. The vector of function values is near zero, as measured by the value of the function tolerance. However, the last step was ineffective.
OS =
1.570794630102631
L/sqrt((E*I)/(2*F))
ans =
0.002805147493273
pi/2
ans =
1.570796326794897
What do you mean by "it doesn't seem to work" ?
the value for OS is either rounded, or inaccurate. Zooming in on the vlaue in the plot, the graph crosses at a value smaller than 1.5708
The graph interpolates because the correct z(n) that makes the function zero is not hit.
I used more points for the graph (see above).
format long
F = .00024; %kg
E = 10^6; %mPa
I = 6.1*10^-9; %kg m^2
L = .01; %m
ep = 10^-8;
func = @(OO) L/sqrt((E*I)/(2*F)) - (2*(ep)^.5)/ (sin(OO))^.5 - integral(@(theta)1./sqrt(cos(OO)-cos(theta)),OO,pi/2);
%OS = fzero(func,.5);
OS = fsolve(func,0.5)
Equation solved, inaccuracy possible. The vector of function values is near zero, as measured by the value of the function tolerance. However, the last step was ineffective.
OS =
1.570794630102631
func(OS)
ans =
4.675807340707300e-09
I see, that makes sense! when you fun
func(OS)
thats still not zero. is that due to the step size? can i make the step size even smaller?
It has nothing to do with "step size". At some stage, you reach the limits of floating-point arithmetics. You could try to set TolFun and/or TolX in the options for "fsolve" to a smaller value, but I think that a residual of 5e-9 should suffice for your purposes, doesn't it ?
Be happy that the integrator does not grump because your function has a singularity at "OO" (you try to evaluate 1/sqrt(cos(OO)-cos(OO)) which gives 1/0).
The series expansion around 0, e.g., seems to indicate that your integral does not exist because int(1/x,0,1) = Inf.
syms x
f = 1/sqrt(1-cos(x));
simplify(series(f,x,'ExpansionPoint',0,'order',10))
ans = 
ah i see i see, thank you very much for your help!
So in short:
Forget the complete discussion. Your problem is ill-posed.

Sign in to comment.

Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

Asked:

on 11 Jul 2022

Commented:

on 12 Jul 2022

Community Treasure Hunt

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

Start Hunting!