-3
$\begingroup$

I wrote a code in MATLAB that solves parabolic equation of two space (heat equation:$u_t = u_{xx} + u_{yy}$ )with ADI (Alternating direction implicit) method (finite difference method).

Now in order to test my code for initial function I want to write a function with two variables that is like "M" ,I mean that in $x-y$ points of "M" it's $z = 1$ and in the other points $z = 0$! I don't have any idea that how I can write this. suppose $x$ is in $[a,b]$ and $y$ is in $[c,d]$.

$\endgroup$
4
  • $\begingroup$ What do you mean by there is no limit on x and y ? You add then that x is in [a,b] and y in [c,d] so x and y are bounded... You could try to define your function as a piecewise-defined function for which you choose the limit of your intervals in order to describe each part of your 'M'... $\endgroup$ – Coriolis May 29 '16 at 7:48
  • $\begingroup$ you are right !I meant $x \in [a,b],y \in [c,d]$ $\endgroup$ – haleh May 29 '16 at 8:58
  • 1
    $\begingroup$ It was difficult for me to be sure what you wanted, so I made an educated guess. Consider rephrasing the question, especially if I am off the mark. $\endgroup$ – Carl Christian May 29 '16 at 18:46
  • 1
    $\begingroup$ Perhaps the function imread might be helpful here? $\endgroup$ – Kirill May 30 '16 at 2:36
1
$\begingroup$

Not a function, but as Kirill said in the comments, you could use imread.

You could convert a 100*100 pixel image of an M into a 100-by-100 matrix with something like

M_bmp = imread('M.bmp') ;
M = 1 - double(M_bmp(:,:,1))/255;

which will pull out the red channel of the bitmap file and scale it to 1.

$\endgroup$
0
$\begingroup$

I suppose that the simplest thing for you to do is to draw your $M$ on a piece of quadrille paper, i.e. paper with pre-printed squares. Embed your $M$ inside a square $S$ of a suitable size, say, 20 by 20 squares. The square $S$ will correspond to your box, i.e. $[a,b] \times [c,d]$. Do not bother with too much detail, but fill out each of the 400 small sub squares as needed to get a nice $M$. Create a table with $T$ with 400 entries and let $T(k)=1$ if an only if cell $k$ is part of your $M$ and $T(k)=0$ otherwise.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.