# How to solve an issue with an equation that has a variable with multiple values.

1 view (last 30 days)
Javier Solis on 30 Aug 2022
Edited: Dyuman Joshi on 13 Sep 2022
I have this equation
đť‘¦ = đť‘’^(3đť‘Ą)(2đť‘Ą+đť‘™đť‘›(40đť‘Ą))
and have to solve y using the values x:[1,2,3,4,5,6,7,8,9,10]
I currently have this as my code, but I keep getting wrong values for y. I am just wondering where I went wrong.
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
y = (exp(3*x).*((2*x)+(log(40*x))))
here are my results
y =
1.0e+14 *
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0003 0.0058 0.1271 2.7776

Dyuman Joshi on 30 Aug 2022
Edited: Dyuman Joshi on 13 Sep 2022
You are not getting wrong values of y.
format long
x = (1:10)';
y = (exp(3*x).*((2*x)+(log(40*x))))
y = 10Ă—1
1.0e+14 * 0.000000000001143 0.000000000033816 0.000000000874120 0.000000021280472 0.000000500104652 0.000011477782122 0.000258946694719 0.005766237134192 0.127085596247646 2.777571252192637
Since there is a big difference in the first value and the last value of the expression, and when presented in short format (the default format), the answer is displayed with (first) 4 (rounded) digits in exponent/scientific notation
When some of the values in an array are short numbers and some have large exponents (as is your case), you can use long format as shown above or shortG as shown below
format shortG
y
y = 10Ă—1
1.0e+00 * 114.26 3381.6 87412 2.128e+06 5.001e+07 1.1478e+09 2.5895e+10 5.7662e+11 1.2709e+13 2.7776e+14
Javier Solis on 30 Aug 2022
Thank you, I greatly appreciate it.

### Categories

Find more on Matrix Indexing in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by