Problem Creating a Function

1 view (last 30 days)
Nuno
Nuno on 19 Jun 2013
Hello comunity! I'm trying to create this function, but the problem is that i can't input the straight lines parallel in a period of time! for example y=0.1 between 0 and 0.625 seconds and x=0 between 1 and 0.1 p.u..
Thank you! =)
  2 Comments
Jan
Jan on 19 Jun 2013
What does "create this function" exactly mean? Do you want to draw a diagram or create a function, which replies the specific y-value for a provided x-value?
Nuno
Nuno on 20 Jun 2013
I want to create a function wich replies the specific y-value for a provided x-value and i could sampling .

Sign in to comment.

Answers (1)

Roger Stafford
Roger Stafford on 19 Jun 2013
Strictly speaking, you cannot define a (single-valued) function that does what you depict, since it is undefined at t = 0. It is necessary to express your "curve" parametrically. Devise some kind of parameter that changes monotonically throughout the curve's path. For example, define parameter s as advancing just as t does except at t = 0 where we defined s as changing from 0 to 1 while t remains constant at 0. You can easily write a matlab function with two outputs, v and t, that does this. Let s be some vector of s values.
[v,t] = Nunosfunc(s)
t1 = (s<0);
t2 = (0<=s)&(s<1);
t3 = (1<=s)&(s<1+.625);
t4 = (1+.625<=s)&(s<1+3);
t5 = (1+3<=s);
v = t1.*1.0+t2.*(1.0-(1.0-0.1)*s)+t3.*0.1+...
t4.*(0.1+(0.9-0.1)/(3-.625)*(s-1-.625))+t5.*0.9;
t = t1.*s+t2.*0+(t3|t4|t5).*(s-1;
return
This is very similar to generating points, say, on an ellipse
x^2/9+y^2/16 = 1
This also cannot be accomplished with a function, but must be generated using some parameter - in this case x = 3*cos(s), y = 4*sin(s), where the parameter s varies over a range of 2*pi.
Note that if in your problem you only wanted to plot that curve, you need only give 'plot' the coordinates of six key (v,t) points, four of them at the bends, using the '-' option and plot will fill in the straight lines for you.
  4 Comments
Roger Stafford
Roger Stafford on 23 Jun 2013
Thanks, Jan. Yes I forgot the 'function' designation. (More senior moments!)
Nuno
Nuno on 25 Jun 2013
Error using Nunosfunc (line 2) Not enough input arguments.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!