Problem Creating a Function
Mostrar comentarios más antiguos
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! =)
Respuestas (1)
Roger Stafford
el 19 de Jun. de 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 comentarios
Nuno
el 21 de Jun. de 2013
Jan
el 23 de Jun. de 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
el 23 de Jun. de 2013
Thanks, Jan. Yes I forgot the 'function' designation. (More senior moments!)
Nuno
el 25 de Jun. de 2013
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!