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

1 次查看(过去 30 天)
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));

采纳的回答

Voss
Voss 2022-5-28
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by