Matlab: How to find answers repeatedly by inserting values?

ISHAN TOPRE
@ishan-nohePN • Oct 22, 2024

I have a programming doubt. The doubt is simple.

"syms a b c;
a=b+c;
b=3; c=1;"

The above is the program. Now when I do b+c, I get answer as 4. But when I want to find the value of a,
the system says a=b+c.

It should say a=4. But it does not.

Another doubt is that, if I keep on changing values of b and c, can I get different values of a?

@#-Link-Snipped-# can you help me?

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Harshad Italiya

    @harshad-ukH5ww Oct 23, 2013

    IssueI have a programming doubt. The doubt is simple.

    "syms a b c;
    a=b+c;
    b=3; c=1;"

    The above is the program. Now when I do b+c, I get answer as 4. But when I want to find the value of a,
    the system says a=b+c.

    It should say a=4. But it does not.

    Another doubt is that, if I keep on changing values of b and c, can I get different values of a?

    @#-Link-Snipped-# can you help me?

    Hey @#-Link-Snipped-#,
    Well I am not pro in MATLAB but I see you have assigned b=3 and c=1 after a=b+c; that may be the reason you are not getting proper value.

    Try this

    "syms a b c;
    b=3; c=1;
    a=b+c;"

    I think this should work for you.

  • ISHAN TOPRE

    @ishan-nohePN Oct 23, 2013

    Thanks brother. It worked!
    but the problem is only partially solved. Say I have an equation,
    Y=3X+2;
    Now I want values of Y for X=1,2,3...

    Then what to do? Each time I do not want to type the equation. Nor do I want to plot X,Y 😔

  • Ramani Aswath

    @ramani-VR4O43 Oct 23, 2013

    Prof.Rudra Pratap's book 'Getting Started With Matlab: A quick introduction for scientists and engineers' published by Oxford University Press is very good for this. Written in a casual style it gets you going fast. I have the book for Matlab v.6. I can vouch for its excellence. (Available from college book stores at a concession. I bought it at IISC, Bangalore)
    Free eBooks are available here:
    #-Link-Snipped-#


    (Note: I do not know anything about the legality of this site.
    @#-Link-Snipped-#, is this OK?)

  • Harshad Italiya

    @harshad-ukH5ww Oct 23, 2013

    IssueThanks brother. It worked!
    but the problem is only partially solved. Say I have an equation,
    Y=3X+2;
    Now I want values of Y for X=1,2,3...

    Then what to do? Each time I do not want to type the equation. Nor do I want to plot X,Y 😔

    Well you can use some kind of array for that. Let me make one example for you.

  • Harshad Italiya

    @harshad-ukH5ww Oct 23, 2013

    A.V.RamaniProf.Rudra Pratap's book 'Getting Started With Matlab: A quick introduction for scientists and engineers' published by Oxford University Press is very good for this. Written in a casual style it gets you going fast. I have the book for Matlab v.6. I can vouch for its excellence. (Available from college book stores at a concession. I bought it at IISC, Bangalore)
    Free eBooks are available here:
    #-Link-Snipped-#


    (Note: I do not know anything about the legality of this site.
    @#-Link-Snipped-#, is this OK?)

    Agree ! not sure about the legality about that site as there are lot of different books posted.

    @#-Link-Snipped-# Have a look at this :- #-Link-Snipped-#
    You want something like this right?

  • ISHAN TOPRE

    @ishan-nohePN Oct 23, 2013

    Harshad ItaliyaAgree ! not sure about the legality about that site as there are lot of different books posted.

    @#-Link-Snipped-# Have a look at this :- #-Link-Snipped-#
    You want something like this right?

    @#-Link-Snipped-# ramani: Thankyou sir, I will check that book from college library tomorrow(first thing). 😀

    @#-Link-Snipped-# Yes I want same type of output.

  • Jeffrey Arulraj

    @jeffrey-xA7lUP Oct 23, 2013

    Using arrays is really simple try using

    a=b.+c
    a=b.*c

    All these simple modifications allow you to perform any operation in which the inputs are sequences

    Remember the fact that '.' (full stop) allows you to perform manipulations of arrays of input

    But balancing inputs are needed i.e Basic rules which govern array computation have to be followed here also