24小时热门版块排行榜    

CyRhmU.jpeg
查看: 694  |  回复: 5

qq449077540

新虫 (初入文坛)

[交流] 【求助】画图中的legend问题已有3人参与

syms x % k=6
x=0:0.001:0.11
y=50/119232*(-0.81*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+2.73*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+4*50*6/119232*(-0.15*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+0.44*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+50/119232*(cosh(6*x).*cos(6*x)-1)%-4*50*6/119232*0.25*(cosh(6*(x-0.11)).*sin(6*(x-0.11))-sinh(6*(x-0.11)).*cos(6*(x-0.11)))
plot(x,y)
hold on
x=0.11:0.001:0.33
y=50/119232*(-0.81*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+2.73*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+4*50*6/119232*(-0.15*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+0.44*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+50/119232*(cosh(6*x).*cos(6*x)-1)-4*50*6/119232*0.25*(cosh(6*(x-0.11)).*sin(6*(x-0.11))-sinh(6*(x-0.11)).*cos(6*(x-0.11)))
plot(x,y)
hold on
syms x % k=6
x=0:0.001:0.22
y=237/119232*(-0.81*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+2.73*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+4*50*6/119232*(-0.11*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+0.13*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+237/119232*(cosh(6*x).*cos(6*x)-1)%-4*50*6/119232*0.25*(cosh(6*(x-0.22)).*sin(6*(x-0.22))-sinh(6*(x-0.22)).*cos(6*(x-0.22)))
plot(x,y)
hold on
x=0.22:0.001:0.33
y=237/119232*(-0.81*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+2.73*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+4*50*6/119232*(-0.11*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+0.13*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+237/119232*(cosh(6*x).*cos(6*x)-1)-4*50*6/119232*0.25*(cosh(6*(x-0.22)).*sin(6*(x-0.22))-sinh(6*(x-0.22)).*cos(6*(x-0.22)))
plot(x,y)
hold on
legend('23','23','56','56')


通过分段函数现2条直线,然后legend一下,前两个函数需要用一个名称,后两个用一个名称。
但是,我得到却是 一个函数一个名称
求助大伙帮个忙,谢谢啦
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

qq449077540

新虫 (初入文坛)

2楼2010-07-16 21:31:16
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

change0618

铁杆木虫 (著名写手)

方丈大师

★ ★ ★
小木虫(金币+0.5):给个红包,谢谢回帖交流
robert2020(金币+2):好方法!呵呵... 2010-07-16 23:38:25
用判断的形式把分段函数弄成一个形式
y=func1*(x>=0 & x<=0.11)+func2*(x>0.11 & x<0.33)
3楼2010-07-16 23:17:39
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

robert2020

银虫 (著名写手)


小木虫(金币+0.5):给个红包,谢谢回帖交流
楼主在使用plot然后hold on以后实际上画出了四条曲线,而hold on后plot默认的曲线颜色为blue(故而四条曲线显示均为blue),legend一般用法是对所用的曲线进行标注。依据楼主编程要求修改如下:
引用回帖:
syms x % k=6
x=0:0.001:0.11;
y=50/119232*(-0.81*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+2.73*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+4*50*6/119232*(-0.15*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+0.44*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+50/119232*(cosh(6*x).*cos(6*x)-1);%-4*50*6/119232*0.25*(cosh(6*(x-0.11)).*sin(6*(x-0.11))-sinh(6*(x-0.11)).*cos(6*(x-0.11)))
H(1)=plot(x,y,'blue');
hold on
x=0.11:0.001:0.33;
y=50/119232*(-0.81*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+2.73*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+4*50*6/119232*(-0.15*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+0.44*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+50/119232*(cosh(6*x).*cos(6*x)-1)-4*50*6/119232*0.25*(cosh(6*(x-0.11)).*sin(6*(x-0.11))-sinh(6*(x-0.11)).*cos(6*(x-0.11)));
H(2)=plot(x,y,'blue');
hold on
syms x % k=6
x=0:0.001:0.22;
y=237/119232*(-0.81*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+2.73*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+4*50*6/119232*(-0.11*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+0.13*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+237/119232*(cosh(6*x).*cos(6*x)-1);%-4*50*6/119232*0.25*(cosh(6*(x-0.22)).*sin(6*(x-0.22))-sinh(6*(x-0.22)).*cos(6*(x-0.22)))
H(3)=plot(x,y,'red');
hold on
x=0.22:0.001:0.33;
y=237/119232*(-0.81*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+2.73*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+4*50*6/119232*(-0.11*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+0.13*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+237/119232*(cosh(6*x).*cos(6*x)-1)-4*50*6/119232*0.25*(cosh(6*(x-0.22)).*sin(6*(x-0.22))-sinh(6*(x-0.22)).*cos(6*(x-0.22)));
H(4)=plot(x,y,'red');
hold on
legend(H([1,3]),'23','56')

图形如下:
引用回帖:
Originally posted by qq449077540 at 2010-07-16 21:29:27:
syms x % k=6
x=0:0.001:0.11
y=50/119232*(-0.81*0.5*(cosh(6*x).*sin(6*x)+sinh(6*x).*cos(6*x))+2.73*0.25*(cosh(6*x).*sin(6*x)-sinh(6*x).*cos(6*x)))+4*50*6/119232*(-0.15*0.5*(cosh(6*x).*sin(6*x)+sin ...

Truthfulness,Compassion,Tolerance,Beauty
4楼2010-07-16 23:31:57
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

qq449077540

新虫 (初入文坛)

引用回帖:
Originally posted by change0618 at 2010-07-16 23:17:39:
用判断的形式把分段函数弄成一个形式
y=func1*(x>=0 & x<=0.11)+func2*(x>0.11 & x<0.33)

谢谢啦,能不能用您的方法把我的问题写一下,不太明白
5楼2010-07-17 13:06:40
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

qq449077540

新虫 (初入文坛)

引用回帖:
Originally posted by robert2020 at 2010-07-16 23:31:57:
楼主在使用plot然后hold on以后实际上画出了四条曲线,而hold on后plot默认的曲线颜色为blue(故而四条曲线显示均为blue),legend一般用法是对所用的曲线进行标注。依据楼主编程要求修改如下:


图形如下:
...

非常感谢,方法很有效
6楼2010-07-17 13:07:20
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 学员hYBQgl 的主题更新
普通表情 高级回复(可上传附件)
信息提示
请填处理意见