ans = 
Hi All. Just wondering why answer to (i) is not 4.9e+4. an why answer to (iii) is not (9x)/2 or 4.5 x. Many thanks. Brian
Ältere Kommentare anzeigen
% (i) Find f(1.2) in the form 'a x 10^n' where a is correct to 1 decimal place
% (ii) Find x for which g(x) = 3.5
% (iii) Find g(f(x)) in simplest form
clear, clc
syms x
f = exp(9*x); g = log(sqrt(x));
% (i)
f_at_x = subs(f,x,1.2); % evaluates f(x = 1.2) as symbolic
f_at_x = double(f_at_x); % converts to double (real)
f_at_x = round(f_at_x,1) % ??? round to 1 decimal place
% (ii)
solve (g == 3.5, x)
% (iii)
g_f_x = (subs(g,x,f));
g_f_x = simplify(g_f_x)
Antworten (2)
Your value in (i) for f(1.2) is 49020.80113638172, so when you round to 1 decimal, it becomes 49020.8 which in engineering notation is 4.9021e4 because of rounding the right most digit.
You should reread the question to understand why you are not getting 4.9 as answer (hint:question is asking a where f(1.2) = a * 10^n ) :)
syms x
f = exp(9*x); g = log(sqrt(x));
% (i)
f_at_x = subs(f,x,1.2); % evaluates f(x = 1.2) as symbolic
format long % change displasy setting
f_at_x = double(f_at_x) % converts to double (real)
f_at_x_rounded = round(f_at_x,1) % ??? round to 1 decimal place
format bank % change displasy setting
f_at_x_rounded
For part ii, log(x^n) = n*log(x) so both expressions are equivalent
fun1 = @(x) 0.5*log(exp(9*x));
fun2 = @(x) log(exp(4.5*x));
fun1(1.2) == fun2(1.2) % are they equal?
7 Kommentare
Brian Smyth
am 5 Jul. 2024
Now this is a different question. Now you are asking how to convert 49020.80113638172 to 4.9 * 10^4. Here is one way
x = 49020.80113638172; % represent as x = a * 10^n
n = floor(log10(x))
tmp_ = 1; % decimal accuracy for a, 1,2,3,4 etc
a = floor(x/10^(n-tmp_))/10^tmp_
newX = a*10^n
x = 49020.80113638172;
fprintf('%.1e',x)
Brian Smyth
am 5 Jul. 2024
@Brian Smyth You're welcome!
Note that fprintf is for outputting formatted text to the command line or to text files. If instead you want to display formatted text in a plot, say, you could use sprintf, which supports the same options for formatting that fprintf does, but returns a character vector containing the formatted text:
x = 49020.80113638172;
plot(1:10)
str = sprintf('%.1e',x) % formatted text (character vector, str)
text(5,8,str) % create a text object at point (5,8) showing that formatted text
Brian Smyth
am 5 Jul. 2024
Verschoben: Torsten
am 5 Jul. 2024
Voss
am 5 Jul. 2024
You're welcome!
For (iii), use
syms x real
instead of
syms x
1 Kommentar
Brian Smyth
am 5 Jul. 2024
Verschoben: Voss
am 5 Jul. 2024
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

