tomleslie

13876 Reputation

20 Badges

15 years, 164 days

MaplePrimes Activity


These are answers submitted by tomleslie

I have added an execution group which performs the iteration you require, but a few caveats are necessary

  1. This (probably?, almost certainly?) won't give the same answer as a call to fsolve(), since fsolve() may well use techniques other than iteration to obtain a solution
  2. You will  (probably?) get a different answer for more or less every initial point
  3. I have made tno attempt to restrict values to specific ranges - although that wouldn't be too difficult

So for what ti is worth -


 

``

restart

``

sys1 := {y[1] = 33/(100*sqrt(y[1])*y[3]^(3/2)*(33/(50*y[1]^(3/2)*y[3]^(3/2))+2/(5*y[2]^(3/2)*y[4]^(3/2))))+11/(40*sqrt(y[1])*y[3]^(3/2)*(11/(20*y[1]^(3/2)*y[3]^(3/2))+1/(2*y[2]^(3/2)*y[4]^(3/2))))+33*y[2]/(200*y[1]^(3/2)*y[3]^(3/2)*(11/(50*y[1]^(3/2)*y[3]^(3/2))+4/(5*y[2]^(3/2)*y[4]^(3/2))))+33*y[2]/(100*y[1]^(3/2)*y[3]^(3/2)*(11/(25*y[1]^(3/2)*y[3]^(3/2))+3/(5*y[2]^(3/2)*y[4]^(3/2)))), y[2] = 2*y[1]/(15*y[2]^(3/2)*y[4]^(3/2)*(33/(50*y[1]^(3/2)*y[3]^(3/2))+2/(5*y[2]^(3/2)*y[4]^(3/2))))+y[1]/(6*y[2]^(3/2)*y[4]^(3/2)*(11/(20*y[1]^(3/2)*y[3]^(3/2))+1/(2*y[2]^(3/2)*y[4]^(3/2))))+2/(5*sqrt(y[2])*y[4]^(3/2)*(11/(50*y[1]^(3/2)*y[3]^(3/2))+4/(5*y[2]^(3/2)*y[4]^(3/2))))+3/(10*sqrt(y[2])*y[4]^(3/2)*(11/(25*y[1]^(3/2)*y[3]^(3/2))+3/(5*y[2]^(3/2)*y[4]^(3/2))))}

{y[1] = (33/100)/(y[1]^(1/2)*y[3]^(3/2)*((33/50)/(y[1]^(3/2)*y[3]^(3/2))+(2/5)/(y[2]^(3/2)*y[4]^(3/2))))+(11/40)/(y[1]^(1/2)*y[3]^(3/2)*((11/20)/(y[1]^(3/2)*y[3]^(3/2))+(1/2)/(y[2]^(3/2)*y[4]^(3/2))))+(33/200)*y[2]/(y[1]^(3/2)*y[3]^(3/2)*((11/50)/(y[1]^(3/2)*y[3]^(3/2))+(4/5)/(y[2]^(3/2)*y[4]^(3/2))))+(33/100)*y[2]/(y[1]^(3/2)*y[3]^(3/2)*((11/25)/(y[1]^(3/2)*y[3]^(3/2))+(3/5)/(y[2]^(3/2)*y[4]^(3/2)))), y[2] = (2/15)*y[1]/(y[2]^(3/2)*y[4]^(3/2)*((33/50)/(y[1]^(3/2)*y[3]^(3/2))+(2/5)/(y[2]^(3/2)*y[4]^(3/2))))+(1/6)*y[1]/(y[2]^(3/2)*y[4]^(3/2)*((11/20)/(y[1]^(3/2)*y[3]^(3/2))+(1/2)/(y[2]^(3/2)*y[4]^(3/2))))+(2/5)/(y[2]^(1/2)*y[4]^(3/2)*((11/50)/(y[1]^(3/2)*y[3]^(3/2))+(4/5)/(y[2]^(3/2)*y[4]^(3/2))))+(3/10)/(y[2]^(1/2)*y[4]^(3/2)*((11/25)/(y[1]^(3/2)*y[3]^(3/2))+(3/5)/(y[2]^(3/2)*y[4]^(3/2))))}

(1)

