Items tagged with code code Tagged Items Feed

Hi everyone, I have been trying to plot the Taylor Polynomial approximation with the following code. However, my maple crushes everytime I run it. I indexed some of the variables to get the plot. The code works fine without the index. What did I do wrong?

y := array(1 .. 2);

Digits := 10;

n := 30;

h := .1;

T := 0;

X := 1; 

f := (x, t) -> 1/(3*x(t)-t-2); 

one := 1/(3*x(t)-t-2);

two := diff(f(x, t), t);

first := diff(x(t), t)

 

for k to n do

y[1] := subs(t = T(k), x(T(k)) = X(k), one);

y[2] := subs(first = y[1], t = T, x(T(k)) = X(k), two);

X[k+1] := X+sum(y[i]*h^i/factorial(i), i = 1 .. 2);

T[k+1] := T+h

end do;

X[n];

data := [seq([T[n], X[n]], n = 0 .. 30)];

p[2] := plot(data, style = point, color = blue);

p[3] := plot(data, style = line, color = blue);
display(p[2],  p[3])


 

The code without Index (which works fine)

y := array(1 .. 2);

Digits := 10;

n := 30;

h := .1;

T := 1;

X := .1547196278;

f := (x, t) -> 1/(3*x(t)-t-2); 

one := x(t)^4*e^t-(1/3)*x(t);

two := diff(f(x, t), t);

first := diff(x(t), t);

for k to n do

y[1] := subs(t = T, x(T) = X, one);

y[2] := subs(first = y[1], t = T, x(T) = X, two);

X := X+sum(y[i]*h^i/factorial(i), i = 1 .. 2);

T := T+h

end do

I am trying to recreate journal work for validating using another computer program so I am trying to use maple to solve the ODE, based on further research I found using laplace might be the best but I am having some trouble.

 

eq8:=d*(n(t)+C(t))/drho = -rho(t)/(l*alpha*K_c)

given the initial conditions of:

ICs:= n(0) = n_0, rho(0) = rho_0, C(0) = (beta-rho_0)*n_0/(l*lambda)

therefore: 

equation9 := dsolve({equation8, ICs}, {C(t), n(t)}, method = laplace)

 

Following this process I get the error: 

Error, (in dsolve) invalid initial condition

 

According to the journal work the solution I am looking for is: 

C(t)=-n(t)+(rho_0^2+rho(t)^2)/(2*l*alpha*K_c)+((Beta+l*lambda-rho_0)*n_0)/(l*lambda)

 

is there something that I'm doing wrong or missing? 

Any help would be greatly Appreciated! 

 

Dear all:

hello everybody;

I need your help to solve the system f(x,y)=0, and g(x,y)=0, such that there some parameter in the system, also all the parameter are positive and also our unkowns  x and y are also positive.

I try to write this code. I feel that under some condition we can have four solution or three or two. I need your help. Many thinks.

 

Systemsolve.mw

Please I need someone to help out with how to solve the below ODE numerically using finite difference method with the necessary maple code:

 

