Question: Use If to define a function that, given a list of numbers, doubles all the positive numbers but leaves the negative numbers unchanged. Rewrite abs


Use If to define a function that, given a list of numbers, doubles all the positive numbers but leaves the negative numbers unchanged.

In[3]:= abs[3+4 1] Greater Equal::nord: Invalid comparison with 3+ 4 i attempted.

Rewrite abs to include a specific rule for the case where its argument is complex.

The definition of the absolute value function in this section does not handle complex numbers well:

One of the fastest methods for computing Fibonacci numbers (Section 5.3) involves iterating multiplication of the matrix {{0, 1}, {1, 1}} and pulling off the appropriate part. For example, the last element in the output of mat 9 is the tenth Fibonacci number.

>> Less::nord: Invalid comparison with 3+ 4 i attempted. >> Out [3]=

Without using MatrixPower, create a function FibMat[n] that iterates the matrix multiplication and then pulls off the correct element from the resulting matrix to give the nth Fibonacci number. Check the speed of your implementation against both MatrixPower and the built-in Fibonacci.

In[3]:= abs[3+4 1] Greater Equal::nord: Invalid comparison with 3+ 4 i attempted. >> Less::nord: Invalid comparison with 3+ 4 i attempted. >> Out [3]= abs [3+ 4 il

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

QUESTION Use If to define a function that given a list of numbers doubles all the positive numbers b... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!