sys2 := {y[3] = 1/(33/(50*y[1]^(3/2)*y[3]^(3/2))+2/(5*y[2]^(3/2)*y[4]^(3/2)))^(1/3), y[4] = 1/(11/(50*y[1]^(3/2)*y[3]^(3/2))+4/(5*y[2]^(3/2)*y[4]^(3/2)))^(1/3)}

{y[3] = 1/((33/50)/(y[1]^(3/2)*y[3]^(3/2))+(2/5)/(y[2]^(3/2)*y[4]^(3/2)))^(1/3), y[4] = 1/((11/50)/(y[1]^(3/2)*y[3]^(3/2))+(4/5)/(y[2]^(3/2)*y[4]^(3/2)))^(1/3)}

(2)

sys := `union`(sys1, sys2)

v := [indets(sys, name)[]]

[y[1], y[2], y[3], y[4]]

(3)

vz := `~`[subsop](0 = z, v)

[z[1], z[2], z[3], z[4]]

(4)

# Replace y's with z's (taken to a power of 2) to translate the system into a polynomial form (to get rid of the square roots and facilitate the computation):

sysP := (`@`(`~`[numer], simplify))(subs(`~`[`=`](v, `~`[`^`](vz, 2)), `~`[lhs-rhs](sys)), symbolic)

{-z[3]*(50^(1/3)*z[1]*z[2]*z[4]-(20*z[1]^3*z[3]^3+33*z[2]^3*z[4]^3)^(1/3)*z[3]), -z[4]*(50^(1/3)*z[1]*z[2]*z[3]-(40*z[1]^3*z[3]^3+11*z[2]^3*z[4]^3)^(1/3)*z[4]), -480000*z[1]^14*z[3]^12-1144000*z[1]^11*z[2]^3*z[3]^9*z[4]^3+363000*z[1]^9*z[2]^5*z[3]^9*z[4]^3-762300*z[1]^8*z[2]^6*z[3]^6*z[4]^6+1143450*z[1]^6*z[2]^8*z[3]^6*z[4]^6-133100*z[1]^5*z[2]^9*z[3]^3*z[4]^9+1058145*z[1]^3*z[2]^11*z[3]^3*z[4]^9+263538*z[2]^14*z[4]^12, 480000*z[1]^14*z[3]^12+1144000*z[1]^11*z[2]^3*z[3]^9*z[4]^3-363000*z[1]^9*z[2]^5*z[3]^9*z[4]^3+762300*z[1]^8*z[2]^6*z[3]^6*z[4]^6-1143450*z[1]^6*z[2]^8*z[3]^6*z[4]^6+133100*z[1]^5*z[2]^9*z[3]^3*z[4]^9-1058145*z[1]^3*z[2]^11*z[3]^3*z[4]^9-263538*z[2]^14*z[4]^12}

(5)

NULL

fsolve(sysP, `~`[`=`]({vz[]}, 1 .. infinity))

{z[1] = 1.076207559, z[2] = 1.052719262, z[3] = 1.047573288, z[4] = 1.050128957}

(6)

# These are the final values of the 4 unknowns, which should be matched with an iterative process (i.e., transfer z's back to y's):

solve(subs({z[1] = 1.076207559, z[2] = 1.052719262, z[3] = 1.047573288, z[4] = 1.050128957}, subs(`~`[`=`](vz, `~`[`^`](v, 1/2)))), {y[1], y[2], y[3], y[4]})

{y[1] = 1.158222710, y[2] = 1.108217845, y[3] = 1.097409794, y[4] = 1.102770826}

(7)

# I'm not sure whether it's of any importance for the solution, but I noticed that the values vary if I start from a different initial point (here 1.01 instead of 1):                           

fsolve(sysP, `~`[`=`]({vz[]}, 1.01 .. infinity))

{z[1] = 1.092072175, z[2] = 1.068237633, z[3] = 1.063015801, z[4] = 1.065609143}

(8)

solve(subs({z[1] = 1.092072175, z[2] = 1.068237633, z[3] = 1.063015801, z[4] = 1.065609143}, subs(`~`[`=`](vz, `~`[`^`](v, 1/2)))), {y[1], y[2], y[3], y[4]})

{y[1] = 1.192621635, y[2] = 1.141131641, y[3] = 1.130002593, y[4] = 1.135522846}

(9)

# However, the solution is the same up-to-scale:

