解决方案二线性方程 [英] solving two linear equation in program

查看:139
本文介绍了解决方案二线性方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两条线路UV和PQ,与U(15,10)V(50,25)和P(40,10)和Q(30,30)。

和我发现这两个点之间的交叉点。
我形成两个线性方程为:

公式1:

的Ux + T(Vx的-UX)= Px活性+ S(QX-Px)的

EQ2

我想用C程序来获得T或s的值来解决这些方程。

我用 T 从第二个方程,并在第一个方程取代它得到一个公式来找到秒。但它没有工作了。我如何在程序中解决这个问题?


解决方案

  int类型,SA,SB;

好吧, SA 是一个整数。

  SA = 1 /((Vx的-UX)*(QY-PY) - (QX-Px)的*(VY-UY));

由于这些都是整数,你正在做使用整数运算整数的倒数。结果是无穷大,如果整数是零个,一个,如果它是一个,如果它是负一负一和零,如果它是别的。因此, SA 只有三个可能的值,或者你崩溃。

也许你应该考虑不使用整数运算?也许浮动SA; SA = 1.0 /(...

I have two lines UV and PQ, with U(15,10) V(50,25) and P(40,10) and Q(30,30).

and i am finding a point of intersection between these two points. I am forming two linear equations for that:

eq 1:

Ux + t(Vx-Ux) = Px +s(Qx-Px)

eq2

I want to solve these equations using C program to get the value of either t or s.

I used the t from second equation and substituted it in first equation to get a formula to find s. But it did not work out. How can I solve this in a program?

解决方案

int s,sa,sb;

Okay, sa is an integer.

sa=1/((Vx-Ux)*(Qy-Py)-(Qx-Px)*(Vy-Uy));

Since these are all integers, you're taking the reciprocal of an integer using integer math. The result is infinity if the integer is zero, one if it's one, negative one if it's negative one, and zero if it's anything else. So sa only has three possible values, or you crash.

Perhaps you should consider not using integer math? Maybe float sa; and sa = 1.0 / (....

这篇关于解决方案二线性方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