Self-Created function won't work anymore

4 次查看(过去 30 天)
Why won't my function work anymore after closing matlab? I had created a function, it was working fine, then I closed the program and reopened it later, tried to use the same function and got this error:
"Execution of script Fermat as a function is not supported:
D:\Documents\School Assignments\Res - Spring Semester
(2023)\MATH307\Assignments\Fermat.mlx"
It is in the directory that is set as the one I'm in, so I know that's not the issue. Just in case it's needed this is the code of my function.
"function [a,b] = Fermat(n)
%Fermat function: Performs Fermat Factorization
% This code takes the input (n) and uses it to calculate the starting
% step value for s, which is the first of the two squares subtracted to
% create the input value of n.
% It then runs the input into a loop that calculates by step s values
% until the difference between the square root of s^2-n and the integer
% value smaller than that value is zero, meaning that it is itself an
% integer.
% Once the value of s is determined it then outputs the two factors of
% n by taking s and t (the two squares) and adding and subtracting
% them.
s=ceil(sqrt(n));
i=1;
while i>0||i<0
s=s+1;
arg=sqrt(s^2-n);
i=arg-floor(arg);
end
s;
t=sqrt(s^2-n);
a=(s-t);
b=(s+t);"

回答(1 个)

Cassie Thompson
Cassie Thompson 2023-2-27
I think I figured it out, I had a live script by the same name in the same directory and I think that confused matlab when I went to call it.

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by