ratio_y1 = 1.192621635/(1.158222710), ratio_y2 = 1.141131641/(1.108217845), ratio_y3 = 1.130002593/(1.097409794), ratio_y4 = 1.135522846/(1.102770826)

ratio_y1 = 1.029699750, ratio_y2 = 1.029699753, ratio_y3 = 1.029699752, ratio_y4 = 1.029699752

(10)

fsolve(sysP)

{z[1] = -1.212997331, z[2] = 1.186523590, z[3] = -1.180723544, z[4] = 1.183604047}

(11)

 

#
# Limit the number of iterations (just in
# case the required tolerance cannot be achieved
#
  numIters:= 100:
#
# Supply a starting point
#
  initialGuess:= [1, 1, 1, 1]:
#
# Specify a tolerance for termination
#
  breakTol:= 1.0e-06:
#
# Convert the original 'sys' to a list
#
  sysL:= rhs~(convert(sys, list)):
#
# Initialize an array to hold the results
#
  vals:= Array(1..numIters, 1..4, [[ y__1, y__2, y__3, y__4], initialGuess]):
#
# Run the iteration
#
  for j from 3 by 1 to numIters do
      vals[j, 1..4]:= Array( evalf( eval( sysL, [ seq( y[k]=vals[j-1,k], k=1..4 )])));
    #
    # If required tolerance has been achieved, then
    # exit loop 9using root mean square)
    #
      if   sqrt(add((vals[j,..]-~vals[j-1,..])^~2)/4) < breakTol
      then break
      fi;
  od:
#
# Display final result
#
  vals[j,..];
#
# Display error - actually the discrpancy between
# the last two iterates, and the rms error
#
  vals[j,..]-~vals[j-1,..];
  sqrt(add((vals[j,..]-~vals[j-1,..])^~2)/4);
#
# Display all values of the iteration
#
  interface(rtablesize=j):
  vals[1..j, 1..4];
  interface(rtablesize=10):

Vector[row](4, {(1) = 1.026593850, (2) = .9822707691, (3) = .9726913817, (4) = .9774433589})

 

Vector[row](4, {(1) = 0.1521e-5, (2) = -0.10139e-5, (3) = -0.2474000000e-6, (4) = 0.2227000000e-6})

 

9.290097228*10^(-7)

 

Array(%id = 36893488148333066228)

(12)

 

NULL


 

Download iterEQ.mw

is shown in the attached figure, produced by Maple.

Calculating the coordinates of the relevant points iin this figure took much less code than actually producing the figure itself!

is shown in the attached - where pretty much everything is defined in matrix form

  restart;
#
# Matrix of dependent variables
#
  X:= Matrix( 2,1, [x__1(t), x__2(t)]);
#
# "Coefficient" matrix
#
  Mcoeff:= Matrix(2,2, [[1, -1], [12,-8]]);
#
# "Scalar addition" matrix
#
  b:=Matrix(2,1, [-3,4]);
#
# Define ode system in terms of above matrices
#
  ode:= diff(X,t) = Mcoeff.X + b;
#
# Solve ode system
#
  dsolve(ode);

Vector(2, {(1) = `#msub(mi("x"),mi("1"))`(t), (2) = `#msub(mi("x"),mi("2"))`(t)})

 

Matrix(2, 2, {(1, 1) = 1, (1, 2) = -1, (2, 1) = 12, (2, 2) = -8})

 

Vector(2, {(1) = -3, (2) = 4})

 

Matrix(%id = 36893488148078258884) = Matrix(%id = 36893488148078259124)

 

{x__1(t) = exp((1/2)*(-7+33^(1/2))*t)*_C2+exp(-(1/2)*(7+33^(1/2))*t)*_C1-7, x__2(t) = -(1/2)*exp((1/2)*(-7+33^(1/2))*t)*_C2*33^(1/2)+(1/2)*exp(-(1/2)*(7+33^(1/2))*t)*_C1*33^(1/2)+(9/2)*exp((1/2)*(-7+33^(1/2))*t)*_C2+(9/2)*exp(-(1/2)*(7+33^(1/2))*t)*_C1-10}

(1)

 


Download matode2.mw

In future please upload your worksheet using the big green up-arrow in the Mapleprimes toolbar - very few (if any!) people here are prepared to retype your code,

