Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Solving equations involving specific elements of matrices in MATLAB?

Tags:
  1. Mar 23, 2014 #1
    So lets say I have 2 matrices A and B. I need to solve 2 eqns involving specific elements of each matrix.
    e.g. A(1)+B(2)=4; A(1)-B(2)=2.

    Is there any way to do this? My efforts with Fsolve and solve have failed.
    Here's what I've done so far:


    function F=myfun(A,B)
    F=[A(1)-B(2)-2;
    A(1)+B(2)-4];
    end

    In the command window I typed:

    >>A=ones(2,2);
    >> B=ones(2,2);
    >> [A,B]=fsolve(@myfun,A,B)

    I even tried

    [A(1),B(1)]=fsolve(@myfun,A(1),B(1))

    Neither attempt worked.
     
  2. jcsd
  3. Mar 24, 2014 #2

    kreil

    User Avatar
    Gold Member

    Why do you need to use fsolve?

    Code (Text):

    myfun(A,B)

    ans =

        -2
        -2
     
     
  4. Apr 3, 2014 #3
    Solving 4 equations for 4 unknowns

    Hi I am trying to solve the following equations using Matlab for C1, C2, C3 and C4. In real fact I only require C1.

    C1-C2-C3-1=0
    n*C2+C3/n+(d-1)*C4=0
    C1+b*C2-b*C3-1=0
    b*n*C2-b*C3/n-C4(1+d)=0

    This is what I have input in Matlab but it seems its getting stuck because of the symbolic expresssion??

    Any help please?

    syms C1 C2 C3 C4 g L g_0 dL
    n=exp(-g*L)
    d=exp(-2*g_0*dL)
    solve(C1-C2-C3-1, n*C2+C3/n+(d-1)*C4, C1+b*C2-b*C3-1, b*n*C2-b*C3/n-C4(1+d), C1)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Solving equations involving specific elements of matrices in MATLAB?
Loading...