I have to write a program which will calculate using false position method the maximum of a given equation. And at the end I need to return the root and a value of the function at that point. I am not getting the answer can anyone help? )
6 次查看(过去 30 天)
显示 更早的评论
%The root should be equal to 225, at least thats what i got when i did same question using bisection method
function [ xr ] = false_position( f,g, xl, xu )
w=1.75;
E=5*10.^5;
I=3*10.^5;
L=450;
g=@(x)(w/(120*E*I*L))*(-x.^5+2*L.^2*x.^3-L.^4*x);%orignal
f=@(x)(w/(120*E*I*L))*(-5*x.^4+6*L.^2*x.^2-L.^4);%derivative
xl=0;
xu=L;
if f(xl)*f(xu)>0
disp('error wrong end points')
else
xr=(xl*f(xu)-xu*f(xl))/(f(xu)-f(xl));
error=abs(f(xr));
while error>1e-4;
if f(xr)>0
xu=xr;
else
xl=xr;
end
xr=(xl*f(xu)-xu*f(xl))/(f(xu)-f(xl));
error=abs(f(xr));
end
fprintf('The point of maximum deflection is: %f\n', xr);
fprintf('The value of maximum deflection is: %f\n',g(xr));
end*
2 个评论
James Tursa
2018-3-29
Do not post screen shots of code. We can't copy & paste screen shots into MATLAB to run. Please remove your screen shot and replace it with text of your code (and use the { } Code button to format your code as well).
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!