█( S〗_h〗^' (t)=Λ_h-αβ_m I_v S_h-μ_h S_h+πI_m,  

〖I_m〗^' (t)=αβ_m I_v S_h-(σ_m+π+μ_h ) I_m

〖 S〗_v〗^' (t)=Λ_v-αβ_v I_m S_v-μ_v S_v

〖I_v〗^' (t)=αβ_v I_m S_v-μ_v I_v )

The initial conditions can be assumed. Suppose i want to include controls, how do I solve the problem and equally plot the graph.

 

Thank you.

ADENIYI MICHAEL

 

This is pretty similar to my last question. but I found this maple code on a website that is suppose to find a vertex coloring of a graph G. The output is is supposed to be a list for example like [3, table([y = 1, k = 2, c = 2, m = 3, h = 1, x = 1] where the first part (in this case 3) is the number of colors and 1,2,3 in the second part are the colors to which each vertex is assigned.  However, no matter what graph I run this on I get everything equal to 1. such as [1, table([y = 1, k = 1, c = 1, m = 1, h = 1, x = 1])]. Why is this happening?  
color:=proc(G)
  local i, j, C, U, V, total_used;
  V:=Vertices(G); total_used:=1;
  C[V[1]]:=1;
  for i from 2 to nops(V) do
    C[V[i]]:=0;
  end do;
  for i from 2 to nops(V) do
    U:={};
      for j from 1 to nops(neighbors(V[i], G)) do
      U:=U union C[neighbors(V[i], G)[j]];
       end do;
    j:=1;
    while member(j, U) do
      j:=j+1;
     end do;
    C[V[i]]:=j;
    if j>total_used then
      total_used:=j;
    end if;
   end do;
  [total_used, eval(C)];
end:

I'm brand new to Maple and was assigned a problem to modify a code provided by my professor to incorporate variable window size. However, I don't know where to begin or what I'm doing. I've attached the link to the problem below. Plz help.  NA1_Project_IDW_01.2014_Fall.pdf

Cause CodeTools:-Test will not eval the paramater:

```
f := x -> x+1;

y := 2;

CodeTools:-Test( f(1), 2); # this will work as normal

CodeTools:-Test( f(1), y); # this will not work because `y` will not eval as 2

```

So current my solution is

```
test := subs(y=2, () -> CodeTools:-Test( f(1), y));

test();

```

 

I don't know is there any more proper solution for this.

More general, is there a way to force evaluate an `uneval` parameter?

 



This is my code for the Extended Euclidean Algorthim which should return integer l, polynomials pi,ri,si,ti for 0<=i<=l+1. And polynomial qi for 1<=i<=l such that si(f)+ti(g) = ri and sl(f)+tl(g)=rl=GCD(f,g).
The problem is, I keep getting division by zero. Also it evaluates pi = lcoeff(ri-1 - qiri) to be zero, everytime. Even when I remove this it still says there is a division of zero, which must be coming from qi:=quo(ri-1,ri, x); however I do not know why considering the requirements for the loop are that r[i] not equal zero. I really could use a fresh pair of eyes to see what I've done wrong. Any help would be greatly appreciated!!

So this is the errorcode I get and my code is

> r := (x1, y1, x2, y2) options operator, arrow; (sqrt((x2-x1)^2+(y2-y1)^2))^2
> hreg := (A, C, x) options operator, arrow; A*x+C
> hpconf := (Q, x1, y1, x2, y2) options operator, arrow; Q*(1/4)*ln(2.25*b*K*t/(S*r(x1, y1, x2, y2)))/(3.14*K*b)


> he1 := (x, y, C) options operator, arrow; hreg(A1, C, x)+hpconf(Q1, x, y, xp1, yp1)+hpconf(Q2, x, y, xp2, yp2)+hpconf(Q3, x, y, xp3, yp3)+hpconf(Q4, x, y, xp4, yp4)
> C1 := solve(he1(-75, 0, C) = 20, C);


> plot3d(he1(x, y, C1), x = -75 .. 75, y = -75 .. 75, style = surfacecontour, axes = box);

I have defined all the constants, and squareboxes shouldn't be needed for the plot, right?

 

test.mw

can someone please look at this modified C.Love code, hopefully the problem i'm having is self explanatary.

Hi all.  I have researched into this problem.  But I could not find a solution to this.

Here is an example.

I have a set of independent variables, say there are 5 of them.  They are 1. Gender 2. Age group 3. Full or part time 4. First language.

I have a set of dependent variables.  Let us consider for an example 6 of them.  They are (i) Develops breast cancer (ii) Develops skin cancer (iii) Develops lung cancer (iv) develops prostate cancer (v) Lives till 50 (vi) Lives till 60 ...

How do I perform the following prediction:

(A) If a person is male and above 50, what are the chances that he is likely to develop prostate cancer?

(B) If a person is female and works part time, what are the chances that she is likely to develop breast cancer and lives till 60?

I need to develop a code and formula to do this?  Can someone please advise?

Many thanks.

Kind regards,

Kris

 

 

 

E     Average
number
Fermi-
Dirac
 0      1.8
 1      1.6
 2      1.2
 3      0.8
 4      0.4
 5      0.2
 6      0
 7      0
 8      0
 9      0

 

E=0   f(E)=1.8  = 1/A+1    A=-0.444    kt is unknown. Hence I try many numbers.

This is my code

plot(1/(-0.444*exp(x/3)+1),x=0..9);

 

I have a problem.  A is negative. The denominator would be zero.

This is the theory.

http://hyperphysics.phy-astr.gsu.edu/hbase/quantum/disfdx.html#c2

I want to write a code but it is too lengthy. I want to do each part of the code in a separate ".mw" file. For example consider the two files "Part1.mw" and "Part2.mw". The "Part2.mw" have specific entries that must be given by "Part1.mw". How should I do this? or in other words How should I link these two files?

I don't want all variables in "Part1.mw" to be passed to "Part2.mw" but just specific variables that are needed.

Hi all

I have written the following code in maple to approximate arbitrary functions by hybrid of block-pulse and bernstein functions but it doesn't work properly especially for f(t)=1.0, so what is the matter?

bb1.mws

 


best wishes

Mahmood   Dadkhah

Ph.D Candidate

Applied Mathematics Department

One would expect that hitting F3 will split from _end_ of the current line (where the cursor is at).

But what Maple does is actually split everything from the current cursor location. Which means if the cursor happened not to be exactly at the end of the line, the current line itself will also be split and broken.

It is much more logical to split starting from end of current _line_ (where the cursor is at), not current character, because that is what normally one would want to do. One will have large block of code, and want to split it from one line down to the end.  It is a simple usability issue, which Maple UI seems to suffer allot from.

Is there a way to modify this behavior? I keep hitting F3 and forget to move the cursor to the end of the line before, and end up wasting time having to fix things afterwords since the line itself is split.

 

 

1 2 3 4 5 6 7 Last Page 1 of 13