Prev: pop up a selection window
Next: designing of high temperature superconducting power cable using matlab
From: Mario Fatafehi on 26 Mar 2010 03:25 I am having great difficulty with trying to plot a piecewise function. I am not allowed to use piecewise_eval etc but rather with a control loop etc. I have already spend one week playing around with for loop, while loop, if elseif etc but I am still getting error.Can someone please help me? The problem is this. Plot x(t) = t-1 for -1=<t<=1, x(t) =0 otherwise. Plot for -2=<t<=2. Use a resolution of 0.1 time units. I am completely lost and can't work out the right way to approach the problem. Thanks.
From: Wayne King on 26 Mar 2010 04:56 "Mario Fatafehi" <coruba9(a)hotmail.com> wrote in message <hohnhf$a4s$1(a)fred.mathworks.com>... > I am having great difficulty with trying to plot a piecewise function. I am not allowed to use piecewise_eval etc but rather with a control loop etc. I have already spend one week playing around with for loop, while loop, if elseif etc but I am still getting error.Can someone please help me? The problem is this. Plot x(t) = t-1 for -1=<t<=1, x(t) =0 otherwise. Plot for -2=<t<=2. Use a resolution of 0.1 time units. I am completely lost and can't work out the right way to approach the problem. Thanks. Hi Mario, Are you reading the MATLAB documentation? If you are spending a week on this type of problem, then it seems like you would benefit greatly from reading the documentation. It shows you how to do these types of things with examples. Also, the problem you had with leaving off semicolons is clearly explained in the documentation. I think your homework assignments will go much better if you work through the Getting Started Guide. I'm not going to give you the answer to your homework outright, but there are a number of ways to do this: 1.) Create a time vector from [-2,2] in increments of 0.1. You will find out how to do this easily by reading the documentation. 2.) Create an x vector of zeros equal in size to your time vector. 3.) Identify those elements of the time vector that correspond to [-1,1]. 4.) Use the indices you obtained in step 3 and fill those elements of the x vector with x(t)=t-1
From: Mario Fatafehi on 26 Mar 2010 05:47 "Wayne King" <wmkingty(a)gmail.com> wrote in message <hohsr2$su9$1(a)fred.mathworks.com>... > "Mario Fatafehi" <coruba9(a)hotmail.com> wrote in message <hohnhf$a4s$1(a)fred.mathworks.com>... > > I am having great difficulty with trying to plot a piecewise function. I am not allowed to use piecewise_eval etc but rather with a control loop etc. I have already spend one week playing around with for loop, while loop, if elseif etc but I am still getting error.Can someone please help me? The problem is this. Plot x(t) = t-1 for -1=<t<=1, x(t) =0 otherwise. Plot for -2=<t<=2. Use a resolution of 0.1 time units. I am completely lost and can't work out the right way to approach the problem. Thanks. > > Hi Mario, Are you reading the MATLAB documentation? If you are spending a week on this type of problem, then it seems like you would benefit greatly from reading the documentation. It shows you how to do these types of things with examples. Also, the problem you had with leaving off semicolons is clearly explained in the documentation. I think your homework assignments will go much better if you work through the Getting Started Guide. I'm not going to give you the answer to your homework outright, but there are a number of ways to do this: > > 1.) Create a time vector from [-2,2] in increments of 0.1. You will find out how to do this easily by reading the documentation. > 2.) Create an x vector of zeros equal in size to your time vector. > 3.) Identify those elements of the time vector that correspond to [-1,1]. > 4.) Use the indices you obtained in step 3 and fill those elements of the x vector with x(t)=t-1 I have done this t=-2:0.1:2 x=zeros(1,41) t1=t.*(t<=1) t2=t.*(-1<=t) Can you tell me how to implement step 3 and 4?
From: Wayne King on 26 Mar 2010 06:18 "Mario Fatafehi" <coruba9(a)hotmail.com> wrote in message <hohvqm$j26$1(a)fred.mathworks.com>... > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hohsr2$su9$1(a)fred.mathworks.com>... > > "Mario Fatafehi" <coruba9(a)hotmail.com> wrote in message <hohnhf$a4s$1(a)fred.mathworks.com>... > > > I am having great difficulty with trying to plot a piecewise function. I am not allowed to use piecewise_eval etc but rather with a control loop etc. I have already spend one week playing around with for loop, while loop, if elseif etc but I am still getting error.Can someone please help me? The problem is this. Plot x(t) = t-1 for -1=<t<=1, x(t) =0 otherwise. Plot for -2=<t<=2. Use a resolution of 0.1 time units. I am completely lost and can't work out the right way to approach the problem. Thanks. > > > > Hi Mario, Are you reading the MATLAB documentation? If you are spending a week on this type of problem, then it seems like you would benefit greatly from reading the documentation. It shows you how to do these types of things with examples. Also, the problem you had with leaving off semicolons is clearly explained in the documentation. I think your homework assignments will go much better if you work through the Getting Started Guide. I'm not going to give you the answer to your homework outright, but there are a number of ways to do this: > > > > 1.) Create a time vector from [-2,2] in increments of 0.1. You will find out how to do this easily by reading the documentation. > > 2.) Create an x vector of zeros equal in size to your time vector. > > 3.) Identify those elements of the time vector that correspond to [-1,1]. > > 4.) Use the indices you obtained in step 3 and fill those elements of the x vector with x(t)=t-1 > > > I have done this > t=-2:0.1:2 > x=zeros(1,41) > t1=t.*(t<=1) > t2=t.*(-1<=t) > Can you tell me how to implement step 3 and 4? Think about how you can identify indices in your t vector that lie between [-1,1] t = -2:0.1:2; so each element of t increments by 0.1. How many elements will there be starting from -2 and going in increments of 0.1 before you find t(N1) = -1 Then ask yourself how many more elements before you find t(N2) = 1. Now you have your range of indices that you need to fill in your x vector.
From: Mario Fatafehi on 26 Mar 2010 06:45 "Wayne King" <wmkingty(a)gmail.com> wrote in message <hoi1kq$hes$1(a)fred.mathworks.com>... > "Mario Fatafehi" <coruba9(a)hotmail.com> wrote in message <hohvqm$j26$1(a)fred.mathworks.com>... > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hohsr2$su9$1(a)fred.mathworks.com>... > > > "Mario Fatafehi" <coruba9(a)hotmail.com> wrote in message <hohnhf$a4s$1(a)fred.mathworks.com>... > > > > I am having great difficulty with trying to plot a piecewise function. I am not allowed to use piecewise_eval etc but rather with a control loop etc. I have already spend one week playing around with for loop, while loop, if elseif etc but I am still getting error.Can someone please help me? The problem is this. Plot x(t) = t-1 for -1=<t<=1, x(t) =0 otherwise. Plot for -2=<t<=2. Use a resolution of 0.1 time units. I am completely lost and can't work out the right way to approach the problem. Thanks. > > > > > > Hi Mario, Are you reading the MATLAB documentation? If you are spending a week on this type of problem, then it seems like you would benefit greatly from reading the documentation. It shows you how to do these types of things with examples. Also, the problem you had with leaving off semicolons is clearly explained in the documentation. I think your homework assignments will go much better if you work through the Getting Started Guide. I'm not going to give you the answer to your homework outright, but there are a number of ways to do this: > > > > > > 1.) Create a time vector from [-2,2] in increments of 0.1. You will find out how to do this easily by reading the documentation. > > > 2.) Create an x vector of zeros equal in size to your time vector. > > > 3.) Identify those elements of the time vector that correspond to [-1,1]. > > > 4.) Use the indices you obtained in step 3 and fill those elements of the x vector with x(t)=t-1 > > > > > > I have done this > > t=-2:0.1:2 > > x=zeros(1,41) > > t1=t.*(t<=1) > > t2=t.*(-1<=t) > > Can you tell me how to implement step 3 and 4? > > Think about how you can identify indices in your t vector that lie between [-1,1] > > t = -2:0.1:2; > > so each element of t increments by 0.1. How many elements will there be starting from -2 and going in increments of 0.1 before you find t(N1) = -1 Then ask yourself how many more elements before you find t(N2) = 1. Now you have your range of indices that you need to fill in your x vector. I have no idea of what you are on about? I think you have make the problem more complicated now than before?
|
Next
|
Last
Pages: 1 2 Prev: pop up a selection window Next: designing of high temperature superconducting power cable using matlab |