If I run your "simple" example in Maple 2021, then all three integrals "work". See the attached

  restart:
  interface(version);
  

`Standard Worksheet Interface, Maple 2021.0, Windows 7, March 5 2021 Build ID 1523359`

(1)

  R:= 7.5;
  f:= z->z;
  a:= [1,2,3,4,5];
  b:= [2,1,1,2,4];
  g:= z-> CurveFitting:-Spline(a, b, z, degree=1);

7.5

 

proc (z) options operator, arrow; z end proc

 

[1, 2, 3, 4, 5]

 

[2, 1, 1, 2, 4]

 

proc (z) options operator, arrow; CurveFitting:-Spline(a, b, z, degree = 1) end proc

(2)

#
# Example 1
#
  Int( Int( Int( arctan(f(r)),r=RR..R)/RR, RR), RR=0..R);
  evala(value(%));
#
# Example 2
#
  Int( Int( Int( g(r),r=RR..R)/RR, RR), RR=0..R);
  evala(value(%));
#
# Example 3
#
  Int( Int( Int( g(r)+arctan(f(r)),r=RR..R)/RR, RR), RR=0..R);
  evala(value(%));

Int(Int((Int(arctan(r), r = RR .. 7.5))/RR, RR), RR = 0 .. 7.5)

 

47.55857943

 

Int(Int((Int(piecewise(r < 2, 3-r, r < 3, 1, r < 4, -2+r, -6+2*r), r = RR .. 7.5))/RR, RR), RR = 0 .. 7.5)

 

135.0979765

 

Int(Int((Int(piecewise(r < 2, 3-r, r < 3, 1, r < 4, -2+r, -6+2*r)+arctan(r), r = RR .. 7.5))/RR, RR), RR = 0 .. 7.5)

 

-1165.637136

(3)

 

 


Download intProb.mw

 

 

However if I run the same worksheet in Maple 2020, I get an *interesting* error which you don't seem to experience, see the attached

  restart:
  interface(version);
  

`Standard Worksheet Interface, Maple 2020.2, Windows 7, November 11 2020 Build ID 1502365`

(1)

  R:= 7.5;
  f:= z->z;
  a:= [1,2,3,4,5];
  b:= [2,1,1,2,4];
  g:= z-> CurveFitting:-Spline(a, b, z, degree=1);

7.5

 

proc (z) options operator, arrow; z end proc

 

[1, 2, 3, 4, 5]

 

[2, 1, 1, 2, 4]

 

proc (z) options operator, arrow; CurveFitting:-Spline(a, b, z, degree = 1) end proc

(2)

#
# Example 1
#
  Int( Int( Int( arctan(f(r)),r=RR..R)/RR, RR), RR=0..R);
  evala(value(%));
#
# Example 2
#
  Int( Int( Int( g(r),r=RR..R)/RR, RR), RR=0..R);
  evala(value(%));
#
# Example 3
#
  Int( Int( Int( g(r)+arctan(f(r)),r=RR..R)/RR, RR), RR=0..R);
  evala(value(%));

Int(Int((Int(arctan(r), r = RR .. 7.5))/RR, RR), RR = 0 .. 7.5)

 

47.55857943

 

Int(Int((Int(piecewise(r < 2, 3-r, r < 3, 1, r < 4, -2+r, -6+2*r), r = RR .. 7.5))/RR, RR), RR = 0 .. 7.5)

 

135.0979765

 

Int(Int((Int(piecewise(r < 2, 3-r, r < 3, 1, r < 4, -2+r, -6+2*r)+arctan(r), r = RR .. 7.5))/RR, RR), RR = 0 .. 7.5)

 

Error, (in Handlers:-hasPiecewise) mismatched multiple assignment of 2 variables on the left side and 1 value on the right side

 

 

 

Download intProb2020.mw

Some are shown in the attached (but there are others!)

  restart;
  JointNum:= 3:
  alpha:= table( [seq(j=0, j=1..JointNum)]):
#
# test
#
  alpha[1];
  alpha[2];
  alpha[3];

0

 

0

 

0

(1)

  restart;
  JointNum := 3:
  seq( (alpha[j]:=0), j=1..JointNum):
#
# test
#
  alpha[1];
  alpha[2];
  alpha[3];

0

 

0

 

0

