## 12745 Reputation

8 years, 296 days

## straightforward...

I'd say that the solution is straightforward.

a*(x-m)+b*(y-n)=0 is a general equation of a line thru [m,n]; it can be normalized by a^2+b^2=1
and one may suppose f(0,0)>=0 (because f=0 and -f=0 produce the same line).

The distance from (0,0) to the line is exactly |f(0,0)|/sqrt(a^2+b^2) = f(0,0). So, the tangency condition is just f(0,0)=r. That's all.

Happy New Year!

## exact...

Why not the exact solution?

sol1:=dsolve({ode,ics}):
plot(rhs(sol1),x=0..1);

## animate...

a:=5: b:=3:
F := proc(u)
plots[display](
plot([sqrt(a^2*cos(u)^2+b^2*sin(u)^2)+ a*cos(t)*cos(u)-b*sin(t)*sin(u),
sqrt(a^2*sin(u)^2+b^2*cos(u)^2)+ a*cos(t)*sin(u)+b*sin(t)*cos(u), t=0..2*Pi]),
plot([sqrt(a^2*cos(v)^2+b^2*sin(v)^2),sqrt(a^2*sin(v)^2+b^2*cos(v)^2),v=0..u],color=blue));
end proc:
plots[animate](F, [u], u = 0 .. Pi,  scaling = constrained );

## assuming...

Strangely, if you simply remove the assumptions in your sheet, it works.

## parabola directly...

To compute the (linear!) fit, you don't need the presence in memory of the vectors X,Y.
It is enugh to have X,Y in a text file (each line containing x_i, y_i)  and read it line by line, e.g.

f:="c:/temp/xy.txt";
A:=Vector(5);B:=Vector(3);
while line<>0 do
x,y:=op(sscanf(line,"%f%f"));
A := A + Vector([1,x,x^2,x^3,x^4]);
B := B + Vector([y,x*y,x^2*y]);
od:
p:= <A[1],A[2],A[3];A[2],A[3],A[4];A[3],A[4],A[5]>^(-1).B:
p[1]+p[2]*t+p[3]*t^2;  # the linear fit (parabola)

## subs...

