Matlab Help
Hi, I'm having a bit of trouble formatting my output.
I want to display:
D1 = 1.0000 + 7.0000x + 31.2100(x-2)^2
D2 = ... etc.
and I want it to be such that we don't know how many D's there will be. So I have a loop set up
syms x;
k =1;
while k<=n-1
S = y(k) + b(k)*(x-z(k)) + c(k)*(x-z(k))^2 + d(k)*(x-z(k))^3;
disp(sprintf('S%d=',k))
disp(S);
k = k+1;
end
but I don't know how to make it show 4 decimal places, even if my number is an integer. It won't let me use sprintf, because x is syms. How can setprecision it to 4?
Also, there's another place in my program that I want it to say:
x = 0.0000 1.0000 45.0000
.. etc.
but sprintf forces be to skip a space, so instead I did:
disp(sprintf('\nx:'))
disp(z)
disp(sprintf('\ny:'))
disp(y)
but again, I don't know how to force my z array to have 4 digits, and how to stop my sprintf from skipping a line after "x:" and "y:".
Please help! =)
I want to display:
D1 = 1.0000 + 7.0000x + 31.2100(x-2)^2
D2 = ... etc.
and I want it to be such that we don't know how many D's there will be. So I have a loop set up
syms x;
k =1;
while k<=n-1
S = y(k) + b(k)*(x-z(k)) + c(k)*(x-z(k))^2 + d(k)*(x-z(k))^3;
disp(sprintf('S%d=',k))
disp(S);
k = k+1;
end
but I don't know how to make it show 4 decimal places, even if my number is an integer. It won't let me use sprintf, because x is syms. How can setprecision it to 4?
Also, there's another place in my program that I want it to say:
x = 0.0000 1.0000 45.0000
.. etc.
but sprintf forces be to skip a space, so instead I did:
disp(sprintf('\nx:'))
disp(z)
disp(sprintf('\ny:'))
disp(y)
but again, I don't know how to force my z array to have 4 digits, and how to stop my sprintf from skipping a line after "x:" and "y:".
Please help! =)
0
Comments
http://icrontic.com/forum/forumdisplay.php?f=70