求解答:matlab中分段函数问题syms u f=-2*u.^4+2*u.^2+u/6+0.3;if u >= (-0.9-f(-0.9)) & u <= (-0.9) g =0.9+u+f(-0.9);else if u>=(-0.9) & u<=1 g=f; else if u>=1 & u<=(1+f(1)) g=1-u-f(1); end
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/28 12:17:59
求解答:matlab中分段函数问题syms u f=-2*u.^4+2*u.^2+u/6+0.3;if u >= (-0.9-f(-0.9)) & u <= (-0.9) g =0.9+u+f(-0.9);else if u>=(-0.9) & u<=1 g=f; else if u>=1 & u<=(1+f(1)) g=1-u-f(1); end
求解答:matlab中分段函数问题
syms u
f=-2*u.^4+2*u.^2+u/6+0.3;
if u >= (-0.9-f(-0.9)) & u <= (-0.9)
g =0.9+u+f(-0.9);
else if u>=(-0.9) & u<=1
g=f;
else if u>=1 & u<=(1+f(1))
g=1-u-f(1);
end
end
end
求大神帮忙看看哪里出错了?是分段函数写的不对还是 syms 的缘故?
求解答:matlab中分段函数问题syms u f=-2*u.^4+2*u.^2+u/6+0.3;if u >= (-0.9-f(-0.9)) & u <= (-0.9) g =0.9+u+f(-0.9);else if u>=(-0.9) & u<=1 g=f; else if u>=1 & u<=(1+f(1)) g=1-u-f(1); end
这样就对了:
>> f = @(u) -2*u.^4+2*u.^2+u/6+0.3;
>> g = @(u) (u>= -0.9-f(-0.9) & u <= -0.9).*(0.9 + u+f(-0.9)) + (u>= -0.9 & u<=1).*f(u) + (u>=1 & u<=1+f(1)).*(1-u-f(1))
g =
@(u)(u>=-0.9-f(-0.9)&u<=-0.9).*(0.9+u+f(-0.9))+(u>=-0.9&u<=1).*f(u)+(u>=1&u<=1+f(1)).*(1-u-f(1))
>> plot(linspace(-1,1,100),g(linspace(-1,1,100)))