Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to solve for system of equation with set of known variables?

Subject: How to solve for system of equation with set of known variables?

From: Michal Kolaj

Date: 15 Nov, 2010 00:47:03

Message: 1 of 3

Hello all, I am a self-taught programmer and I am having a problem with the following:

So I need to solve for 2 variables, I have 2 equations. Easy enough... but:

In each of the 2 equations i have another 2 variables which I know and have a large list of. I need some sort of code to solve the system of equations for the two unknown variables for the entire list of known variables (like a loop statement)

my equations:

RH=sqrt(4*z^2+1)-2*z;
RV=1/sqrt(4*z^2+1);
VD=c*(1-RV)
HD=c*(1-RH)

I have vectors for both VD and HD (my known variables)

How do i cycle through solutions for z,c for each pair of VD HD ?

I can solve for any specific VD,HD pair using the solve function or fsolve but I do not know how to include a loop statement in this in order to solve for the full list of VD and HD vectors.

Any help would be appreciated.
---

Subject: How to solve for system of equation with set of known variables?

From: Michal Kolaj

Date: 15 Nov, 2010 01:06:03

Message: 2 of 3

Solved:

function F = conductivity(H,V)
syms c z
f1=((1/(4*(z^2)+1)^(1/2)))-((V-c)/(-c));
f2=(((4*(z^2)+1)^(1/2))-(2*z))-((H-c)/(-c));
F=solve(f1,f2);
end

then:

for n=1:71
p(n)=conductivity(H(n),V(n))
end

Sorry if I wasted anyones time.

Subject: How to solve for system of equation with set of known variables?

From: Roger Stafford

Date: 15 Nov, 2010 01:38:03

Message: 3 of 3

"Michal Kolaj" <toomanybullets@hotmail.com> wrote in message <ibpvu7$iot$1@fred.mathworks.com>...
> Hello all, I am a self-taught programmer and I am having a problem with the following:
>
> So I need to solve for 2 variables, I have 2 equations. Easy enough... but:
>
> In each of the 2 equations i have another 2 variables which I know and have a large list of. I need some sort of code to solve the system of equations for the two unknown variables for the entire list of known variables (like a loop statement)
>
> my equations:
>
> RH=sqrt(4*z^2+1)-2*z;
> RV=1/sqrt(4*z^2+1);
> VD=c*(1-RV)
> HD=c*(1-RH)
>
> I have vectors for both VD and HD (my known variables)
>
> How do i cycle through solutions for z,c for each pair of VD HD ?
>
> I can solve for any specific VD,HD pair using the solve function or fsolve but I do not know how to include a loop statement in this in order to solve for the full list of VD and HD vectors.
>
> Any help would be appreciated.
> ---
- - - - - - - - -
  I don't think you need to use a for-loop. If you take the ratio VD/HD, this leads after some manipulation to a quadratic equation in z (after discarding the z = 0 root) which has two roots that have explicit solution expressions in terms of the above ratio. You could evaluate this as a vectorized solution for a list of VD and HD vectors. The value c can easily be obtained from this.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us