(2)

  restart;
  JointNum:= 3:
  seq( assign(alpha[j], 0), j=1..JointNum):
#
# test
#
  alpha[1];
  alpha[2];
  alpha[3];

0

 

0

 

0

(3)

  restart;
  JointNum:= 3:
  alpha:= Array(1..3, fill=0):
#
# test
#
  alpha[1];
  alpha[2];
  alpha[3];

0

 

0

 

0

(4)

 

 

Download assgn.mw

 

See the help page ?@.

Basically (sin@cos)(x) is the same as sin(cos(x)), because '@' is the function composition operator

So in the example you quote

 restart;
  expr:=u[1,1]*u[2,3]+u[1,1,2];
  (`[]`@ op)~(indets(expr, indexed));

the "composite" function  (`[]`@ op) is applied elementwise to the entries in (indets(expr, indexed))

the attached perhaps?

  A:= u[1,2]+u[2]*u[1,1,1];
  LT:= (expr, term)-> select(has, expr, term);
  LT(A, u[1,1,1]);
  LT(A, u[2]);
  LT(A, u[1,2]);

u[2]*u[1, 1, 1]+u[1, 2]

 

proc (expr, term) options operator, arrow; select(has, expr, term) end proc

 

u[2]*u[1, 1, 1]

 

u[2]*u[1, 1, 1]

 

u[1, 2]

(1)

 

Download selTerm.mw

k>0, when either x<20 or x>100.

See the attached


 

  restart;
  gamma__1:= 2:
  k:=gamma__1*(100-x)/100-x*0.05*(gamma__1*(100-x)/100):
#
# Ensure that 'M' is only defined when k>0
#
  M:= 41539.42878*piecewise( k>0,
                             0.010+0.0001*((k+2*gamma__1)/2)^2,
                             undefined
                           ):
#
# Observation, k>0 when x<20 or x>100
#
  plot(k, x=-200..200);
  plot( abs(M), x=-200..200);

 

 

 

 

 

 


 

Download pwplot.mw

the attached?

  restart;
  RA:= rtable(1 .. 5, 1 .. 5):

  ik:= 1:

  s:= proc()
           global ik, RA;
           RA[ik, 1]:= 1;
           ik:= ik + 1;
           RA[ik, 2]:= 2;
           ik:= ik + 1;
      end proc:

  t:= proc()
           global ik, RA;
           RA[ik, 3]:= 3;
           ik:= ik + 1;
           RA[ik, 4]:= 4;
           ik:= ik + 1;
       end proc:

  s():
  t():
  RA;
  ik;

Matrix(5, 5, {(1, 1) = 1, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (1, 5) = 0, (2, 1) = 0, (2, 2) = 2, (2, 3) = 0, (2, 4) = 0, (2, 5) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 3, (3, 4) = 0, (3, 5) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 4, (4, 5) = 0, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = 0, (5, 5) = 0})

 

5

(1)

 


 

Download globtab.mw

like the attached?


 

  restart;
  expr:=u[1,1]*u[2,3]+u[1,1,2];
  (`[]`@ op)~(indets(expr, indexed));

u[1, 1]*u[2, 3]+u[1, 1, 2]

 

{[1, 1], [2, 3], [1, 1, 2]}

(1)

 


 

Download getInd.mw

I think what you *meant* is in the attached - although I could be wrong because (as well as syntax issues) you have some execution groups which appear a bit *redundant*

  restart;
  with(geometry):
  with(plots):
  local O:
  _EnvHorizontalName := x: _EnvVerticalName := y:

  alias(coor = coordinates):
  ell := x^2/a^2+y^2/b^2 = 1:
  point(P1,a*cos(omega), b*sin(omega)):
  point(P2,a*cos(omega-(1/2)*Pi), b*sin(omega-(1/2)*Pi)):
  point(P3,a*cos(omega+(8/7)*Pi), b*sin(omega+(8/7)*Pi)):
  point(P4,a*cos(omega+5*Pi*(1/2)), b*sin(omega+5*Pi*(1/2))):
  a := 5: b := 3: omega := (1/5)*Pi:
  Ell := implicitplot(ell, x = -a .. a, y = -b .. b, color = red):
  dr := draw([seq(P || k, k = 1 .. 4)], axes = normal, printtext = true):

  for i from 1 to 4 do
      tgP||i := x*coor(P||i)[1]/a^2+y*coor(P||i)[2]/b^2 = 1
  od:
  poly := Matrix([coor(P1), coor(P2), coor(P3), coor(P4)]):
  Quadri := polygonplot(poly, axes = normal, color = "DarkGreen", transparency = .8):

  with(combinat): with(ListTools):
  L := [1, 2, 3, 4]:
