السلام عليكم ورحمة الله وبركاته
اليوم ابيين كيف نحل مسائل الاعداد المركبة ونرسمها ماهو العدد المركب
الصيغة المثلثية
X+iy
الصيغة الدائرية
z=r*exp(jtheta)
يتكون العدد المركب من جزئيين حقيقي وخيالي قد تعطى لنا مسئلة مكونة من مجموعة اعداد مركبة مضروبة ببعضها اومقسومة بصيغة دائري poler اومثلثي ومطلوب منا رسمها وحلها [/size]



خير وسيلة هيا الربط بين الدوت نت ولماتلاب بداية نكون دالة في الماتلاب ترسل لها سترنك تحمل العدد المركب وهيا تحله وتعديد الجواب من جزء حقيقي وخيالي ونرسم الاعداد في الجوت نت اذن تكتب هذه الدالة في الماتلاب ونحولها الى ملف DLL باستخدام dot net bulder هكذا
function [y]=drawingcomplex(string12) try z=eval(string12); y(1)=real(z); y(2)=imag(z); catch y='error cannot find this result' end end
خطوات التحويل الى DLL نكتب امر deploytool tool في ال
command windows

لاخذ
الدالة التي كوناها اشرنا عليها لاننا سوف نضيفها الى class الذي نكونه في هذه الخطوة

الان نحوله الى ملف dll باستخدام الزر الذي تدخل اليه اسهم

