[Error: Function definition not supported in this context. Create functions in code file

clc; clear;
% dy = zeros(2,1); % y(1) = y ; y(2) = dy
% y = y(1);
% dy(1) = y(2);
% dy(2) = t- 4*y(2)-4*y(1);
f = @(t,y) [y(2) ; t- 4*y(2)-4*y(1)];
%-----------------------------------------
% To slove the BVP by the shooting method.
x = 0.5;
x1 = fzero(F,x);
%-----------------------------------------
% The problem are here ! ! ! I have a problem that I have been thinking about for a long time and still can't solve.
% To slove the ODE by ode45.
function F = solver(x);
options = odeset ('RelTol', 1e-8, 'AbsTol',[1e-8, 1e-8]);
[t,y] = ode45(f, [0 1], [1 x], options);
F = y(length(t),1)-1;
end
%----------------------------------------
figure(1);
plot(t,y(:,1));

 Risposta accettata

To get past that particular error, move all the function definitions to the bottom of the script.
I've done this for the m-file script uploaded with the question, and the updated script is attached here.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by