You have in two places subs({r=x, s=t} instead of subs({x=r, t=s}.

Note that it is not a good idea to use exclusively ":" instead of ";". You will have no chance to debug the code.

## antiderivative...

Compute the antiderivative first.

J:=Int((4/3)*t^(3/2)/sqrt(x-t), t = 0 .. x);

int((4/3)*t^(3/2)/sqrt(x-t), t):
J = limit(%,t=x,left) - limit(%,t=0,right) assuming x>0;

Edit. Actually,

value(J) assuming x>0;

also works.

## b value...

It is obvious that b should not be allowed to be too large, otherwise the graph may become almost "dense" and will fit any data.

For example, DirectSearch ==>

DataFit(a*sin(b*x+c)+d, [b<=2,b>=0], Vector(X), Vector(Y), x, fitmethod = lms, strategy = globalsearch, method = quadratic);

gave

which seems resonable.

## arctan...

The arctan function seems to be not very "smart".

For example,

arctan( cos(t/2),sin(t/2)) assuming t>0,t<Pi/2;

simplifies to Pi/2 - t/2

but equivalent expressions

arctan( 1+cos(t),sin(t)) assuming t>0,t<Pi/2;

simplify(  arctan( 1+cos(2*t),sin(2*t))  ) assuming t>0,t<Pi/4;

do not.

In such circumstances I think that it would be better to use an inert variant; at least Maple will not try to simplify.

## coeffs...

roundcoeffs:=proc(p,x)  local t;
end:

p:=3.5*x^2+3.2*x-6.5+88.3*x*y-y^3+a*y:
roundcoeffs(p,[x,y]);

## evalf...

Use

f := unapply(evalf(x^2/(sin(x)+x+1)), x);

## NonlinearFit...

restart;
f:=(x,y)->evalf(2*x*Int(sqrt(1+y^2*(t*x-1)^2/(1-(t*x-1)^2)), t = 0 .. 1)):
m:=19;n:=9;
G:=Matrix(m*n,3,datatype=float);
k:=0;
for i to m  do   for j to n do
k:=k+1;
G[k,1]:=2*i/(m+1); G[k,2]:=j/(n+1); G[k,3]:=f(2*i/(m+1),j/(n+1))
od od:

f_fit:=a1*x*sqrt(1+y^2*((a2*x-a3)^2/(1-(a4*x-1)^2)));
Statistics[NonlinearFit](f_fit, G, [x, y], initialvalues = [a1 = 1, a2 = 0, a3 = 0, a4=1/2],
output = [leastsquaresfunction, residuals]);
f1:=unapply(%[1],x,y);

printf("x    y    f(x,y)    f_fit(x,y)  \n");
for x_ from 0.1 to 1.9 by 0.1 do
for y_ from 0.1 to 0.9 by 0.1 do
printf("%2.1f  %2.1f  %6f  %6f\n",x_,y_,f(x_,y_), f1(x_,y_)      );
od; od;

## example...

You may replace arcsin by wrongarcsin where:

wrongarcsin := x -> piecewise(x<0, arcsin(x)+2*Pi, arcsin(x));

## You may simply "cut" the polynomial, or ...

You may simply "cut" the polynomial, or use:

hor:= (f,x,i) -> numapprox[hornerform](select(u -> degree(u,x)<=i, f) ,x);

hor(f,x,3);

## rephrase...

Your notations are not clear (at least for me).

Given the function  g = f(r,theta)*r
you can integrate it in the domain

A = { (r,theta) :  a<= r <= b,  c(r) <= theta <= d(r)}

or

B = { (r,theta) :  a<= theta <= b,  c(theta) <= r <= d(theta)}.

In the A case, the integral is
int(int(g, theta=c(r)..d(r)), r = a..b);

and similarly for B.
The provided text passage does not contain any mathematical questions or calculations. It appears to be a series of comments or discussions about Maple code or mathematical concepts, but no specific question is asked or answered.
no_question
Given a text passage, determine:
    1. If it contains a mathematical question (including word problems or calculations)
    2. If an answer to that mathematical question is provided in the text

First, describe the content structure you found in 1-2 sentences.

Then provide your analysis in the following format:
TYPE: <one of the following values>
- NO_QUESTION
- SINGLE_QUESTION
- SINGLE_QUESTION_WITH_ANSWER
- MULTIPLE_QUESTIONS
- MULTIPLE_QUESTIONS_WITH_ANSWERS
system
## 12745 Reputation

8 years, 296 days

## straightforward...

I'd say that the solution is straightforward.

a*(x-m)+b*(y-n)=0 is a general equation of a line thru [m,n]; it can be normalized by a^2+b^2=1
and one may suppose f(0,0)>=0 (because f=0 and -f=0 produce the same line).

The distance from (0,0) to the line is exactly |f(0,0)|/sqrt(a^2+b^2) = f(0,0). So, the tangency condition is just f(0,0)=r. That's all.

Happy New Year!

## exact...

Why not the exact solution?

sol1:=dsolve({ode,ics}):
plot(rhs(sol1),x=0..1);

## animate...

a:=5: b:=3:
F := proc(u)
plots[display](
plot([sqrt(a^2*cos(u)^2+b^2*sin(u)^2)+ a*cos(t)*cos(u)-b*sin(t)*sin(u),
sqrt(a^2*sin(u)^2+b^2*cos(u)^2)+ a*cos(t)*sin(u)+b*sin(t)*cos(u), t=0..2*Pi]),
plot([sqrt(a^2*cos(v)^2+b^2*sin(v)^2),sqrt(a^2*sin(v)^2+b^2*cos(v)^2),v=0..u],color=blue));
end proc:
plots[animate](F, [u], u = 0 .. Pi,  scaling = constrained );

## assuming...

Strangely, if you simply remove the assumptions in your sheet, it works.

## parabola directly...

To compute the (linear!) fit, you don't need the presence in memory of the vectors X,Y.
It is enugh to have X,Y in a text file (each line containing x_i, y_i)  and read it line by line, e.g.

f:="c:/temp/xy.txt";
A:=Vector(5);B:=Vector(3);
while line<>0 do
x,y:=op(sscanf(line,"%f%f"));
A := A + Vector([1,x,x^2,x^3,x^4]);
B := B + Vector([y,x*y,x^2*y]);
od:
p:= <A[1],A[2],A[3];A[2],A[3],A[4];A[3],A[4],A[5]>^(-1).B:
p[1]+p[2]*t+p[3]*t^2;  # the linear fit (parabola)

## subs...

You have in two places subs({r=x, s=t} instead of subs({x=r, t=s}.

Note that it is not a good idea to use exclusively ":" instead of ";". You will have no chance to debug the code.

## antiderivative...

Compute the antiderivative first.

J:=Int((4/3)*t^(3/2)/sqrt(x-t), t = 0 .. x);

int((4/3)*t^(3/2)/sqrt(x-t), t):
J = limit(%,t=x,left) - limit(%,t=0,right) assuming x>0;

Edit. Actually,

value(J) assuming x>0;

also works.

## b value...

It is obvious that b should not be allowed to be too large, otherwise the graph may become almost "dense" and will fit any data.

For example, DirectSearch ==>

DataFit(a*sin(b*x+c)+d, [b<=2,b>=0], Vector(X), Vector(Y), x, fitmethod = lms, strategy = globalsearch, method = quadratic);

gave

which seems resonable.

## arctan...

The arctan function seems to be not very "smart".

For example,

arctan( cos(t/2),sin(t/2)) assuming t>0,t<Pi/2;

simplifies to Pi/2 - t/2

but equivalent expressions

arctan( 1+cos(t),sin(t)) assuming t>0,t<Pi/2;

simplify(  arctan( 1+cos(2*t),sin(2*t))  ) assuming t>0,t<Pi/4;

do not.

In such circumstances I think that it would be better to use an inert variant; at least Maple will not try to simplify.

## coeffs...

roundcoeffs:=proc(p,x)  local t;
end:

p:=3.5*x^2+3.2*x-6.5+88.3*x*y-y^3+a*y:
roundcoeffs(p,[x,y]);

## evalf...

Use

f := unapply(evalf(x^2/(sin(x)+x+1)), x);

## NonlinearFit...

restart;
f:=(x,y)->evalf(2*x*Int(sqrt(1+y^2*(t*x-1)^2/(1-(t*x-1)^2)), t = 0 .. 1)):
m:=19;n:=9;
G:=Matrix(m*n,3,datatype=float);
k:=0;
for i to m  do   for j to n do
k:=k+1;
G[k,1]:=2*i/(m+1); G[k,2]:=j/(n+1); G[k,3]:=f(2*i/(m+1),j/(n+1))
od od:

f_fit:=a1*x*sqrt(1+y^2*((a2*x-a3)^2/(1-(a4*x-1)^2)));
Statistics[NonlinearFit](f_fit, G, [x, y], initialvalues = [a1 = 1, a2 = 0, a3 = 0, a4=1/2],
output = [leastsquaresfunction, residuals]);
f1:=unapply(%[1],x,y);

printf("x    y    f(x,y)    f_fit(x,y)  \n");
for x_ from 0.1 to 1.9 by 0.1 do
for y_ from 0.1 to 0.9 by 0.1 do
printf("%2.1f  %2.1f  %6f  %6f\n",x_,y_,f(x_,y_), f1(x_,y_)      );
od; od;

## example...

You may replace arcsin by wrongarcsin where:

wrongarcsin := x -> piecewise(x<0, arcsin(x)+2*Pi, arcsin(x));

## You may simply "cut" the polynomial, or ...

You may simply "cut" the polynomial, or use:

hor:= (f,x,i) -> numapprox[hornerform](select(u -> degree(u,x)<=i, f) ,x);

hor(f,x,3);

## rephrase...

Your notations are not clear (at least for me).

Given the function  g = f(r,theta)*r
you can integrate it in the domain

A = { (r,theta) :  a<= r <= b,  c(r) <= theta <= d(r)}

or

B = { (r,theta) :  a<= theta <= b,  c(theta) <= r <= d(theta)}.

In the A case, the integral is
int(int(g, theta=c(r)..d(r)), r = a..b);

and similarly for B.
user
The provided text passage does not contain any mathematical questions or calculations. It appears to be a series of comments or discussions about Maple code or mathematical concepts, but no specific question is asked or answered.

TYPE: NO_QUESTION