All pastes #742005 Raw Edit

jdahm

public text v1 · immutable
·published 2007-10-19 04:09 UTC
rendered paste body
function file: func.m:


function f=func(t,y)
k=0.01;
L=1;
global h;
f = (k.*y.*(L-y)-h.*(sin(pi.*t)).^2);

script file:


t0=0;tf=1;

tol=input('Enter tolerance: ');
hstart=input('Enter H start: ');
hend=input('Enter H end: ');
step=input('Enter step size: ');
i=0;
out=zeros(1,3);
example=[h,difference,y(1)];
disp(example);
for C=hstart:step:hend
  sol=ode45(@func,[t0 tf],0.5);
  sxint=deval(sol,tf);
  b=[C,diff,sxint];
  diff=abs(0.5-sxint);
  if diff < tol,i=i+1; out(i,:)=b; end;
end;
disp(out);

Currently it is not liking something with the h.  I want to vary the h in the for loop but it keeps the same h every time.  I have tried also making this a handle, but I cant pass h as a parameter in the function in ode45().