Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please i need to change this to matlab programing import random source = jiKnp4bqpmAbp target = Hello, World! def fitness(source, target): fitval = 0 for

Please i need to change this to matlab programing

import random

source = "jiKnp4bqpmAbp"

target = "Hello, World!"

def fitness(source, target):

fitval = 0

for i in range(0, len(source)):

fitval += (ord(target[i]) - ord(source[i])) ** 2

return(fitval)

def mutate(source):

charpos = random.randint(0, len(source) - 1)

parts = list(source)

parts[charpos] = chr(ord(parts[charpos]) + random.randint(-1,1))

return(''.join(parts))

random.seed()

fitval = fitness(source, target)

i = 0

while True:

i += 1

m = mutate(source)

fitval_m = fitness(m, target)

if fitval_m < fitval:

fitval = fitval_m

source = m

print "%5i %5i %14s" % (i, fitval_m, m)

if fitval == 0:

break

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions

Question

Explain the concept of employment at will.

Answered: 1 week ago