Matlab Solving Muller Method
5 views (last 30 days)
Show older comments
Hi, I keep receiving an error and I can't figure out how to get around it.
function [v3]=ParachuteMuller(m0,m1,m2)
%2/11/2020 William D.
%MULLER'S METHOD: PROBLEM 7.11
ea=5;
es=1;
iter=1;
itermax=100;
g=9.81;
c=15;
v=35;
while es<ea && iter<itermax
f0=@(m0) (g*m0/c)*(1-e^(-c*t/m0))-v;
f1=@(m1) (g*m1/c)*(1-e^(-c*t/m1))-v;
f2=@(m2) (g*m2/c)*(1-e^(-c*t/m2))-v;
c=f2; %c value
h0=m1-m0; %h0 value
h1=m2-m1; %h1 value
delta0=(f1-f0)/(m1-m0); %delta0 calculated value
delta1=(f2-f1)/(m2-m1); %delta1 calculated value
a=(delta1-delta0)/(h1+h0); %calculated a value
b=a*h1+delta1; %calculated b value
if sign(b)==1 %for + value of b use +
m3=m2+(-2*c)/(b+sqrt(b^2-4*a*c));
elseif sign(b)==-1 %for - value b use -
m3=m2+(-2*c)/(b-sqrt(b^2-4*a*c));
end
if m3~=0
ea=abs((m3-m2)*100/m3); %calculated approx. error
end
m0=m1; %replace x0 with x1
m1=m2; %replace x1 with x2
m2=m3; %replace x2 with calculated x3 value
iter=iter+1; %increase iteration
end
%Nobody Cares, Work Harder
%Keep Hammering
end
ERROR MESSAGE:
Undefined operator '-' for input arguments of type 'function_handle'.
Error in ParachuteMuller (line 22)
delta0=(f1-f0)/(m1-m0); %delta0 calculated value
0 Comments
Accepted Answer
Steven Lord
on 12 Feb 2020
f0=@(m0) (g*m0/c)*(1-e^(-c*t/m0))-v;
Nowhere have you defined e. If you wanted to compute the exponential, instead just call the exp function.
f0 = @(m0) (g*m0/c)*(1-exp(-c*t/m0))-v;
f1=@(m1) (g*m1/c)*(1-e^(-c*t/m1))-v;
f2=@(m2) (g*m2/c)*(1-e^(-c*t/m2))-v;
c=f2; %c value
h0=m1-m0; %h0 value
h1=m2-m1; %h1 value
delta0=(f1-f0)/(m1-m0); %delta0 calculated value
You cannot add or subtract function handles like you're trying to do on the line that defines delta0. You can add or subtract the values you get by evaluating function handles, however.
delta0 = (f1(2)-f0(1))./(m1-m0)
That example subtracts the value of f0 evaluated at m0 = 1 from the value of f1 evaluated at m1 = 2.
0 Comments
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!