MATLAB: How can write this in matlab

fittingregression

I want to make one M-file that finds a function P(x)=A*e^M*x, which can approximate a function that is given in tabular shape.

Best Answer

Assuming that ‘A’ and ‘M’ are matrices, and that ‘x’ is a vector:
function Z = P(A, M, x)
for k1 = 1:length(x)
P(:,:,k1) = A*expm(M*x(k1)); % Anonymous Function
end
end
Call it as:
N = 3; % Matrix Size
A = rand(N); % Create Random Matrix To Test Code

M = rand(N); % Create Random Matrix To Test Code
x = linspace(0, 1, 10); % Create ‘x’ Vector
Z = P(A, M, x); % Z = A*expm(M*x)