#
# following for loop seems a bit redundant??
# Comment out for now
#
#  for i from 1 to 4 do
#      Rotate(L, i)[1]
#  od:

#
# Fix syntax in this loop
#
  for i to 4 do
      solve({tgP || (Rotate(L, i)[1]), tgP || i});
      point(S || i, subs(%, x), subs(%, y));
      coor(S || i)
  end do:

#
# Following code repeats what above 'for' loop
# does?? Why have it. Comment out for now
#

#  solve({tgP1, tgP2}, {x, y}):
#  point(S1, subs(%, x), subs(%, y)):
#  coor(S1):
#  solve({tgP2, tgP3}, {x, y}):
#  point(S2, subs(%, x), subs(%, y)):
#  coor(S2):
#  solve({tgP3, tgP4}, {x, y}):
#  point(S3, subs(%, x), subs(%, y)):
#  coor(S3):
#  solve({tgP1, tgP4}, {x, y}):
#  point(S4, subs(%, x), subs(%, y)):
#  coor(S4):
  
  poly:= Matrix([coor(S1), coor(S2), coor(S3), coor(S4)]):
  Quadri2:= polygonplot(poly, axes = normal, color = "DarkGreen", transparency = .9):
  #dr2:= draw(seq(S||k,k =1..4), axes = normal, printtext = true):
  line(diag13, [S1, S3]):
  line(diag24, [S2, S4]):
  midpoint(M1, S1, S3):
  midpoint(M2, S4, S2):
  line(Lm, [M1, M2]):

  dr2 := draw( [S1, S2, S3, S4, M1, M2, Lm(color = black), diag13, diag24],
               axes = normal,
               printtext = true
             ):

  for i from 1 to 4 do
      TgP||i := implicitplot( tgP||i,
                              x = -a-5 .. a+5,
                              y = -b-5 .. b+5,
                              color = blue
                            )
  od:

  display( [Ell, seq(TgP||i,i=1..4), Quadri, Quadri2, dr, dr2],
           view = [-a-5 .. a+3, -b-2 .. b+2],
           scaling = constrained,
           size = [700, 700]
         );
  
 

 

 


 

Download ellplt.mw

Provided that the "equation" in the Excel spreadsheet resolves to a value, then the value is imported to Maple.

So what kind of "equation" are we talking about? Please upload (using the big green up-arrow in the Mapleprimes toolbar) an Excel worksheet which demonstrate so that I can reproduce your issue

a few typos, I get the attached with a"toy" example.

It is not clear (to me) whether you want to return the Array() 'a', or the expression 'F', so the attached returns both

  restart;
  Chebyshev_approx:= proc(f::procedure, N::numeric)
                          local F:=0, a:= Array(0..N), n;
                          for n from 0 to N do
                              if   n=0
                              then a[n]:=1/Pi*evalf( Int(1/sqrt(1-x^2)*f(x), x=-1..1) );
                              else a[n]:=2/Pi*evalf( Int(1/sqrt(1-x^2)*f(x)*ChebyshevT(n , x), x=-1..1) );
                              fi;
                              F:=F+a[n]*ChebyshevT(n, x);
                          od;
                          return eval(a), F;
                    end proc:
  A, F:=Chebyshev_approx( x->sin(x), 6):
  A;
  F;

`Array(0..6, {(1) = 0., (2) = .8801011710, (3) = 0., (4) = -0.3912670796e-1, (5) = 0., (6) = 0.4995154604e-3})`

 

.8801011710*ChebyshevT(1, x)-0.3912670796e-1*ChebyshevT(3, x)+0.4995154604e-3*ChebyshevT(5, x)

(1)

 

Download cheby.mw

I tried a variety of possibilities (Import, importData, ImportMatrix etc) and none did exactly what you want.

It is reasonably simple to write a small procedure whic will do what you want - although I don't really think this should be necessary. I hope someone can come up with a "simpler" way

