I have questions in a maple worksheet like this
q1 := Quiz("Find f'(x). f(x) = $P/x^2+ $T", 3,
proc () local p, t, temp, tg, answer;
p := (rand(0 .. 100))();
temp := (rand(1 .. 2))();
tg := [sin(x), cos(x)];
t := tg[temp];
Quiz:-Set(`$P` = p);
Quiz:-Set(`$T` = t);
answer := diff(p/x^2, x)+diff(t, x);
[diff(nextprime(p)/x^2, x)+t, diff(p/x, x), answer]
end proc,
style = multiplechoice, output = mapleta)
To export them, I use the following code
with(MapleTA);
currentdir("/path");
MapleTA:-Export([q1], "ques.zip");
When I try to import them on the mapleTA site, I get the following error,
Errors loading the question bank, ques.zip : Reason: Error at line 1. Line ended while reading variable name (missing "=" at end of name?)
That exported zip file from Maple is a Course Module in Maple T.A.
The error you report usually occurs when you try importing a Course Module as a Question Bank in Maple T.A.
To fix this, go to the Question Repository in Maple T.A. and click on Course Modules > Import. Then choose the zip file you got from Maple.
Related
I am working on some Numerical Analysis with Maple as a part of my course and I am not sure where my error is with the code I am using.. If anyone can point out my flaw It would be very much appreciated as I seem to be getting the answer wrong.
f(x)=sqrt((cosh(x))^2 + 1) - sinh(x).
Find a good approximation to f(4.86) using a 6-digit arithmetic.
Then, Use 20 digit arithmetic to calculate the relative error.
Finally, round it to 6 (significant) digits
f := sqrt(cosh(x)^2+1)-sinh(x);
f1 := evalf[6](f(4.86));
f1 := 0.0155
f2 := evalf(f(4.86));
f2 := 0.01550004
Digits := 20;
Digits := 20
Q4 := abs((f2-f1)/f2);
Q4 := 0.0000025806385015780604437
Digits := 6;
Digits := 6
evalf[6](Q4);
0.00000258064
Thanks everyone
You've made one syntax transcription mistake, and one Maple programming mistake.
Your first line is
f := sqrt(cosh(x)^2+1)-sinh(x);
but you subsequently call it like an operator (procedure), eg. f(4.86) and obtain a numeric value. Therefore you must have originally used something like this procedure, instead.
f := x -> sqrt(cosh(x)^2+1)-sinh(x);
So that was likely just a transcription error when posting here.
You have made a programming mistake, in computing
f2 := evalf(f(4.86));
before setting the working-precision environment variable Digits to 20. Thus you have computed f2 at only the default Digits=10 working precision. But from the wording of the question it seems that you are being asked to compute f2 also at 20 digits of working precision.
Your code might be revised as follows:
restart;
f := x -> sqrt(cosh(x)^2+1)-sinh(x):
f1 := evalf[6](f(4.86));
f1 := 0.0155
Digits := 20:
f2 := evalf(f(4.86));
f2 := 0.015500036806894590
Q4 := abs((f2-f1)/f2);
Q4 := 0.0000023746327217512077767
evalf[6](Q4);
0.00000237463
You have used two different mechanisms for specifying the working precision. You could have also done it (slightly more consistently in methodology) as follows:
restart;
f := x -> sqrt(cosh(x)^2+1)-sinh(x):
f1 := evalf[6]( f(4.86) );
f1 := 0.0155
f2 := evalf[20](f(4.86));
f2 := 0.015500036806894590
rel := evalf[20]( abs((f2-f1)/f2) );
rel := 0.0000023746327217512077767
evalf[6]( rel );
0.00000237463
There's always the possibility that I have misunderstood the question. What is the desired answer?
I get the following error trying to solve a non linear system in Octave:
error: #Jfun: no function and no method found
error: called from
voc at line 4 column 13
I'm using 4 scripts and I couldn't find the source of the error. The ffun, jfun and newtonsys files have been tested before and I am almost sure the issue is not there (I don't know if it could be an issue with the naming of variables though), but I have included them all below just in case.
file voc.m
x0=[9;8;0.5];
tol=10^-3;
nmax=1000;
[z,res,niter]=newtonsys(#Ffun,#Jfun,x0,tol,nmax)
File Ffun.m
q=1.602E-19;
k=1.381E-23;
Ncs=12;
Tc=329.25;
gamma=1.35;
Isc=9.14;
Rsh=94.5;
Vmp=37.8;
Imp=8.74;
function F=Ffun(x)
F(1,1)=Isc+x(2)*[exp((q*Isc*x(3))/(gamma*k*Tc*Ncs))-1]-(Isc*x(3))/Rsh-x(1);
F(2,1)=x(2)*[exp(q*(Voc)/(gamma*k*Tc*Ncs))-1]+(Voc/Rsh)-x(1);
F(3,1)=Imp+x(2)*[exp(q*(Vmp+Imp*x(3))/(gamma*k*Tc*Ncs))-1]+(Vmp+(Imp*x(3)))/Rsh-x(1);
endfunction
File JFun.m
q=1.602E-19;
k=1.381E-23;
Ncs=12;
Tc=329.25;
gamma=1.35;
Isc=9.14;
Rsh=94.5;
Vmp=37.8;
Imp=8.74;
function J=Jfun(x)
J(1,1)=-1;
J(1,2)=exp((q*Isc*x(3))/(gamma*k*Tc*Ncs))-1;
J(1,3)=x(2)*[exp((q*Isc*x(3))/(gamma*k*Tc*Ncs))]*(q*Isc/(gamma*k*Tc*Ncs))-(Isc/Rsh);
J(2,1)=-1;
J(2,2)=exp(q*(Voc)/(gamma*k*Tc*Ncs))-1;
J(2,3)=0;
J(3,1)=-1;
J(3,2)=exp(q*(Vmp+Imp*x(3))/(gamma*k*Tc*Ncs))-1;
J(3,3)=x(2)*[exp(q*(Vmp+Imp*x(3))/(gamma*k*Tc*Ncs))]*(q*Imp/(gamma*k*Tc*Ncs))+(Imp/Rsh);
endfunction
file newtonsys.m
function [x,res,niter] = newtonsys(Ffun,Jfun,x0,tol,...
nmax, varargin)
niter = 0;
err = tol + 1;
x = x0;
while err >= tol & niter < nmax
J = Jfun(x,varargin{:});
F = Ffun(x,varargin{:});
delta = - J\F;
x = x + delta;
err = norm(delta);
niter = niter + 1;
end
res = norm(Ffun(x,varargin{:}));
if (niter==nmax & err> tol)
fprintf(['Il metodo non converge nel massimo ',...
'numero di iterazioni. L''ultima iterata\n',...
'calcolata ha residuo relativo pari a %e\n'],F);
else
fprintf(['Il metodo converge in %i iterazioni',...
' con un residuo pari a %e\n'],niter,F);
end
return
The problem is your JFun.m file is NOT a function file, it is a script file which happens to define an 'on-the-spot' function JFun within it. If the voc.m script happens to call that function before it has been defined (i.e. before the JFun.m script has had a chance to be run and therefore end up defining that function in the current environment) then it will complain it's not there.
The solution in your case is to move all those variable definitions inside the function block, making it a proper 'function file', which will then be accessible from voc (as long as it's on the same directory / in the octave path).
Alternatively, if you still prefer JFun.m to be a script, (e.g. maybe you do want all those variables to end up being defined at global scope), then simply make sure you run it as a script first, such that it first defines the function you need; however, in that case, it is a good idea to change the name of your script to something else, so that its name doesn't conflict with the on-the-spot function defined inside it.
Have a quick look at the respective section in the manual, and in particular this part.
I keep receiving error,';' unexpected in this piece of maple code. I have looked and looked and just can't seem to find where I'm going wrong. Can anyone spot it?
QSFactorization := proc (n::(And(posint, odd)), mult::nonnegint := 0, { mindeps::posint := 5, c := 1.5 })
local mfb, m, x, fb, nfb, r, M, d;
if isprime(n) then
return "(n)"
elif issqr(n) then
return "(isqrt(n))"*"(isqrt(n))"
elif n < 1000000 then
return ifactor(n)
end if;
if mult = 0 then
mfb := MultSelect(n, ':-c' = c)
else mfb := [mult, FactorBase(mult*n, c)]
end if;
m := mfb[1];
if 1 < m then
print('Using*multiplier; -1');
print(m)
end if;
x := m*n*print('Using*smoothness*bound; -1');
print(ceil(evalf(c*sqrt(exp(sqrt(ln(n)*ln(ln(n))))))));
fb := Array(mfb[2], datatype = integer[4]);
nfb := ArrayNumElems(fb);
print('Size*of*factor*base; -1');
print(nfb);
r := Relations(x, fb, ':-mindeps' = mindeps);
M := r[3]; print('Smooth*values*found; -1');
print(nfb+mindeps);
print('Solving*a*matrix*of*size; -1');
print(LinearAlgebra:-Dimension(M));
d := Dependencies(M);
print('Number*of*linear*dependencies*found; -1');
print(nops(d));
print('Factors; -1');
FindFactors(n, r, d)
end proc
I'd really appreciate any insight.
You basic problem is that you are using the wrong quotes inside your print statements. This is invalid,
print('Using*multiplier; -1');
You are using single right-quotes (tick), which in Maple is used for unevaluation. In this case the semicolons inside your print statements are syntax errors.
Use either double-quotes or single left-quotes instead. The former delimits a string, and the latter delimits a name. Eg,
print("Using*multiplier; -1");
print(`Using*multiplier; -1`);
If you choose to go with name-quotes then the print command will prettyprint the output in the Maple GUI with the name in an italic font by default, but you won't see the quotes in the output.
If you choose to go with string-quotes then the print command will show the quotes in the output, but will use an upright roman font by default.
Some other comments/answers (since deleted) on your post suggest that you are missing statement terminators (colon or semicolon) for these two statements,
print(m)
FindFactors(n, r, d)
That is not true. Those statements appear right before end if and end proc respectively, and as such statement terminators are optional for them. Personally I dislike coding Maple with such optional terminator instances left out, as it can lead to confusion when you add intermediate lines or pass the code to someone else, etc.
I am trying to perform a quick fix for a client. We have a report field that shows tolerance values in strings like +/-20 , -19 +18. This is in micrometer and the client wants it in millimeter. So i need to divide only the numeric part of this string by 1000 and display the result.
I am relatively new to crystal reports, with my limited knowledge and from searching this site for suggestions, i created a function with the following code lines,
Function (stringvar x)
local stringvar array input := split(x,"+/-");
val(input[ubound(input)])/1000
The above function works perfectly for tolerance values of +/-. However i am not able to figure out a way to do it for '-19 +18'. I would like to have the result as -0.019 +0.018
I can easily do it in the database source and send it to the report. However the client needs a quick fix of just the report. Any help would be greatly appreciated.
try this
if(Left (x, 3 )="+/-")
then ToNumber(split(x ,"+/-")[2])/100
else if(Left ({x , 1 )="+")
then ToNumber(split(x ,"+")[2])/100
else if(Left (x , 1 )="-")
then ToNumber(split(x ,"-")[2])/100
I figured out an answer which would work for this specific case.
I used the following conditions in a formula field. Based on the condition I called a User defined function 'Tolerance','Tolerance2', 'Tolerance3'.
Formula field:
IF (Left ({PDPRINTDATA.PD_T45}, 3 )="+/-") THEN
'+/-' + ToText(Tolerance({PDPRINTDATA.PD_T45}),3)
ELSE IF (Left ({PDPRINTDATA.PD_T45} , 1 )="-") THEN
'-' + ToText(Tolerance2({PDPRINTDATA.PD_T45}),3) + ' +' + ToText(Tolerance3({PDPRINTDATA.PD_T45}),3)
Tolerance:
Function (stringvar x)
local stringvar array input := split(x,"+/-");
val(input[ubound(input)])/1000;
Tolerance2:
Function (stringvar x) local stringvar mystr := x;
If NumericText (mystr[2 to 3]) Then
ToNumber(mystr[2 to 3])/1000
Else 0
Tolerance3:
Function (stringvar x)
local stringvar mystr := x;
If NumericText (mystr[7 to 8]) Then
ToNumber(mystr[7 to 8])/1000
Else
0
This solution works for me considering the fact that the string will always be of this format '+/-XX' or '-XX +YY'.
I'm trying to use Newton's method to approximate where the gradient of a function = 0 But I'm guessing error messages when I try to put in guesses for an iteration of Newton's, and I don't know what the problem is.
(For reference, Profit = 144TVa - 0.07TVb TVb - 0.01 TVa^2 + 174TVb -0.01TVb^2 - 4E5)
with(LinearAlgebra):
with(VectorCalculus):
DProfit := Gradient(Profit, [TVa, TVb])
F := unapply(DProfit, TVa, TVb)
J := Jacobian(DProfit)
Guess := V->evalf(V-Multiply(Jinv,F(V))):
But when I try to evaluate Guess at any points, it gives me an error:
Guess(3000,3000)
Error, (in Guess) invalid input: F uses a 2nd argument, TVb, which is missing
Guess(<3000,3000>
Error, (in Guess) invalid input: F uses a 2nd argument, TVb, which is missing
even though F(3000,3000) returns [-66,-36]
Thanks for the help.
Figured out how to fix it!
Instead of:
Guess := V->evalf(V-Multiply(Jinv,F(V))):
I did:
Guess := V->evalf(V-Multiply(Jinv,F(V[1],V[2]))):