Problem Creating a Function

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 Kommentare

Jan
Jan am 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 am 20 Jun. 2013
I want to create a function wich replies the specific y-value for a provided x-value and i could sampling .

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Roger Stafford
Roger Stafford am 19 Jun. 2013

1 Stimme

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 Kommentare

Nuno
Nuno am 21 Jun. 2013
Thank you! but in my matlab showm this:
Undefined function or variable 's'.
Error in Untitled (line 3) [v, t] = Nunosfunc(s);
Jan
Jan am 23 Jun. 2013
I assume, that Roger forgot a "function" and it should be:
function [v,t] = Nunosfunc(s)
Then "s" is the input argument.
Roger Stafford
Roger Stafford am 23 Jun. 2013
Thanks, Jan. Yes I forgot the 'function' designation. (More senior moments!)
Nuno
Nuno am 25 Jun. 2013
Error using Nunosfunc (line 2) Not enough input arguments.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 19 Jun. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by