See the attached

  restart:
  fName:="C:/Users/TomLeslie/Desktop/data.txt":

  myRead:= proc( myFile )
                 local j:=1,
                       l,
                       line;
                 while true do
                       line:=readline( myFile );
                       if   line <> 0
                       then l[j]:=[parse(line)];
                            j:=j+1;
                       else break;
                       fi;
                od:
                return Matrix([entries(l, 'nolist')])
         end proc:

   M:=myRead( fName)

Matrix(3, 4, {(1, 1) = 1, (1, 2) = 2, (1, 3) = "0", (1, 4) = 4, (2, 1) = 1, (2, 2) = 2, (2, 3) = "1", (2, 4) = 4, (3, 1) = 1, (3, 2) = 2, (3, 3) = "A", (3, 4) = 4})

(1)

 


 

Download fread.mw

 precisely what the problem is??

Maybe something in the attached will cover your issue

   restart:

  b1:=1.41:d:=0.5/1:xi:=0.1:ea:=0.5:ra:=2:

  L:= unapply
      ( piecewise
        ( d<=z,
          1-2*xi*(cos((2*3.14)*((z-d)*(1/2))-1/4)-(7/100)*cos((32*3.14)*(z-d-1/2))),
          z<=d+1,
          1-2*xi*(cos((2*3.14)*((z-d)*(1/2))-1/4)-(7/100)*cos((32*3.14)*(z-d-1/2))),
          1
        ),
        z
      );
#
# OP seems interested in L(0.71) - not sure why
#
  L(0.71);
#
# OP also seems interested in the value of z fo
# which L(z)=1 (again not sure why)
#
  ans:=fsolve( L(z)=1,z);

L := proc (z) options operator, arrow; piecewise(.5 <= z, 1+(-1)*.2*cos(3.140000000*z-1.820000000)+0.1400000000e-1*cos(100.48*z-100.4800000), z <= 1.5, 1+(-1)*.2*cos(3.140000000*z-1.820000000)+0.1400000000e-1*cos(100.48*z-100.4800000), 1) end proc

 

.8074456472

 

1.099093517

(1)

#
# Define PDE and boundary/initial conditions
#
  PDE1 :=ra*(diff(f(x,t),t))=+b1*(1+ea*cos(t))+(1/(L(z)^2))*((diff(f(x,t),x,x))+(1/x)*diff(f(x,t),x));
  IBC := { D[1](f)(0,t)=0, f(1,t)=0, f(x,0)=0 };
  

PDE1 := 2*(diff(f(x, t), t)) = 1.41+.705*cos(t)+(diff(f(x, t), x, x)+(diff(f(x, t), x))/x)/piecewise(.5 <= z, 1-.2*cos(3.140000000*z-1.820000000)+0.1400000000e-1*cos(100.48*z-100.4800000), z <= 1.5, 1-.2*cos(3.140000000*z-1.820000000)+0.1400000000e-1*cos(100.48*z-100.4800000), 1)^2

 

{f(1, t) = 0, f(x, 0) = 0, (D[1](f))(0, t) = 0}

(2)

#
# Solve the PDE for z=0.71 and obtain the value of 'f'
# at x=0.71, t=1.12
#
  sol:=pdsolve( eval( PDE1,
                      z = 0.71
                    ),
                IBC,
                numeric
              );
  sol:-value( f(x,t))(0.71, 1.12 );
#
# Idle curiosity plot f(x,t) as a function of x, t.
#
  sol:-plot3d( f(x,t), x=0..1, t=0..10);

_m649558432

 

[x = .71, t = 1.12, f(x, t) = .146679035917915479]

 

 

#
# Solve the PDE for L(z)=1 and obtain the value of 'f'
# at x=0.71, t=1.12
#
  sol:=pdsolve( eval( PDE1,
                      z = fsolve( L(z)=1 )
                    ),
                IBC,
                numeric
              );
  sol:-value(f(x,t))(0.71, 1.12);
#
# Idle curiosity plot f(x,t) as a function of x, t.
#
  sol:-plot3d( f(x,t), x=0..1, t=0..10);

_m709776896

 

[x = .71, t = 1.12, f(x, t) = .222598684892558074]

 

 

 


 

Download pdeSols.mw

First 47 48 49 50 51 52 53 Last Page 49 of 207