Frage

I am using the following code to produce a numerical solution to a system of ODE's with 6 boundary conditions.

I am using the initial conditions to obtain a solution but I must vary three other conditions in order to find the true solution. The function I have is as follows:

function diff = prob5diff(M,Fx,Fy)

u0 = [pi/2 0 0]';
sSpan = [0 13];
p = @(t,u) prob5(t,u,M,Fx,Fy);
options = odeset('reltol',1e-6,'abstol',1e-6);
[s,u] = ode45(p,sSpan,u0,options);
L = length(s);
x = u(:,2); y = u(:,3); theta = u(:,1);

diff(1) = x(L) - 5;
diff(2) = y(L);
diff(3) = theta(L) + pi/2;
end

Ultimately, different values of M,Fx, and Fy will produce different solutions and I would like a solution such that the values in diff are as close to zero as possible so I want fsolve to iterate through different values of M,Fx, and Fy

I am receiving the following error: when I call it in this way:

opt = optimset('Display','iter','TolFun',1e-6);
guess = [1;1;1];
soln = fsolve(@prob5diff,guess,opt);

Error in line:
soln = fsolve(@prob5diff,guess,opt);

Caused by:
    Failure in initial user-supplied objective function evaluation. FSOLVE cannot      continue.

Thanks!

War es hilfreich?

Lösung

One problem is that you have to call fsolve on prob5diff which takes a single vector input since your guess is a single vector:

prob5diff(x)
    M = x(1);
    Fx = x(2);
    Fy = x(3);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top