Self-Created function won't work anymore

4 Ansichten (letzte 30 Tage)
Cassie Thompson
Cassie Thompson am 27 Feb. 2023
Beantwortet: Cassie Thompson am 27 Feb. 2023
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);"

Antworten (1)

Cassie Thompson
Cassie Thompson am 27 Feb. 2023
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.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by