MATLAB Answers

Matlab code for fractions

28 views (last 30 days)
Johnny McKenney
Johnny McKenney on 27 Sep 2020 at 15:57
Commented: Star Strider on 27 Sep 2020 at 16:20
How would I write 1.5/s as a num[ ] den[ ] code in matlab?

  0 Comments

Sign in to comment.

Answers (2)

John D'Errico
John D'Errico on 27 Sep 2020 at 16:08
Confusing question.
Do you know the value of s?
s = 7
s =
7
>> 1.5/s
ans =
0.214285714285714
>> format rat
>> 1.5/s
ans =
3/14
Do you not know what is is, so you want to use s in a symbolic form?
syms s
1.5/s
ans =
3/(2*s)

  1 Comment

Johnny McKenney
Johnny McKenney on 27 Sep 2020 at 16:14
I do not know S. I think it is 1. We are meant to write
numx = [ 1 2 3]
denx = [1 2 3]
as an example. I just can't figure out how to do that with 1.5/S or 1/S+2

Sign in to comment.


Star Strider
Star Strider on 27 Sep 2020 at 16:11
Use the rat function:
x = 1.5
[num,den] = rat(x)
producing:
num =
3
den =
2
.

  2 Comments

Johnny McKenney
Johnny McKenney on 27 Sep 2020 at 16:15
ok thank you
Star Strider
Star Strider on 27 Sep 2020 at 16:20
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!