وبهذا نكون قد كونا دالة في تعيد لنا جزء حقيقي وخيالي نضيفها الى مشروعنا ملف ال DLL الموجود بهذا المسار الخاص بالتعامل مع المصفوفات وهو MWArray.dll \
C:\Program Files\MATLAB\R2010a\toolbox\dotnetbuilder\bin\win32\v2.0
وفي زر بدء الرسم نكتب هذه الاسطر
Button1.Enabled = False
Button1.Text = " انتضر"
Try
ListBox1.Items.Clear()
Dim test As New Class1Draw
'عرفنا كائن من نوع الكلاس الذي صممناه بالماتلاب
x = test.drawingcomplex(Convert.ToString(fdrawtxt.Text))
'TextBox1.Text = Convert.ToString(x)
ax = Convert.ToDouble(Convert.ToString(x(1)))
ay = Convert.ToDouble(Convert.ToString(x(2)))
If ay > 0 Then
ListBox1.Items.Add(Convert.ToString(x(1)) & "+" & Convert.ToString(x(2)) & "i")
Else
ListBox1.Items.Add(ax & ay & "i")
End If
ListBox1.Items.Add("Real=" & ax)
ListBox1.Items.Add("imag=" & ay)
ra = Math.Sqrt((ax * ax) + (ay * ay))
'تحميل صورة جديدة على مربع الصورة
Dim II As New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)
Me.PictureBox1.Image = II
' تحديد قلم المحاور غير ضروري في جميع الخطوات
Dim mypen As New Pen(Color.Black, 4)
mypen.Alignment = Drawing2D.PenAlignment.Center
mypen.StartCap = Drawing2D.LineCap.ArrowAnchor
mypen.EndCap = Drawing2D.LineCap.ArrowAnchor
'استدعاء دالة رسم المنحني
BegindrawALXsfuncompex(Graphics.FromImage(Me.PictureBox1.Image), New Point(Me.PictureBox1.Width \ 2, Me.PictureBox1.Height \ 2), Me.Font, (Me.PictureBox1.Width \ 72) - 1, (Me.PictureBox1.Width \ 72) - 1, (Me.PictureBox1.Height \ 72) - 1, (Me.PictureBox1.Height \ 72) - 1, 2.6, mypen, New Pen(Color.Red, 2))
'قتل القلم بعد الانهاء
mypen.Dispose()
Beep()
Catch ex As Exception
MsgBox(ex.Message, "Error ")
End Try
Button1.Text = "بدء الرسم"
Button1.Enabled = True'استدعاء دالة رسم المنحني
Sub BegindrawALXsfuncompex(ByVal Gr As Graphics, ByVal StartPoint As Point, ByVal NumFont As Font, Optional ByVal Right_x_Long As Integer = 0, Optional ByVal Left_x_Long As Integer = 0, Optional ByVal Right_y_Long As Integer = 0, Optional ByVal Left_y_Long As Integer = 0, Optional ByVal XXX As Single = 1, Optional ByVal Line_pen As Pen = Nothing, Optional ByVal Fun_pen As Pen = Nothing)
Try
Const bbb As Integer = 100
If Line_pen Is Nothing Then
Line_pen = New Pen(Color.Empty)
End If
If Fun_pen Is Nothing Then
Fun_pen = Pens.Black
End If
Gr.DrawLine(Line_pen, CInt(StartPoint.X - ((Left_x_Long + 0.5) * bbb)), StartPoint.Y, CInt(StartPoint.X + ((Right_x_Long + 0.5) * bbb)), StartPoint.Y)
' رسم المحور السيني غير ضروري
Gr.DrawLine(Line_pen, StartPoint.X, CInt(StartPoint.Y - ((Right_y_Long + 0.5) * bbb)), StartPoint.X, CInt(StartPoint.Y + ((Left_y_Long + 0.5) * bbb)))
'
For f As Single = -Left_x_Long To Right_x_Long Step 0.5
If f <> CInt(f) Then
Gr.DrawLine(New Pen(Line_pen.Color, 2), StartPoint.X + (f * bbb), StartPoint.Y - 1 - Line_pen.Width, StartPoint.X + (f * bbb), StartPoint.Y + 1 + Line_pen.Width)
Else
Gr.DrawLine(New Pen(Line_pen.Color, 2), StartPoint.X + (f * bbb), StartPoint.Y - 2 - Line_pen.Width, StartPoint.X + (f * bbb), StartPoint.Y + 2 + Line_pen.Width)
If Not f = 0 Then Gr.DrawString(f, NumFont, New SolidBrush(Line_pen.Color), StartPoint.X + (f * bbb), StartPoint.Y + 5)
End If
Next
For f As Single = -Right_y_Long To Left_y_Long Step 0.5
If f <> CInt(f) Then
Gr.DrawLine(New Pen(Line_pen.Color, 2), StartPoint.X - 1 - Line_pen.Width, StartPoint.Y + (f * bbb), StartPoint.X + 1 + Line_pen.Width, StartPoint.Y + (f * bbb))
Else
Gr.DrawLine(New Pen(Line_pen.Color, 2), StartPoint.X - 2 - Line_pen.Width, StartPoint.Y + (f * bbb), StartPoint.X + 2 + Line_pen.Width, StartPoint.Y + (f * bbb))
If Not f = 0 Then Gr.DrawString(-f, NumFont, New SolidBrush(Line_pen.Color), StartPoint.X + 5, StartPoint.Y + (f * bbb))
End If
Next
'===================
x_axis(0) = StartPoint.X + ax * bbb
'وضعنا اشارة سالبة لان قيمة الواي على الفورم
'تزداد كلما اتجهنا الى الاسفل والاحداتيات تزداد لالاعلى لذالك طرحنا
y_asxis(0) = StartPoint.Y - ay * bbb
Dim Po1 As New Point(StartPoint.X, StartPoint.Y)
Dim Po2 As New Point(x_axis(0), y_asxis(0))
Dim Curvepoints As PointF() = {Po1, Po2}
Gr.DrawCurve(New Pen(Color.Blue, 2), Curvepoints)
' the complement for the curve
y_asxis(0) = StartPoint.Y - (-1 * ay) * bbb
Dim Po21 As New Point(x_axis(0), y_asxis(0))
Dim Curvepoints12 As PointF() = {Po1, Po21}
Gr.DrawCurve(Pens.Red, Curvepoints12)
y_asxis(0) = StartPoint.Y - ay * bbb
Dim Po12 As New Point(x_axis(0), StartPoint.Y)
Dim Curvepoints1 As PointF() = {Po12, Po2}
Gr.DrawCurve(Pens.Gold, Curvepoints1)
Dim Po121 As New Point(StartPoint.X, y_asxis(0))
Dim Curvepoints11 As PointF() = {Po121, Po2}
Gr.DrawCurve(Pens.Gold, Curvepoints11)
' Gr.DrawLine(Pens.Yellow, StartPoint.X, 0, 0, yx)
' Gr.DrawEllipse(Pens.Gold, StartPoint.X, StartPoint.Y, ra, ra)
'MsgBox(x_axis(0) & "=" & y_asxis(0))
Catch ex As Exception
MsgBox(ex.Message, "Error ")
End Try
End Sub
حسين احمد