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

3 ビュー (過去 30 日間)
Brian Smyth
Brian Smyth 2024 年 7 月 5 日
コメント済み: Voss 2024 年 7 月 5 日
% (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
f_at_x = 4.9021e+04
% (ii)
solve (g == 3.5, x)
ans = 
% (iii)
g_f_x = (subs(g,x,f));
g_f_x = simplify(g_f_x)
g_f_x = 

回答 (2 件)

Aquatris
Aquatris 2024 年 7 月 5 日
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 =
4.902080113638172e+04
f_at_x_rounded = round(f_at_x,1) % ??? round to 1 decimal place
f_at_x_rounded =
4.902080000000000e+04
format bank % change displasy setting
f_at_x_rounded
f_at_x_rounded =
49020.80
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?
ans = logical
1
  7 件のコメント
Brian Smyth
Brian Smyth 2024 年 7 月 5 日
移動済み: Torsten 2024 年 7 月 5 日
Hi Voss.
That's good to know. Never quite understood the difference between the two (i..e fprintf and sprintf)! Thank you.

サインインしてコメントする。


Torsten
Torsten 2024 年 7 月 5 日
移動済み: Voss 2024 年 7 月 5 日
For (iii), use
syms x real
instead of
syms x
  1 件のコメント
Brian Smyth
Brian Smyth 2024 年 7 月 5 日
移動済み: Voss 2024 年 7 月 5 日
Hi Torsten. Brilliant. Thanks a mil. Brian

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by