Hi People... 2 Questions Here ...

Hi Every One
1- Suppose We Have 1.7321 . Which Command returns the non-numerical value? (I mean sqrt(3) )
2-Run This
% Interactive script to fit a cubic to data points
clf;clc;clear all;
grid on
hold on
axis([0 100 0 100]);
diff = 10;
xold = 68;
i = 0;
xp = zeros(1); % data points
yp = zeros(1);
while diff > 2
[a b] = ginput(1);
diff = abs(a - xold);
if diff > 2
i = i + 1;
xp(i) = a;
yp(i) = b;
xold = a;
plot(a, b, 'k*')
end
end
p = polyfit(xp, yp, 3 );
plotfunction=poly2sym((p))
x = 0:0.1:xp(length(xp));
y=p(1)*x.^3 + p(2)*x.^2 + p(3)*x + p(4);
plot(x,y), title( 'cubic polynomial fit'), ...
ylabel('y(x)'), xlabel('x')
hold off
end
The Output has a large amount of number... how can i simplify it???

2 Commenti

Azzi Abdelmalek
Azzi Abdelmalek il 28 Mar 2013
Can you explain question 1?
Masoud Ghanbari
Masoud Ghanbari il 29 Mar 2013
I mean you have the 1.7321 and you want to radical(?)=1.7321

Accedi per commentare.

 Risposta accettata

Walter Roberson
Walter Roberson il 28 Mar 2013
Modificato: Walter Roberson il 28 Mar 2013
For #1: if you have access to the full version of Maple, such as through the old Extended Symbolic Mathematics Toolbox, then you can use the Maple command "identify". If you do have that access (it is not the current Symbolic Toolbox, which is MuPAD rather than Maple), then try
feval(symengine, 'identify', 1.7321)
or
maple(sprintf('identify(%g)', 1.7321))
MuPAD (the current Symbolic Toolbox) does not appear to have a similar function.
You could try using
simplify(plotfunction)
to get a more compact expression. The result might still have a lot of rational numbers in it. If you want the rational numbers converted to fixed point numbers, then use
vpa(plotfunction)

5 Commenti

Dear Walter .. Thanks For the vpa... It Worked
the first answer failed
Run this and tell me why elseif does not work , Please
%
clf;clc;clear all;
grid on
hold on
axis([0 100 0 100]);
diff = 10;
xold = 68;
i = 0;
xp = zeros(1); % data points
yp = zeros(1);
while diff > 2
[a b] = ginput(1);
diff = abs(a - xold);
if diff > 2
i = i + 1;
xp(i) = a;
yp(i) = b;
xold = a;
plot(a, b, 'k*')
end
end
p = polyfit(xp, yp, 3 );
plotfunction=poly2sym((p));
fitfunction = vpa(plotfunction,4)
x = 0:0.1:xp(length(xp));
y=p(1)*x.^3 + p(2)*x.^2 + p(3)*x + p(4);
plot(x,y), title( 'cubic polynomial fit'), ...
ylabel('y(x)'), xlabel('x')
hold off
userans=input('Do You Want The Result With More Precision? (Y/N)\n','s');
if userans == 'Y' || 'y'
clc;
plotfunction =poly2sym((p));
fitfunction
fullfitfunction = plotfunction
msgbox('Done');
elseif userans == 'N' || 'n'
msgbox('Done');
mghanbari.ir </a>')
end
end
if you type 'n' it will do the same as when you type 'y'
The line
if userans == 'Y' || 'y'
means the same thing as
if ((userans == 'Y') || ('y'))
which means the same thing as
if ((userans == 'Y') || ('y' ~= 0))
And since 'y' is indeed non-zero, the test is always true.
The What is the correct format?
if strcmpi(userans, 'y')
Masoud Ghanbari
Masoud Ghanbari il 11 Apr 2013
Thanks Dear Friends...

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by