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! =)
답변 (1개)
Roger Stafford
2013년 6월 19일
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
Nuno
2013년 6월 21일
Jan
2013년 6월 23일
I assume, that Roger forgot a "function" and it should be:
function [v,t] = Nunosfunc(s)
Then "s" is the input argument.
Roger Stafford
2013년 6월 23일
Thanks, Jan. Yes I forgot the 'function' designation. (More senior moments!)
Nuno
2013년 6월 25일
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!