Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
Trying to create a matrix by programming, where the diagonal should be 1 and 0 otherwise. I even get the same result if I replace if-else to define every element 1. This does not make any sense to me. I assume there is an easy solution, but I was unable to find a solution by searching.
Solved! Go to Solution.
Hi,
Try this:-
You can use programming as you have tried or the identity() inbuilt function.
Mathcad arrays start at index 0 unless you set ORIGIN=1.
Hi,
Try this:-
You can use programming as you have tried or the identity() inbuilt function.
Mathcad arrays start at index 0 unless you set ORIGIN=1.
Thank you! Very useful.
In this specific case, where you only want array elements other than 0 on the diagonal, your program can be much simpler:
This makes use of the fact that all array elements are assigned the value 0 by default. The variable ORIGIN is used to make the array creation independent of the actual value of ORIGIN.
But of course, as Terry pointed out, for an identity matrix, you should better use the built-in identity function:
Success!
Luc