Getting an error while solving fractional differential equation using Physics-informed Neural Network
Show older comments
When I run the code below, I get the error
Not enough input arguments.
Error in solve_caputo_fractional (line 28)
t_points = linspace(0, T, 100);
I'm not sure how to fix this error because I'm not familiar with the concept of "physics-informed neural network." Any help is greatly appreciated. Thank you very much.
% solve_caputo_fractional.m
function solve_caputo_fractional(alpha, T)
% Parameters
hidden_layers = 3;
neurons_per_layer = 50;
layers = [
featureInputLayer(1, 'Name', 'input')
];
for i = 1:hidden_layers
layers = [
layers
fullyConnectedLayer(neurons_per_layer, 'Name', ['fc_' num2str(i)])
reluLayer('Name', ['relu_' num2str(i)])
];
end
layers = [
layers
fullyConnectedLayer(1, 'Name', 'output')
];
% Create the neural network
net = layerGraph(layers);
% Define the loss function
t_points = linspace(0, T, 100);
u_predicted = predict(net, t_points');
loss_eqn_fn = @(t_val, u_val) ...
(1/gamma(1-alpha)) * trapz(t_points, (u_val - interp1(t_points, u_val, t_points - t_val)) ./ (t_points - t_val).^alpha) + u_val;
loss_function = @(u_predicted) sum(arrayfun(@(i) loss_eqn_fn(t_points(i), u_predicted(i))^2, 1:length(t_points)));
% Training the PINN
options = trainingOptions('adam', ...
'MaxIterations', 10000, ...
'MiniBatchSize', 32, ...
'GradientThreshold', 1, ...
'InitialLearnRate', 0.001, ...
'LearnRateSchedule', 'piecewise', ...
'LearnRateDropFactor', 0.5, ...
'LearnRateDropPeriod', 1000, ...
'Verbose', true, ...
'Plots', 'training-progress');
[net, trainingInfo] = trainNetwork(net, t_points', ones(length(t_points), 1), options);
% Plot the Results
u_predicted = predict(net, t_points');
figure;
plot(t_points, u_predicted, 'b', 'LineWidth', 2);
xlabel('t');
ylabel('u(t)');
title('Predicted Solution');
grid on;
end
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Toolbox 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!